Skip to content

Commit

Permalink
Added Derate Factor code to AMS interface
Browse files Browse the repository at this point in the history
  • Loading branch information
shaynoorani committed May 21, 2024
1 parent 207b299 commit 5262fe8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/interfaces/include/AMSInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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__ */
27 changes: 27 additions & 0 deletions lib/interfaces/src/AMSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5262fe8

Please sign in to comment.