From 997c6f0868d310b1833a72c15a0a3559ffa323d8 Mon Sep 17 00:00:00 2001 From: Leonard Hall Date: Mon, 23 Feb 2015 13:52:39 +0900 Subject: [PATCH] Motors: move battery resistance calcs to parent Moving from MotorsMatrix to parent Motors class allows these to be used from other frame types Also initialise battery resistance --- libraries/AP_Motors/AP_MotorsMatrix.cpp | 13 +------------ libraries/AP_Motors/AP_Motors_Class.cpp | 26 +++++++++++++++++++++++++ libraries/AP_Motors/AP_Motors_Class.h | 3 +++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/libraries/AP_Motors/AP_MotorsMatrix.cpp b/libraries/AP_Motors/AP_MotorsMatrix.cpp index 5bcc4a9aaf..9d1f5976ca 100644 --- a/libraries/AP_Motors/AP_MotorsMatrix.cpp +++ b/libraries/AP_Motors/AP_MotorsMatrix.cpp @@ -179,9 +179,6 @@ void AP_MotorsMatrix::output_armed() // Every thing is limited limit.roll_pitch = true; limit.yaw = true; - _batt_voltage_resting = _batt_voltage; - _batt_current_resting = _batt_current; - _batt_timer = 0; } else { @@ -190,14 +187,6 @@ void AP_MotorsMatrix::output_armed() limit.throttle_lower = true; } - // calculate battery resistance - int16_t hov_out_pwm = get_hover_throttle_as_pwm(); - if (_batt_timer < 400 && _rc_throttle.radio_out >= hov_out_pwm && ((_batt_current_resting*2.0f) < _batt_current)) { - // filter reaches 90% in 1/4 the test time - _batt_resistance += 0.05*(( (_batt_voltage_resting-_batt_voltage)/(_batt_current-_batt_current_resting) ) - _batt_resistance); - _batt_timer += 1; - } - // calculate roll and pitch for each motor // set rpy_low and rpy_high to the lowest and highest values of the motors for (i=0; i= _hover_out) { + // filter reaches 90% in 1/4 the test time + _batt_resistance += 0.05f*(( (_batt_voltage_resting-_batt_voltage)/(_batt_current-_batt_current_resting) ) - _batt_resistance); + _batt_timer += 1; + } else { + // initialize battery resistance to prevent change in resting voltage estimate + _batt_resistance = ((_batt_voltage_resting-_batt_voltage)/(_batt_current-_batt_current_resting)); + } + } + } +} diff --git a/libraries/AP_Motors/AP_Motors_Class.h b/libraries/AP_Motors/AP_Motors_Class.h index d63ab213ba..dbb57f3849 100644 --- a/libraries/AP_Motors/AP_Motors_Class.h +++ b/libraries/AP_Motors/AP_Motors_Class.h @@ -190,6 +190,9 @@ protected: // update_lift_max_from_batt_voltage - used for voltage compensation void update_lift_max_from_batt_voltage(); + // update_battery_resistance - calculate battery resistance when throttle is above hover_out + void update_battery_resistance(); + // flag bitmask struct AP_Motors_flags { uint8_t armed : 1; // 1 if the motors are armed, 0 if disarmed