From 6cbaf6de176a4f969b5add07a755b6ca7406edbf Mon Sep 17 00:00:00 2001 From: shaynoorani <113149316+shaynoorani@users.noreply.github.com> Date: Sun, 26 May 2024 14:15:55 -0700 Subject: [PATCH] Updated AMS interface to include derate factor --- lib/interfaces/include/AMSInterface.h | 5 +++++ lib/interfaces/src/AMSInterface.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/interfaces/include/AMSInterface.h b/lib/interfaces/include/AMSInterface.h index 4227c3a37..8d7c4ca61 100644 --- a/lib/interfaces/include/AMSInterface.h +++ b/lib/interfaces/include/AMSInterface.h @@ -60,6 +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 */ @@ -68,6 +70,8 @@ class AMSInterface void retrieve_temp_CAN(CAN_message_t &recvd_msg); /* read BMS voltage messages */ void retrieve_voltage_CAN(CAN_message_t &recvd_msg); + /*Updates Acc_derate_factor*/ + void calculate_acc_derate_factor(); private: /* Private functions */ @@ -94,6 +98,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..349d911d2 100644 --- a/lib/interfaces/src/AMSInterface.cpp +++ b/lib/interfaces/src/AMSInterface.cpp @@ -76,5 +76,32 @@ void AMSInterface::retrieve_temp_CAN(CAN_message_t &recvd_msg) { void AMSInterface::retrieve_voltage_CAN(CAN_message_t &recvd_msg) { bms_voltages_.load(recvd_msg.buf); } +void AMSInterface::calculate_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); +} + +float AMSInterface::get_acc_derate_factor() { + return acc_derate_factor; +}