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

Fix bug when saving servo params causing the servos not to move as configured #2950

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
sbufReadU8(src);
servoParamsMutable(tmp_u8)->forwardFromChannel = sbufReadU8(src);
servoParamsMutable(tmp_u8)->reversedSources = sbufReadU32(src);
servoComputeScalingFactors(tmp_u8);
}
break;
#endif
Expand Down
17 changes: 10 additions & 7 deletions src/main/flight/servos.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ int servoDirection(int servoIndex, int inputSource)
return 1;
}

/*
* Compute scaling factor for upper and lower servo throw
*/
void servoComputeScalingFactors(uint8_t servoIndex) {
servoMetadata[servoIndex].scaleMax = (servoParams(servoIndex)->max - servoParams(servoIndex)->middle) / 500.0f;
servoMetadata[servoIndex].scaleMin = (servoParams(servoIndex)->middle - servoParams(servoIndex)->min) / 500.0f;
}

void servosInit(void)
{
const mixerMode_e currentMixerMode = mixerConfig()->mixerMode;
Expand Down Expand Up @@ -235,13 +243,8 @@ void servosInit(void)
}
}

/*
* Compute scaling factor for upper and lower servo throw
*/
for (uint8_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
servoMetadata[i].scaleMax = (servoParams(i)->max - servoParams(i)->middle) / 500.0f;
servoMetadata[i].scaleMin = (servoParams(i)->middle - servoParams(i)->min) / 500.0f;
}
for (uint8_t i = 0; i < MAX_SUPPORTED_SERVOS; i++)
servoComputeScalingFactors(i);

}

Expand Down
1 change: 1 addition & 0 deletions src/main/flight/servos.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ void servoMixerLoadMix(int index);
bool loadCustomServoMixer(void);
int servoDirection(int servoIndex, int fromChannel);
void servoMixer(float dT);
void servoComputeScalingFactors(uint8_t servoIndex);
void servosInit(void);