diff --git a/projects/tms/src/main.cc b/projects/tms/src/main.cc index 312b51755..27f94ff2d 100644 --- a/projects/tms/src/main.cc +++ b/projects/tms/src/main.cc @@ -43,6 +43,23 @@ FanController fan_controller{bindings::fan_controller_pwm}; VehBus veh_can_bus{bindings::veh_can_base}; +TxTMSValues TMSBroadcast(const std::array& temperatures) { + return TxTMSValues{ + .val1 = static_cast(bindings::temp_sensor_adc_1.ReadVoltage() * + 50.0f), + .val2 = static_cast(bindings::temp_sensor_adc_2.ReadVoltage() * + 50.0f), + .val3 = static_cast(bindings::temp_sensor_adc_3.ReadVoltage() * + 50.0f), + .val4 = static_cast(bindings::temp_sensor_adc_4.ReadVoltage() * + 50.0f), + .val5 = static_cast(bindings::temp_sensor_adc_5.ReadVoltage() * + 50.0f), + .val6 = static_cast(bindings::temp_sensor_adc_6.ReadVoltage() * + 50.0f), + }; +} + TxBmsBroadcast PackBmsBroadcast( const std::array& temperatures) { // Compute the min, max, and avg temperatures @@ -58,7 +75,7 @@ TxBmsBroadcast PackBmsBroadcast( auto t = static_cast(temperatures[i]); if (t < low_temp) { low_temp = t; - low_index = 1; + low_index = i; } if (t > high_temp) { high_temp = t; @@ -101,7 +118,10 @@ void Update(float update_period_ms) { // Send the temperatures to the BMS TxBmsBroadcast bms_broadcast = PackBmsBroadcast(temperatures); + TxTMSValues tms = TMSBroadcast(temperatures); + veh_can_bus.Send(bms_broadcast); + veh_can_bus.Send(tms); // Adjust the fan speed based on the average temperature fan_controller.Update(avg_temp, update_period_ms); diff --git a/projects/tms/src/temp_sensor/temp_sensor.cc b/projects/tms/src/temp_sensor/temp_sensor.cc index 7c2c77074..d1377b72d 100644 --- a/projects/tms/src/temp_sensor/temp_sensor.cc +++ b/projects/tms/src/temp_sensor/temp_sensor.cc @@ -21,6 +21,7 @@ float TempSensor::Read() { /// buffer between them. V_STM = 1.44 + 0.836 * V_TS / 2 So the /// inverse is V_TS = 2 * (V_STM - 1.44) / 0.83 float volt_at_tempsensor = 2 * (volt_at_stm - 1.44) / 0.836; + float temperature = macfe::LookupTable::Evaluate(volt_ts_to_degC, volt_at_tempsensor); diff --git a/projects/veh.dbc b/projects/veh.dbc index 22e1cea9f..1ee8c8799 100644 --- a/projects/veh.dbc +++ b/projects/veh.dbc @@ -290,6 +290,15 @@ BO_ 2553934720 BmsBroadcast: 8 TMS SG_ LowThermID : 48|8@1+ (1,0) [0|0] "" BMS SG_ Checksum : 56|8@1+ (1,0) [0|0] "" BMS +BO_ 204 TMSValues: 6 TMS + SG_ val1 : 0|8@1+ (1,0) [0|0] "" BMS + SG_ val2 : 8|8@1+ (1,0) [0|0] "" BMS + SG_ val3 : 16|8@1+ (1,0) [0|0] "" BMS + SG_ val4 : 24|8@1+ (1,0) [0|0] "" BMS + SG_ val5 : 32|8@1+ (1,0) [0|0] "" BMS + SG_ val6 : 40|8@1+ (1,0) [0|0] "" BMS + + BO_ 2566844926 ThermistorBroadcast: 8 TMS SG_ RelThermID : 0|16@1+ (1,0) [0|0] "" BMS SG_ ThermValue : 16|8@1- (1,0) [0|0] " C" BMS