Skip to content

Commit

Permalink
Updated AMS interface to include derate factor
Browse files Browse the repository at this point in the history
  • Loading branch information
shaynoorani committed May 26, 2024
1 parent ecf55e3 commit 6cbaf6d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/interfaces/include/AMSInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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__ */
27 changes: 27 additions & 0 deletions lib/interfaces/src/AMSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


0 comments on commit 6cbaf6d

Please sign in to comment.