Rework discharge calculation

This commit is contained in:
Daniel 2023-11-22 22:23:54 +02:00
parent 36deffd9e9
commit e2d3c4f023
2 changed files with 9 additions and 10 deletions

View file

@ -26,7 +26,6 @@ CAN_frame_t TESLA_221_2 = {
.MsgID = 0x221, .MsgID = 0x221,
.data = {0x61, 0x15, 0x01, 0x00, 0x00, 0x00, 0x20, 0xBA}}; //Contactor Frame 221 - hv_up_for_drive .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_discharge = 0;
static uint32_t total_charge = 0; static uint32_t total_charge = 0;
static uint16_t volts = 0; // V static uint16_t volts = 0; // V
@ -186,15 +185,13 @@ 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 remaining_capacity_Wh = (expected_energy_remaining * 100); //Scale up 60.3kWh -> 60300Wh
//Calculate the allowed discharge power, cap it if it gets too large // Define the allowed discharge power
temporaryvariable = (max_discharge_current * volts); max_target_discharge_power = (max_discharge_current * volts);
if (temporaryvariable > 60000) { // Cap the allowed discharge power if battery is empty, or discharge power is higher than the maximum discharge power allowed
max_target_discharge_power = 60000; if (SOC == 0) {
} else {
max_target_discharge_power = temporaryvariable;
}
if (SOC < 20) { // When battery is lower than 0.20% , set allowed discharge W to 0
max_target_discharge_power = 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 //The allowed charge power behaves strangely. We instead estimate this value

View file

@ -9,6 +9,8 @@
4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) 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 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 // These parameters need to be mapped for the Inverter
extern uint16_t SOC; extern uint16_t SOC;