Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion projects/tms/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ FanController fan_controller{bindings::fan_controller_pwm};

VehBus veh_can_bus{bindings::veh_can_base};

TxTMSValues TMSBroadcast(const std::array<float, kSensorCount>& temperatures) {
return TxTMSValues{
.val1 = static_cast<uint8_t>(bindings::temp_sensor_adc_1.ReadVoltage() *
50.0f),
.val2 = static_cast<uint8_t>(bindings::temp_sensor_adc_2.ReadVoltage() *
50.0f),
.val3 = static_cast<uint8_t>(bindings::temp_sensor_adc_3.ReadVoltage() *
50.0f),
.val4 = static_cast<uint8_t>(bindings::temp_sensor_adc_4.ReadVoltage() *
50.0f),
.val5 = static_cast<uint8_t>(bindings::temp_sensor_adc_5.ReadVoltage() *
50.0f),
.val6 = static_cast<uint8_t>(bindings::temp_sensor_adc_6.ReadVoltage() *
50.0f),
};
}

TxBmsBroadcast PackBmsBroadcast(
const std::array<float, kSensorCount>& temperatures) {
// Compute the min, max, and avg temperatures
Expand All @@ -58,7 +75,7 @@ TxBmsBroadcast PackBmsBroadcast(
auto t = static_cast<int8_t>(temperatures[i]);
if (t < low_temp) {
low_temp = t;
low_index = 1;
low_index = i;
}
if (t > high_temp) {
high_temp = t;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions projects/tms/src/temp_sensor/temp_sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions projects/veh.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading