Fix coulomb counting
This commit is contained in:
parent
cef05f52bc
commit
fdd9c3f4af
|
@ -32,7 +32,7 @@ void soc_init() {
|
|||
|
||||
void soc_update() {
|
||||
uint32_t now = HAL_GetTick();
|
||||
if (shunt_data.current >= SOC_ESTIMATION_NO_CURRENT_THRESH) {
|
||||
if (abs(shunt_data.current) >= SOC_ESTIMATION_NO_CURRENT_THRESH) {
|
||||
last_current_time = now;
|
||||
if (!current_was_flowing) {
|
||||
soc_before_current = current_soc;
|
||||
|
@ -52,7 +52,7 @@ void soc_update() {
|
|||
// Otherwise, use the current counter to update SoC
|
||||
float as_delta = shunt_data.current_counter - mAs_before_current;
|
||||
float soc_delta = as_delta / SOC_ESTIMATION_BATTERY_CAPACITY * 100;
|
||||
current_soc = soc_before_current + soc_delta;
|
||||
current_soc = soc_before_current - soc_delta;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue