From 7a5a28d056d2ea8090f75c4bc565f897c2b50def Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Tue, 9 Jul 2024 21:25:20 +0200 Subject: [PATCH] Sign fixes for SoC estimation --- Core/Src/shunt_monitoring.c | 2 +- Core/Src/soc_estimation.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/Src/shunt_monitoring.c b/Core/Src/shunt_monitoring.c index 57ae38e..22a5265 100644 --- a/Core/Src/shunt_monitoring.c +++ b/Core/Src/shunt_monitoring.c @@ -54,7 +54,7 @@ void shunt_handle_can_msg(uint16_t id, const uint8_t *data) { if (shunt_data.last_current_message > 0) { uint32_t now = HAL_GetTick(); float dt = (now - shunt_data.last_current_message) * 0.001f; - shunt_data.current_counter -= shunt_data.current * dt; + shunt_data.current_counter += shunt_data.current * dt; } shunt_data.last_current_message = HAL_GetTick(); break; diff --git a/Core/Src/soc_estimation.c b/Core/Src/soc_estimation.c index 3720d0b..8143ddd 100644 --- a/Core/Src/soc_estimation.c +++ b/Core/Src/soc_estimation.c @@ -7,6 +7,7 @@ #include #include +#include #define SOC_ESTIMATION_NO_CURRENT_THRESH 200 // mA #define SOC_ESTIMATION_NO_CURRENT_TIME 100000 // ms @@ -32,7 +33,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;