Compare commits
3 Commits
cef05f52bc
...
fa3ef04b58
Author | SHA1 | Date |
---|---|---|
Jasper Blanckenburg | fa3ef04b58 | |
Jasper Blanckenburg | 7c7ae41ee6 | |
Jasper Blanckenburg | fdd9c3f4af |
|
@ -12,6 +12,7 @@
|
|||
#define CAN_ID_AMS_IN 0x00B
|
||||
#define CAN_ID_AMS_ERROR 0x00C
|
||||
#define CAN_ID_SLAVE_STATUS_BASE 0x080
|
||||
#define CAN_ID_SLAVE_STATUS_FUCKED 0x0A0
|
||||
#define CAN_ID_SLAVE_LOG 0x4F4
|
||||
#define CAN_ID_SHUNT_BASE 0x520
|
||||
#define CAN_ID_SHUNT_CURRENT 0x521
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
|
||||
#include "stm32f3xx_hal.h"
|
||||
|
||||
#define SHUNT_TIMEOUT 300 // ms
|
||||
#define SHUNT_THRESH_OVERCURRENT 300000 // mA
|
||||
#define SHUNT_THRESH_OVERTEMP 1000 // 1/10 °C
|
||||
#define SHUNT_TIMEOUT 300 // ms
|
||||
#define SHUNT_THRESH_OVERCURRENT 300000 // mA
|
||||
#define SHUNT_THRESH_OVERCURRENT_REGEN 50000 // mA
|
||||
#define SHUNT_THRESH_OVERTEMP 1000 // 1/10 °C
|
||||
|
||||
typedef struct {
|
||||
int32_t current; // mA
|
||||
|
|
|
@ -18,6 +18,7 @@ void can_init(CAN_HandleTypeDef *handle) {
|
|||
ftcan_add_filter(CAN_ID_AMS_IN, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_PANIC, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_STATUS_BASE, 0xFF0);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_STATUS_FUCKED, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_LOG, 0xFFF);
|
||||
}
|
||||
|
||||
|
@ -50,6 +51,8 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
|||
} else if ((id & 0xFF0) == CAN_ID_SLAVE_STATUS_BASE) {
|
||||
slaves_handle_status(data);
|
||||
return;
|
||||
} else if (id == CAN_ID_SLAVE_STATUS_FUCKED) {
|
||||
slaves_handle_status(data);
|
||||
}
|
||||
switch (id) {
|
||||
case CAN_ID_SLAVE_PANIC:
|
||||
|
|
|
@ -28,9 +28,10 @@ void shunt_check() {
|
|||
if (HAL_GetTick() - shunt_data.last_message > SHUNT_TIMEOUT) {
|
||||
is_error = 1;
|
||||
can_send_error(TS_ERRORKIND_SHUNT_TIMEOUT, 0);
|
||||
} else if (shunt_data.current >= SHUNT_THRESH_OVERCURRENT) {
|
||||
} else if (shunt_data.current >= SHUNT_THRESH_OVERCURRENT ||
|
||||
shunt_data.current <= -SHUNT_THRESH_OVERCURRENT_REGEN) {
|
||||
is_error = 1;
|
||||
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||
can_send_error(TS_ERRORKIND_SHUNT_OVERCURRENT, 0);
|
||||
} else if (shunt_data.busbartemp >= SHUNT_THRESH_OVERTEMP) {
|
||||
is_error = 1;
|
||||
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||
|
|
|
@ -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