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

SRV_Channel: fix override timeout without repeated calls #18669

Merged
merged 1 commit into from Sep 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions libraries/SRV_Channel/SRV_Channel.cpp
Expand Up @@ -113,6 +113,8 @@ uint16_t SRV_Channel::pwm_from_angle(int16_t scaled_value) const
void SRV_Channel::calc_pwm(int16_t output_scaled)
{
if (have_pwm_mask & (1U<<ch_num)) {
// Note that this allows a set_output_pwm call to override E-Stop!!
// tricky to fix because we would endup E-stoping to individual SEROVx_MIN not MOT_PWM_MIN on copter
return;
}

Expand All @@ -123,13 +125,16 @@ void SRV_Channel::calc_pwm(int16_t output_scaled)
force = true;
}

uint16_t pwm;
if (!force && override_active) {
// don't overwrite a override
return;
}

if (type_angle) {
pwm = pwm_from_angle(output_scaled);
output_pwm = pwm_from_angle(output_scaled);
} else {
pwm = pwm_from_range(output_scaled);
output_pwm = pwm_from_range(output_scaled);
}
set_output_pwm(pwm,force);
}

void SRV_Channel::set_output_pwm(uint16_t pwm, bool force)
Expand Down
9 changes: 9 additions & 0 deletions libraries/SRV_Channel/SRV_Channels.cpp
Expand Up @@ -328,7 +328,16 @@ void SRV_Channels::set_output_pwm_chan_timeout(uint8_t chan, uint16_t value, uin
const uint32_t loop_count = ((timeout_ms * 1000U) + (loop_period_us - 1U)) / loop_period_us;
override_counter[chan] = constrain_int32(loop_count, 0, UINT16_MAX);
channels[chan].set_override(true);
const bool had_pwm = SRV_Channel::have_pwm_mask & (1U<<chan);
channels[chan].set_output_pwm(value,true);
if (!had_pwm) {
// clear the have PWM mask so the channel will default back to the scaled value when timeout expires
// this is also cleared by set_output_scaled but that requires it to be re-called as some point
// after the timeout is applied
// note that we can't default back to a pre-override PWM value as it is not stored
// checking had_pwm means the PWM will not change after the timeout, this was the existing behaviour
SRV_Channel::have_pwm_mask &= ~(1U<<chan);
}
}
}

Expand Down