Merge branch 'main' into feature/double-lilygo

This commit is contained in:
Daniel 2023-11-25 11:36:40 +02:00
commit 44fa2ba3b0
8 changed files with 175 additions and 26 deletions

View file

@ -34,7 +34,7 @@
#endif
#ifdef SERIAL_LINK_RECEIVER
#include "SERIAL-LINK-RECEIVER-FROM-BATTERY.h"
#include "SERIAL-LINK-RECEIVER-FROM-BATTERY.h" //See this file for more Serial-battery settings
#endif
#endif
#endif

View file

@ -241,6 +241,15 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
max_target_discharge_power = 0;
}
//Check if SOC% is plausible
if (battery_voltage >
(ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
if (LB_SOC < 650) {
bms_status = FAULT;
Serial.println("ERROR: SOC% reported by battery not plausible. Restart battery!");
}
}
if (LB_Full_CHARGE_flag) { //Battery reports that it is fully charged stop all further charging incase it hasn't already
max_target_charge_power = 0;
}

View file

@ -26,7 +26,6 @@ CAN_frame_t TESLA_221_2 = {
.MsgID = 0x221,
.data = {0x61, 0x15, 0x01, 0x00, 0x00, 0x00, 0x20, 0xBA}}; //Contactor Frame 221 - hv_up_for_drive
static uint32_t temporaryvariable = 0;
static uint32_t total_discharge = 0;
static uint32_t total_charge = 0;
static uint16_t volts = 0; // V
@ -156,8 +155,8 @@ static const char* hvilStatusState[] = {"NOT OK",
#define MIN_CELL_VOLTAGE_NCA_NCM 2950 //Battery is put into emergency stop if one cell goes below this value
#define MAX_CELL_DEVIATION_NCA_NCM 500 //LED turns yellow on the board if mv delta exceeds this value
#define MAX_CELL_VOLTAGE_LFP 3450 //Battery is put into emergency stop if one cell goes over this value
#define MIN_CELL_VOLTAGE_LFP 2800 //Battery is put into emergency stop if one cell goes over this value
#define MAX_CELL_VOLTAGE_LFP 3500 //Battery is put into emergency stop if one cell goes over this value
#define MIN_CELL_VOLTAGE_LFP 2800 //Battery is put into emergency stop if one cell goes below this value
#define MAX_CELL_DEVIATION_LFP 150 //LED turns yellow on the board if mv delta exceeds this value
void update_values_tesla_model_3_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
@ -186,19 +185,22 @@ void update_values_tesla_model_3_battery() { //This function maps all the value
remaining_capacity_Wh = (expected_energy_remaining * 100); //Scale up 60.3kWh -> 60300Wh
//Calculate the allowed discharge power, cap it if it gets too large
temporaryvariable = (max_discharge_current * volts);
if (temporaryvariable > 60000) {
max_target_discharge_power = 60000;
} else {
max_target_discharge_power = temporaryvariable;
// Define the allowed discharge power
max_target_discharge_power = (max_discharge_current * volts);
// Cap the allowed discharge power if battery is empty, or discharge power is higher than the maximum discharge power allowed
if (SOC == 0) {
max_target_discharge_power = 0;
} else if (max_target_discharge_power > MAXDISCHARGEPOWERALLOWED) {
max_target_discharge_power = MAXDISCHARGEPOWERALLOWED;
}
//The allowed charge power behaves strangely. We instead estimate this value
if (SOC == 10000) {
max_target_charge_power = 0; //When battery is 100% full, set allowed charge W to 0
} else {
max_target_charge_power = 15000; //Otherwise we can push 15kW into the pack!
if (SOC == 10000) { // When scaled SOC is 100%, set allowed charge power to 0
max_target_charge_power = 0;
} else if (soc_vi > 950) { // When real SOC is between 95-99.99%, ramp the value between Max<->0
max_target_charge_power = MAXCHARGEPOWERALLOWED * (1 - (soc_vi - 950) / 50.0);
} else { // No limits, max charging power allowed
max_target_charge_power = MAXCHARGEPOWERALLOWED;
}
stat_batt_power = (volts * amps); //TODO: check if scaling is OK

View file

@ -7,7 +7,10 @@
#define ABSOLUTE_MAX_VOLTAGE \
4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 2450 // 245.0V if battery voltage goes under this, discharging further is disabled
#define ABSOLUTE_MIN_VOLTAGE 2450 // 245.0V if battery voltage goes under this, discharging further is disabled
#define MAXCHARGEPOWERALLOWED 15000 // 15000W we use a define since the value supplied by Tesla is always 0
#define MAXDISCHARGEPOWERALLOWED \
60000 // 60000W we need to cap this value to max 60kW, most inverters overflow otherwise
// These parameters need to be mapped for the Inverter
extern uint16_t SOC;

View file

@ -189,7 +189,7 @@ void update_values_can_solax() { //This function maps all the values fetched fr
//BMS_PackTemps (strange name, since it has voltages?)
SOLAX_1876.data.u8[2] = (uint8_t)cell_max_voltage; //TODO: scaling OK?
SOLAX_1876.data.u8[3] = (cell_min_voltage >> 8);
SOLAX_1876.data.u8[3] = (cell_max_voltage >> 8);
SOLAX_1876.data.u8[6] = (uint8_t)cell_min_voltage; //TODO: scaling OK?
SOLAX_1876.data.u8[7] = (cell_min_voltage >> 8);