File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ class Sensors : public ParamListenerInterface
122122 void correct_mag (void );
123123 void correct_baro (void );
124124 void correct_diff_pressure (void );
125+ void lpf_battery (void );
125126 void update_battery_monitor_multipliers (void );
126127
127128 // IMU calibration
@@ -151,6 +152,8 @@ class Sensors : public ParamListenerInterface
151152 // Battery Monitor
152153 float battery_voltage_alpha_{0.995 };
153154 float battery_current_alpha_{0.995 };
155+ float previous_battery_voltage_{0.0 };
156+ float previous_battery_current_{0.0 };
154157};
155158
156159} // namespace rosflight_firmware
Original file line number Diff line number Diff line change @@ -52,7 +52,9 @@ const float Sensors::DIFF_PRESSURE_MAX_CALIBRATION_VARIANCE = 100.0; // standard
5252
5353Sensors::Sensors (ROSflight & rosflight)
5454 : rf_(rosflight)
55- {}
55+ {
56+ previous_battery_voltage_ = rf_.params_ .get_param_float (PARAM_BATTERY_VOLTAGE_ALPHA);
57+ }
5658
5759void Sensors::init ()
5860{
@@ -169,7 +171,9 @@ got_flags Sensors::run()
169171 got.sonar = rf_.board_ .sonar_read (&sonar_);
170172
171173 // BATTERY_MONITOR:
172- got.battery = rf_.board_ .battery_read (&battery_);
174+ if ((got.battery = rf_.board_ .battery_read (&battery_))) {
175+ lpf_battery ();
176+ }
173177
174178 return got;
175179}
@@ -477,6 +481,14 @@ void Sensors::correct_diff_pressure()
477481 * sqrt ((fabs (diff_pressure_.pressure ) / (0.5 * 1.225 )));
478482}
479483
484+ void Sensors::lpf_battery ()
485+ {
486+ battery_.voltage = battery_.voltage * (1.0 - battery_voltage_alpha_) + previous_battery_voltage_ * battery_voltage_alpha_;
487+ battery_.current = battery_.current * (1.0 - battery_current_alpha_) + previous_battery_current_ * battery_current_alpha_;
488+ previous_battery_voltage_ = battery_.voltage ;
489+ previous_battery_current_ = battery_.current ;
490+ }
491+
480492void Sensors::update_battery_monitor_multipliers ()
481493{
482494 float voltage_multiplier = this ->rf_ .params_ .get_param_float (PARAM_BATTERY_VOLTAGE_MULTIPLIER);
You can’t perform that action at this time.
0 commit comments