diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2014-05-23 20:22:26 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2014-05-23 20:22:26 +0200 |
commit | 287973da2837584e5f52c21ce599db913d1685c7 (patch) | |
tree | 0943aee5a8c0b221476429634654809dfddf48dc /src/modules | |
parent | 69421be983c7dcd87d00df3022f8f319b0bb7365 (diff) | |
download | px4-firmware-287973da2837584e5f52c21ce599db913d1685c7.tar.gz px4-firmware-287973da2837584e5f52c21ce599db913d1685c7.tar.bz2 px4-firmware-287973da2837584e5f52c21ce599db913d1685c7.zip |
pwm_limit: Do proper band limiting
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/systemlib/pwm_limit/pwm_limit.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/modules/systemlib/pwm_limit/pwm_limit.c b/src/modules/systemlib/pwm_limit/pwm_limit.c index 190b315f1..de2caf143 100644 --- a/src/modules/systemlib/pwm_limit/pwm_limit.c +++ b/src/modules/systemlib/pwm_limit/pwm_limit.c @@ -142,6 +142,13 @@ void pwm_limit_calc(const bool armed, const unsigned num_channels, const uint16_ case PWM_LIMIT_STATE_ON: for (unsigned i=0; i<num_channels; i++) { effective_pwm[i] = output[i] * (max_pwm[i] - min_pwm[i])/2 + (max_pwm[i] + min_pwm[i])/2; + + /* last line of defense against invalid inputs */ + if (effective_pwm[i] < min_pwm[i]) { + effective_pwm[i] = min_pwm[i]; + } else if (effective_pwm[i] > max_pwm[i]) { + effective_pwm[i] = max_pwm[i]; + } } break; default: |