Store the result of get_inverter_temp to a member variable

This commit is contained in:
Unknown
2020-04-25 22:38:53 -04:00
parent c63d6baff0
commit 9ef3d0c6a1
2 changed files with 6 additions and 5 deletions
+3 -3
View File
@@ -150,8 +150,7 @@ float Motor::get_inverter_temp() {
return horner_fma(normalized_voltage, thermistor_poly_coeffs, thermistor_num_coeffs);
}
bool Motor::update_thermal_limits() {
float fet_temp = get_inverter_temp();
bool Motor::update_thermal_limits(float fet_temp) {
float temp_margin = config_.inverter_temp_limit_upper - fet_temp;
float derating_range = config_.inverter_temp_limit_upper - config_.inverter_temp_limit_lower;
thermal_current_lim_ = config_.current_lim * (temp_margin / derating_range);
@@ -170,7 +169,8 @@ bool Motor::do_checks() {
set_error(ERROR_DRV_FAULT);
return false;
}
if (!update_thermal_limits()) {
inverter_temp_ = get_inverter_temp();
if (!update_thermal_limits(inverter_temp_)) {
//error already set in function
return false;
}
+3 -2
View File
@@ -125,7 +125,7 @@ public:
void set_error(Error_t error);
bool do_checks();
float get_inverter_temp();
bool update_thermal_limits();
bool update_thermal_limits(float fet_temp);
float effective_current_lim();
void log_timing(TimingLog_t log_idx);
float phase_current_from_adcval(uint32_t ADCValue);
@@ -187,6 +187,7 @@ public:
DRV8301_FaultType_e drv_fault_ = DRV8301_FaultType_NoFault;
DRV_SPI_8301_Vars_t gate_driver_regs_; //Local view of DRV registers (initialized by DRV8301_setup)
float thermal_current_lim_ = 10.0f; //[A]
float inverter_temp_ = 20.0f;
// Communication protocol definitions
auto make_protocol_definitions() {
@@ -200,7 +201,7 @@ public:
make_protocol_property("DC_calib_phC", &DC_calib_.phC),
make_protocol_property("phase_current_rev_gain", &phase_current_rev_gain_),
make_protocol_ro_property("thermal_current_lim", &thermal_current_lim_),
make_protocol_function("get_inverter_temp", *this, &Motor::get_inverter_temp),
make_protocol_ro_property("inverter_temp", &inverter_temp_),
make_protocol_object("current_control",
make_protocol_property("p_gain", &current_control_.p_gain),
make_protocol_property("i_gain", &current_control_.i_gain),