Skip to content

Commit

Permalink
Merge pull request #9366 from shota3527/sh_servo_fix
Browse files Browse the repository at this point in the history
fixes servo output issue
  • Loading branch information
DzikuVx authored Oct 12, 2023
2 parents 96549fc + e5d9033 commit 750e8c3
Showing 1 changed file with 30 additions and 22 deletions.
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

0 comments on commit 750e8c3

Please sign in to comment.