Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes servo output issue #9366

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions src/main/flight/servos.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,33 @@ void servoComputeScalingFactors(uint8_t servoIndex) {
servoMetadata[servoIndex].scaleMin = (servoParams(servoIndex)->middle - servoParams(servoIndex)->min) / 500.0f;
}

void computeServoCount(void)
{
static bool firstRun = true;
if (!firstRun) {
return;
}
minServoIndex = 255;
maxServoIndex = 0;
for (int j = 0; j < MAX_MIXER_PROFILE_COUNT; j++) {
for (int i = 0; i < MAX_SERVO_RULES; i++) {
// check if done
if (mixerServoMixersByIndex(j)[i].rate == 0){
break;
}
if (mixerServoMixersByIndex(j)[i].targetChannel < minServoIndex) {
minServoIndex = mixerServoMixersByIndex(j)[i].targetChannel;
}

if (mixerServoMixersByIndex(j)[i].targetChannel > maxServoIndex) {
maxServoIndex = mixerServoMixersByIndex(j)[i].targetChannel;
}
mixerUsesServos = true;
}
}
firstRun = false;
}

void servosInit(void)
{
// give all servos a default command
Expand All @@ -153,12 +180,12 @@ void servosInit(void)
/*
* load mixer
*/
computeServoCount();
loadCustomServoMixer();

// If there are servo rules after all, update variables
if (servoRuleCount > 0) {
if (mixerUsesServos) {
servoOutputEnabled = true;
mixerUsesServos = true;
}

for (uint8_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
Expand All @@ -168,26 +195,7 @@ void servosInit(void)

int getServoCount(void)
{
bool servoRuleDetected = false;
minServoIndex = 0;
maxServoIndex = 255;
for (int j = 0; j < MAX_MIXER_PROFILE_COUNT; j++) {
for (int i = 0; i < MAX_SERVO_RULES; i++) {
// check if done
if (mixerServoMixersByIndex(j)[i].rate == 0){
break;
}
if (mixerServoMixersByIndex(j)[i].targetChannel < minServoIndex) {
minServoIndex = mixerServoMixersByIndex(j)[i].targetChannel;
}

if (mixerServoMixersByIndex(j)[i].targetChannel > maxServoIndex) {
maxServoIndex = mixerServoMixersByIndex(j)[i].targetChannel;
}
servoRuleDetected = true;
}
}
if (servoRuleDetected) {
if (mixerUsesServos) {
return 1 + maxServoIndex - minServoIndex;
}
else {
Expand Down
Loading