From 287973da2837584e5f52c21ce599db913d1685c7 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Fri, 23 May 2014 20:22:26 +0200 Subject: pwm_limit: Do proper band limiting --- src/modules/systemlib/pwm_limit/pwm_limit.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') 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 max_pwm[i]) { + effective_pwm[i] = max_pwm[i]; + } } break; default: -- cgit v1.2.3 From 542cc7d7fbf67499a172efdd52542b517ec0dc21 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Fri, 23 May 2014 20:23:05 +0200 Subject: fmu: Rely on pwm_limit() call for band limits, do constrain instead of altering the direction / value --- src/drivers/px4fmu/fmu.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/drivers/px4fmu/fmu.cpp b/src/drivers/px4fmu/fmu.cpp index fd69cf795..8a4bfa18c 100644 --- a/src/drivers/px4fmu/fmu.cpp +++ b/src/drivers/px4fmu/fmu.cpp @@ -648,11 +648,9 @@ PX4FMU::task_main() /* iterate actuators */ for (unsigned i = 0; i < num_outputs; i++) { - /* last resort: catch NaN, INF and out-of-band errors */ - if (i >= outputs.noutputs || - !isfinite(outputs.output[i]) || - outputs.output[i] < -1.0f || - outputs.output[i] > 1.0f) { + /* last resort: catch NaN and INF */ + if ((i >= outputs.noutputs) || + !isfinite(outputs.output[i])) { /* * Value is NaN, INF or out of band - set to the minimum value. * This will be clearly visible on the servo status and will limit the risk of accidentally @@ -664,6 +662,7 @@ PX4FMU::task_main() uint16_t pwm_limited[num_outputs]; + /* the PWM limit call takes care of out of band errors and constrains */ pwm_limit_calc(_servo_armed, num_outputs, _disarmed_pwm, _min_pwm, _max_pwm, outputs.output, pwm_limited, &_pwm_limit); /* output to the servos */ -- cgit v1.2.3 From 0ea3e95422c4898b3ab93ba7b9b84cbdb76bad02 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Fri, 23 May 2014 20:23:33 +0200 Subject: px4iofirmware: Indicate with a comment that band limiting happens in pwm_limit() call --- src/modules/px4iofirmware/mixer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/modules/px4iofirmware/mixer.cpp b/src/modules/px4iofirmware/mixer.cpp index ebf4f3e8e..2f721bf1e 100644 --- a/src/modules/px4iofirmware/mixer.cpp +++ b/src/modules/px4iofirmware/mixer.cpp @@ -213,6 +213,7 @@ mixer_tick(void) mixed = mixer_group.mix(&outputs[0], PX4IO_SERVO_COUNT); in_mixer = false; + /* the pwm limit call takes care of out of band errors */ pwm_limit_calc(should_arm, mixed, r_page_servo_disarmed, r_page_servo_control_min, r_page_servo_control_max, outputs, r_page_servos, &pwm_limit); for (unsigned i = mixed; i < PX4IO_SERVO_COUNT; i++) -- cgit v1.2.3 From b4a03d8de540f71232672427491e4eb6e6df9f3c Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Fri, 23 May 2014 20:38:13 +0200 Subject: pwm_limit: Add missing case for the arming ramp --- src/modules/systemlib/pwm_limit/pwm_limit.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/modules/systemlib/pwm_limit/pwm_limit.c b/src/modules/systemlib/pwm_limit/pwm_limit.c index de2caf143..ea5ba9e52 100644 --- a/src/modules/systemlib/pwm_limit/pwm_limit.c +++ b/src/modules/systemlib/pwm_limit/pwm_limit.c @@ -136,6 +136,13 @@ void pwm_limit_calc(const bool armed, const unsigned num_channels, const uint16_ } effective_pwm[i] = output[i] * (max_pwm[i] - ramp_min_pwm)/2 + (max_pwm[i] + ramp_min_pwm)/2; + + /* last line of defense against invalid inputs */ + if (effective_pwm[i] < ramp_min_pwm) { + effective_pwm[i] = ramp_min_pwm; + } else if (effective_pwm[i] > max_pwm[i]) { + effective_pwm[i] = max_pwm[i]; + } } } break; -- cgit v1.2.3