From 2d83c9c029843fb03ea63ab957dbc96c49d3b8d2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 25 Feb 2024 12:45:23 +0200 Subject: [PATCH] Fix ramp function overflow --- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 4fde48fb..e3541261 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -202,8 +202,11 @@ void update_values_battery() { //This function maps all the values fetched via //The allowed charge power behaves strangely. We instead estimate this value if (system_scaled_SOC_pptt == 10000) { // When scaled SOC is 100.00%, set allowed charge power to 0 system_max_charge_power_W = 0; - } else if (soc_vi > RAMPDOWNSOC) { // When real SOC is between RAMPDOWNSOC-99.99%, ramp the value between Max<->0 - system_max_charge_power_W = MAXCHARGEPOWERALLOWED * (1 - (soc_vi - RAMPDOWNSOC) / 50.0); + } + if (soc_vi > 990) { + system_max_charge_power_W = FLOATPOWERMAX; + } else if (soc_vi > RAMPDOWNSOC) { // When real SOC is between RAMPDOWNSOC-99%, ramp the value between Max<->0 + system_max_charge_power_W = MAXCHARGEPOWERALLOWED * (1 - (soc_vi - RAMPDOWNSOC) / (1000.0 - RAMPDOWNSOC)); //If the cellvoltages start to reach overvoltage, only allow a small amount of power in if (system_LFP_Chemistry) { if (cell_max_v > (MAX_CELL_VOLTAGE_LFP - MILLIVOLTFLOAT)) {