Improve safety for stopping charge/discharge when battery is full/empty

This commit is contained in:
Daniel Öster 2025-07-27 16:31:08 +03:00
parent 2b6ad122bb
commit 28a337684d

View file

@ -130,7 +130,8 @@ void update_machineryprotection() {
// Battery is fully charged. Dont allow any more power into it // Battery is fully charged. Dont allow any more power into it
// Normally the BMS will send 0W allowed, but this acts as an additional layer of safety // Normally the BMS will send 0W allowed, but this acts as an additional layer of safety
if (datalayer.battery.status.reported_soc == 10000) //Scaled SOC% value is 100.00% if (datalayer.battery.status.reported_soc == 10000 ||
datalayer.battery.status.real_soc == 10000) //Either Scaled OR Real SOC% value is 100.00%
{ {
if (!battery_full_event_fired) { if (!battery_full_event_fired) {
set_event(EVENT_BATTERY_FULL, 0); set_event(EVENT_BATTERY_FULL, 0);
@ -145,7 +146,8 @@ void update_machineryprotection() {
// Battery is empty. Do not allow further discharge. // Battery is empty. Do not allow further discharge.
// Normally the BMS will send 0W allowed, but this acts as an additional layer of safety // Normally the BMS will send 0W allowed, but this acts as an additional layer of safety
if (datalayer.battery.status.bms_status == ACTIVE) { if (datalayer.battery.status.bms_status == ACTIVE) {
if (datalayer.battery.status.reported_soc == 0) { //Scaled SOC% value is 0.00% if (datalayer.battery.status.reported_soc == 0 ||
datalayer.battery.status.real_soc == 0) { //Either Scaled OR Real SOC% value is 0.00%, time to stop
if (!battery_empty_event_fired) { if (!battery_empty_event_fired) {
set_event(EVENT_BATTERY_EMPTY, 0); set_event(EVENT_BATTERY_EMPTY, 0);
battery_empty_event_fired = true; battery_empty_event_fired = true;