Sign fixes for SoC estimation

This commit is contained in:
Jasper Blanckenburg 2024-07-09 21:25:20 +02:00
parent 0a9b178cc1
commit 7a5a28d056
2 changed files with 3 additions and 2 deletions

View File

@ -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;

View File

@ -7,6 +7,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#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;