Track raw battery voltage and filtered battery voltage separately. Estimate remaining battery as min(voltage_estimate, discharged_estimate). Battery voltage LPF time increased.

This commit is contained in:
Anton Babushkin
2013-11-11 22:02:55 +04:00
parent e8487b7498
commit 714f5ea634
6 changed files with 57 additions and 68 deletions

View File

@@ -44,6 +44,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <fcntl.h>
#include <math.h>
#include <uORB/uORB.h>
#include <uORB/topics/vehicle_status.h>
@@ -282,12 +283,15 @@ float battery_remaining_estimate_voltage(float voltage, float discharged)
counter++;
/* remaining charge estimate based on voltage */
float remaining_voltage = (voltage - bat_n_cells * bat_v_empty) / (bat_n_cells * (bat_v_full - bat_v_empty));
if (bat_capacity > 0.0f) {
/* if battery capacity is known, use it to estimate remaining charge */
ret = 1.0f - discharged / bat_capacity;
/* if battery capacity is known, use discharged current for estimate, but don't show more than voltage estimate */
ret = fminf(remaining_voltage, 1.0f - discharged / bat_capacity);
} else {
/* else use voltage */
ret = (voltage - bat_n_cells * bat_v_empty) / (bat_n_cells * (bat_v_full - bat_v_empty));
ret = remaining_voltage;
}
/* limit to sane values */