From 5262fe863b9df002e12565476522d49171ff36b1 Mon Sep 17 00:00:00 2001 From: shaynoorani <113149316+shaynoorani@users.noreply.github.com> Date: Mon, 20 May 2024 23:53:20 -0700 Subject: [PATCH] Added Derate Factor code to AMS interface --- lib/interfaces/include/AMSInterface.h | 4 +++- lib/interfaces/src/AMSInterface.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/interfaces/include/AMSInterface.h b/lib/interfaces/include/AMSInterface.h index 4227c3a37..e499a7de7 100644 --- a/lib/interfaces/include/AMSInterface.h +++ b/lib/interfaces/include/AMSInterface.h @@ -60,7 +60,8 @@ class AMSInterface float get_filtered_max_cell_temp(); /* IIR filter and return filtered min cell voltage */ float get_filtered_min_cell_voltage(); - + /*gets the derate factor for acc system*/ + float get_acc_derate_factor(); //RETRIEVE CAN MESSAGES// /* read BMS status messages */ void retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg); @@ -94,6 +95,7 @@ class AMSInterface float filtered_min_cell_voltage; float cell_temp_alpha; float cell_voltage_alpha; + float acc_derate_factor; }; #endif /* __AMSINTERFACE_H__ */ diff --git a/lib/interfaces/src/AMSInterface.cpp b/lib/interfaces/src/AMSInterface.cpp index 14af00e5a..c142db5c8 100644 --- a/lib/interfaces/src/AMSInterface.cpp +++ b/lib/interfaces/src/AMSInterface.cpp @@ -57,6 +57,33 @@ float AMSInterface::get_filtered_max_cell_temp() { return filtered_max_cell_temp; } +float AMSInterface::get_acc_derate_factor() { + float voltage_lim_factor = 1.0; + float startDerateVoltage = 3.5; + float endDerateVoltage = 3.2; + float voltage_lim_max = 1; + float voltage_lim_min = 0.2; + + float temp_lim_factor = 1.0; + float startDerateTemp = 50; + float stopDerateTemp = 58; + float temp_lim_max = 1; + float temp_lim_min = 0.2; + + float filtered_min_cell_voltage = get_filtered_min_cell_voltage(); + //float_map equivalient because new code is bad + voltage_lim_factor = (filtered_min_cell_voltage - startDerateVoltage) * (voltage_lim_min - voltage_lim_max) / (endDerateVoltage - startDerateVoltage) + voltage_lim_max; + voltage_lim_factor = max(min(voltage_lim_max, voltage_lim_factor), voltage_lim_min); + + temp_lim_factor = (filtered_max_cell_temp - startDerateTemp) * (temp_lim_min - temp_lim_max) / (stopDerateTemp - startDerateTemp) + temp_lim_max; + temp_lim_factor = max(min(temp_lim_factor, temp_lim_max), temp_lim_min); + + acc_derate_factor = min(temp_lim_factor,voltage_lim_factor); + return acc_derate_factor; +} + +} + float AMSInterface::get_filtered_min_cell_voltage() { bms_low_voltage = bms_voltages_.get_low() / 10000.0; filtered_min_cell_voltage = filtered_min_cell_voltage * cell_temp_alpha + (1.0 - cell_voltage_alpha) * bms_low_voltage;