diff options
author | Anton Babushkin <anton.babushkin@me.com> | 2013-11-11 22:02:55 +0400 |
---|---|---|
committer | Anton Babushkin <anton.babushkin@me.com> | 2013-11-11 22:02:55 +0400 |
commit | 714f5ea634a184ac80254e2a415221f738d2ecd6 (patch) | |
tree | 74ab7ba9332964a49c03ee6f59b3ccbb748bc9af /src/modules/commander/commander_helper.cpp | |
parent | e8487b7498e8a47dd93915f7ace10d97618a6969 (diff) | |
download | px4-firmware-714f5ea634a184ac80254e2a415221f738d2ecd6.tar.gz px4-firmware-714f5ea634a184ac80254e2a415221f738d2ecd6.tar.bz2 px4-firmware-714f5ea634a184ac80254e2a415221f738d2ecd6.zip |
Track raw battery voltage and filtered battery voltage separately. Estimate remaining battery as min(voltage_estimate, discharged_estimate). Battery voltage LPF time increased.
Diffstat (limited to 'src/modules/commander/commander_helper.cpp')
-rw-r--r-- | src/modules/commander/commander_helper.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/modules/commander/commander_helper.cpp b/src/modules/commander/commander_helper.cpp index 49fe5ea4d..21a1c4c2c 100644 --- a/src/modules/commander/commander_helper.cpp +++ b/src/modules/commander/commander_helper.cpp @@ -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 */ |