From c69f7bb1d052c9446ae08fdfc068cf3457e1783c Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 2 May 2018 17:19:12 +0900 Subject: [PATCH] AP_MotorsUGV: consolidate parameter sanity checks --- APMrover2/AP_MotorsUGV.cpp | 17 +++++++++++------ APMrover2/AP_MotorsUGV.h | 3 +++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/APMrover2/AP_MotorsUGV.cpp b/APMrover2/AP_MotorsUGV.cpp index b7b3c48a17..bab1f1016c 100644 --- a/APMrover2/AP_MotorsUGV.cpp +++ b/APMrover2/AP_MotorsUGV.cpp @@ -106,9 +106,6 @@ void AP_MotorsUGV::init() // set safety output setup_safety_output(); - - // sanity check parameters - _vector_throttle_base = constrain_float(_vector_throttle_base, 0.0f, 100.0f); } // setup output in case of main CPU failure @@ -162,9 +159,6 @@ void AP_MotorsUGV::set_steering(float steering) // set throttle as a value from -100 to 100 void AP_MotorsUGV::set_throttle(float throttle) { - // sanity check throttle min and max - _throttle_min = constrain_int16(_throttle_min, 0, 20); - _throttle_max = constrain_int16(_throttle_max, 30, 100); // check throttle is between -_throttle_max ~ +_throttle_max but outside -throttle_min ~ +throttle_min _throttle = constrain_float(throttle, -_throttle_max, _throttle_max); @@ -189,6 +183,9 @@ void AP_MotorsUGV::output(bool armed, float dt) armed = false; } + // sanity check parameters + sanity_check_parameters(); + // clear and set limits based on input (limit flags may be set again by output_regular or output_skid_steering methods) set_limits_from_input(armed, _steering, _throttle); @@ -333,6 +330,14 @@ bool AP_MotorsUGV::pre_arm_check(bool report) const return true; } +// sanity check parameters +void AP_MotorsUGV::sanity_check_parameters() +{ + _throttle_min = constrain_int16(_throttle_min, 0, 20); + _throttle_max = constrain_int16(_throttle_max, 30, 100); + _vector_throttle_base = constrain_float(_vector_throttle_base, 0.0f, 100.0f); +} + // setup pwm output type void AP_MotorsUGV::setup_pwm_type() { diff --git a/APMrover2/AP_MotorsUGV.h b/APMrover2/AP_MotorsUGV.h index 0a4fa3e47d..247c1b1492 100644 --- a/APMrover2/AP_MotorsUGV.h +++ b/APMrover2/AP_MotorsUGV.h @@ -74,6 +74,9 @@ public: protected: + // sanity check parameters + void sanity_check_parameters(); + // setup pwm output type void setup_pwm_type();