Skip to content

Commit

Permalink
Merge pull request #327 from amarofarinha/main
Browse files Browse the repository at this point in the history
Max Charge / Discharge Limit Failures - Fix Charge / Discharge Limit exceeded early events
  • Loading branch information
amarofarinha authored May 29, 2024
2 parents 81c0c30 + e1c2b7a commit ccec28a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Software/src/devboard/safety/safety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../utils/events.h"

static uint16_t cell_deviation_mV = 0;
static uint8_t charge_discharge_limit_failures = 0;

void update_machineryprotection() {
// Start checking that the battery is within reason. Incase we see any funny business, raise an event!
Expand Down Expand Up @@ -82,18 +83,28 @@ void update_machineryprotection() {
// Inverter is charging with more power than battery wants!
if (datalayer.battery.status.active_power_W > 0) { // Charging
if (datalayer.battery.status.active_power_W > (datalayer.battery.status.max_charge_power_W + 2000)) {
set_event(EVENT_CHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
if (charge_discharge_limit_failures > MAX_CHARGE_DISCHARGE_LIMIT_FAILURES) {
set_event(EVENT_CHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
} else {
charge_discharge_limit_failures++;
}
} else {
clear_event(EVENT_CHARGE_LIMIT_EXCEEDED);
charge_discharge_limit_failures = 0;
}
}

// Inverter is pulling too much power from battery!
if (datalayer.battery.status.active_power_W < 0) { // Discharging
if (-datalayer.battery.status.active_power_W > (datalayer.battery.status.max_discharge_power_W + 2000)) {
set_event(EVENT_DISCHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
if (charge_discharge_limit_failures > MAX_CHARGE_DISCHARGE_LIMIT_FAILURES) {
set_event(EVENT_DISCHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
} else {
charge_discharge_limit_failures++;
}
} else {
clear_event(EVENT_DISCHARGE_LIMIT_EXCEEDED);
charge_discharge_limit_failures = 0;
}
}

Expand Down
2 changes: 2 additions & 0 deletions Software/src/devboard/safety/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#define MAX_CAN_FAILURES 50

#define MAX_CHARGE_DISCHARGE_LIMIT_FAILURES 1

void update_machineryprotection();

#endif

0 comments on commit ccec28a

Please sign in to comment.