From d2b5f2d170481470ef0d7f1e3f62e1cea37f0a2f Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Mon, 4 May 2026 19:26:56 -0400 Subject: [PATCH 1/8] created new interface for brake rotor temp sensors --- lib/interfaces/include/BrakeRotorTemp.h | 52 +++++++ lib/interfaces/src/BrakeRotorTemp.cpp | 175 ++++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 lib/interfaces/include/BrakeRotorTemp.h create mode 100644 lib/interfaces/src/BrakeRotorTemp.cpp diff --git a/lib/interfaces/include/BrakeRotorTemp.h b/lib/interfaces/include/BrakeRotorTemp.h new file mode 100644 index 0000000..11c1b78 --- /dev/null +++ b/lib/interfaces/include/BrakeRotorTemp.h @@ -0,0 +1,52 @@ +#ifndef BRAKEROTORTEMP_H +#define BRAKEROTORTEMP_H + +/* External libraries */ +#include "FlexCAN_T4.h" +#include "etl/singleton.h" + + +namespace BrakeRotorTempDefaultParams { + constexpr size_t channels_within_brake_temp_sensor = 16; // TODO: check if our sensors are actually 16 channel +} + +struct BrakeTempSensorData_s { + float max_temp; + float avg_temp; + + std::array channel_data; +}; + +struct BrakeTempData_s { + BrakeTempSensorData_s fl_sensor; + BrakeTempSensorData_s fr_sensor; +}; + +class BrakeRotorTemp +{ + public: + // default empty constructor will init state to zeros + BrakeRotorTemp() {} + + /** + * Retrieves the latest data that has been sent from the sensors + * @return the latest temp data + */ + BrakeTempData_s getBrakeRotorTempData() const; + + /** + * CAN receive function to parse the new CAN msg and update internal state + * Called by VCF's recv switch + * @param msg the CAN msg to parse + */ + void receiveBrakeRotorTempData(const CAN_message_t &msg); + + private: + BrakeTempData_s _temp_data; + + void _updateCalculatedValues(bool sensor); +}; + +using BrakeRotorTempInstance = etl::singleton; + +#endif // BRAKEROTORTEMP_H \ No newline at end of file diff --git a/lib/interfaces/src/BrakeRotorTemp.cpp b/lib/interfaces/src/BrakeRotorTemp.cpp new file mode 100644 index 0000000..58fe7b5 --- /dev/null +++ b/lib/interfaces/src/BrakeRotorTemp.cpp @@ -0,0 +1,175 @@ +#include "BrakeRotorTemp.h" + +#include "hytech.h" + +BrakeTempData_s BrakeRotorTemp::getBrakeRotorTempData() const { + return _temp_data; +} + +void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { + switch (msg.id) { + case FL_BRAKE_ROTOR_TEMP_CH1_CH4_CANID: + { + // unpack the msg + FL_BRAKE_ROTOR_TEMP_CH1_CH4_t unpacked_msg; + Unpack_FL_BRAKE_ROTOR_TEMP_CH1_CH4_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<0>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_1_ro_fromS(unpacked_msg.brake_temp_channel_1_ro); + std::get<1>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_2_ro_fromS(unpacked_msg.brake_temp_channel_2_ro); + std::get<2>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_3_ro_fromS(unpacked_msg.brake_temp_channel_3_ro); + std::get<3>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_4_ro_fromS(unpacked_msg.brake_temp_channel_4_ro); + + // update FL outputs + _updateCalculatedValues(0); + break; + } + + case FL_BRAKE_ROTOR_TEMP_CH5_CH8_CANID: + { + // unpack the msg + FL_BRAKE_ROTOR_TEMP_CH5_CH8_t unpacked_msg; + Unpack_FL_BRAKE_ROTOR_TEMP_CH5_CH8_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<4>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_5_ro_fromS(unpacked_msg.brake_temp_channel_5_ro); + std::get<5>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_6_ro_fromS(unpacked_msg.brake_temp_channel_6_ro); + std::get<6>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_7_ro_fromS(unpacked_msg.brake_temp_channel_7_ro); + std::get<7>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_8_ro_fromS(unpacked_msg.brake_temp_channel_8_ro); + + // update FL outputs + _updateCalculatedValues(0); + break; + } + + case FL_BRAKE_ROTOR_TEMP_CH9_CH12_CANID: + { + // unpack the msg + FL_BRAKE_ROTOR_TEMP_CH9_CH12_t unpacked_msg; + Unpack_FL_BRAKE_ROTOR_TEMP_CH9_CH12_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<8>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_9_ro_fromS(unpacked_msg.brake_temp_channel_9_ro); + std::get<9>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_10_ro_fromS(unpacked_msg.brake_temp_channel_10_ro); + std::get<10>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_11_ro_fromS(unpacked_msg.brake_temp_channel_11_ro); + std::get<11>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_12_ro_fromS(unpacked_msg.brake_temp_channel_12_ro); + + // update FL outputs + _updateCalculatedValues(0); + break; + } + + case FL_BRAKE_ROTOR_TEMP_CH13_CH16_CANID: + { + // unpack the msg + FL_BRAKE_ROTOR_TEMP_CH13_CH16_t unpacked_msg; + Unpack_FL_BRAKE_ROTOR_TEMP_CH13_CH16_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<12>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_13_ro_fromS(unpacked_msg.brake_temp_channel_13_ro); + std::get<13>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_14_ro_fromS(unpacked_msg.brake_temp_channel_14_ro); + std::get<14>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_15_ro_fromS(unpacked_msg.brake_temp_channel_15_ro); + std::get<15>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_16_ro_fromS(unpacked_msg.brake_temp_channel_16_ro); + + // update FL outputs + _updateCalculatedValues(0); + break; + } + + case FR_BRAKE_ROTOR_TEMP_CH1_CH4_CANID: + { + // unpack the msg + FR_BRAKE_ROTOR_TEMP_CH1_CH4_t unpacked_msg; + Unpack_FR_BRAKE_ROTOR_TEMP_CH1_CH4_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<0>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_1_ro_fromS(unpacked_msg.brake_temp_channel_1_ro); + std::get<1>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_2_ro_fromS(unpacked_msg.brake_temp_channel_2_ro); + std::get<2>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_3_ro_fromS(unpacked_msg.brake_temp_channel_3_ro); + std::get<3>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_4_ro_fromS(unpacked_msg.brake_temp_channel_4_ro); + + // update FR outputs + _updateCalculatedValues(1); + break; + } + + case FR_BRAKE_ROTOR_TEMP_CH5_CH8_CANID: + { + // unpack the msg + FR_BRAKE_ROTOR_TEMP_CH5_CH8_t unpacked_msg; + Unpack_FR_BRAKE_ROTOR_TEMP_CH5_CH8_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<4>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_5_ro_fromS(unpacked_msg.brake_temp_channel_5_ro); + std::get<5>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_6_ro_fromS(unpacked_msg.brake_temp_channel_6_ro); + std::get<6>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_7_ro_fromS(unpacked_msg.brake_temp_channel_7_ro); + std::get<7>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_8_ro_fromS(unpacked_msg.brake_temp_channel_8_ro); + + // update FR outputs + _updateCalculatedValues(1); + break; + } + + case FR_BRAKE_ROTOR_TEMP_CH9_CH12_CANID: + { + // unpack the msg + FR_BRAKE_ROTOR_TEMP_CH9_CH12_t unpacked_msg; + Unpack_FR_BRAKE_ROTOR_TEMP_CH9_CH12_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<8>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_9_ro_fromS(unpacked_msg.brake_temp_channel_9_ro); + std::get<9>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_10_ro_fromS(unpacked_msg.brake_temp_channel_10_ro); + std::get<10>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_11_ro_fromS(unpacked_msg.brake_temp_channel_11_ro); + std::get<11>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_12_ro_fromS(unpacked_msg.brake_temp_channel_12_ro); + + // update FR outputs + _updateCalculatedValues(1); + break; + } + + case FR_BRAKE_ROTOR_TEMP_CH13_CH16_CANID: + { + // unpack the msg + FR_BRAKE_ROTOR_TEMP_CH13_CH16_t unpacked_msg; + Unpack_FR_BRAKE_ROTOR_TEMP_CH13_CH16_hytech(&unpacked_msg, msg.buf, msg.len); + + // copy data over to interface data + std::get<12>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_13_ro_fromS(unpacked_msg.brake_temp_channel_13_ro); + std::get<13>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_14_ro_fromS(unpacked_msg.brake_temp_channel_14_ro); + std::get<14>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_15_ro_fromS(unpacked_msg.brake_temp_channel_15_ro); + std::get<15>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_16_ro_fromS(unpacked_msg.brake_temp_channel_16_ro); + + // update FR outputs + _updateCalculatedValues(1); + break; + } + + default: + break; + } +} + +/** + * Helper method to update the calculated values of max and avg temps for each sensor after new data is + * received. Will only update for the specified sensor. + * @param sensor corresponds to which sensor was updated. FL = 0, FR = 1 + */ +void BrakeRotorTemp::_updateCalculatedValues(bool sensor) { + // init iterators to assume FL updated + auto begin_iterator = _temp_data.fl_sensor.channel_data.begin(); + auto end_iterator = _temp_data.fl_sensor.channel_data.end(); + + if (sensor) { + // if FR was actually updated, then overwrite + begin_iterator = _temp_data.fr_sensor.channel_data.begin(); + end_iterator = _temp_data.fr_sensor.channel_data.end(); + } + + // update values for specific channel based on iterators + // update maximum value + _temp_data.fr_sensor.max_temp = *std::max_element(begin_iterator, end_iterator); + + // update avg value + float sum = std::accumulate(begin_iterator, end_iterator, 0.0f); // find sum + _temp_data.fr_sensor.avg_temp = sum / static_cast(BrakeRotorTempDefaultParams::channels_within_brake_temp_sensor); +} \ No newline at end of file From 753ebabc6d2e9cc2a76592d16851f6f5b8535300 Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Mon, 4 May 2026 19:31:54 -0400 Subject: [PATCH 2/8] added brake temp to CAN interface --- lib/interfaces/include/VCFCANInterfaceImpl.h | 7 ++++-- lib/interfaces/src/VCFCANInterfaceImpl.cpp | 25 ++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/interfaces/include/VCFCANInterfaceImpl.h b/lib/interfaces/include/VCFCANInterfaceImpl.h index 519565c..2968a78 100644 --- a/lib/interfaces/include/VCFCANInterfaceImpl.h +++ b/lib/interfaces/include/VCFCANInterfaceImpl.h @@ -12,6 +12,7 @@ #include "DashboardInterface.h" #include "ACUInterface.h" #include "VCRInterface.h" +#include "BrakeRotorTemp.h" #include "SharedFirmwareTypes.h" @@ -27,14 +28,16 @@ using FrontAuxCAN_t = FlexCAN_T4; /* Interfaces accessible to this one */ struct CANInterfaces { - explicit CANInterfaces(DashboardInterface &dash_int, ACUInterface &acu_int, VCRInterface &vcr_int) + explicit CANInterfaces(DashboardInterface &dash_int, ACUInterface &acu_int, VCRInterface &vcr_int, BrakeRotorTemp &brake_rotor_temp_int) : dash_interface(dash_int), acu_interface(acu_int), - vcr_interface(vcr_int) {} + vcr_interface(vcr_int), + brake_rotor_temp_interface(brake_rotor_temp_int) {} DashboardInterface &dash_interface; ACUInterface &acu_interface; VCRInterface &vcr_interface; + BrakeRotorTemp &brake_rotor_temp_interface; }; using CANInterfacesInstance = etl::singleton; diff --git a/lib/interfaces/src/VCFCANInterfaceImpl.cpp b/lib/interfaces/src/VCFCANInterfaceImpl.cpp index 842736a..48481fd 100644 --- a/lib/interfaces/src/VCFCANInterfaceImpl.cpp +++ b/lib/interfaces/src/VCFCANInterfaceImpl.cpp @@ -11,21 +11,10 @@ namespace VCFCANInterfaceImpl { void on_faux_can_recv(const CAN_message_t &msg) { - VCFCANInterfaceInstance::instance().TELEM_CAN.write(msg); //immediately forward onto telem can to view data + // VCFCANInterfaceInstance::instance().TELEM_CAN.write(msg); //immediately forward onto telem can to view data uint8_t buf[sizeof(CAN_message_t)]; memmove(buf, &msg, sizeof(msg)); // NOLINT (memory operations are fine) VCFCANInterfaceInstance::instance().front_aux_can_rx_buffer.push_back(buf, sizeof(CAN_message_t)); - - // Serial.println("msg recvd"); - // Serial.print("MB: "); Serial.print(msg.mb); - // Serial.print(" ID: 0x"); Serial.print(msg.id, HEX); - // Serial.print(" EXT: "); Serial.print(msg.flags.extended); - // Serial.print(" LEN: "); Serial.print(msg.len); - // Serial.print(" DATA: "); - // for ( uint8_t i = 0; i < 8; i++ ) { - // Serial.print(msg.buf[i]); Serial.print(" "); - // } - // Serial.print(" TS: "); Serial.println(msg.timestamp); } void vcf_recv_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis, CANInterfaceType_e interface_type) @@ -72,6 +61,18 @@ namespace VCFCANInterfaceImpl { interfaces.vcr_interface.receive_inverter_status_4(msg); break; } + case FL_BRAKE_ROTOR_SENSOR_TEMP_CANID: + case FL_BRAKE_ROTOR_TEMP_CH1_CH4_CANID: + case FL_BRAKE_ROTOR_TEMP_CH5_CH8_CANID: + case FL_BRAKE_ROTOR_TEMP_CH9_CH12_CANID: + case FL_BRAKE_ROTOR_TEMP_CH13_CH16_CANID: + case FR_BRAKE_ROTOR_SENSOR_TEMP_CANID: + case FR_BRAKE_ROTOR_TEMP_CH1_CH4_CANID: + case FR_BRAKE_ROTOR_TEMP_CH5_CH8_CANID: + case FR_BRAKE_ROTOR_TEMP_CH9_CH12_CANID: + case FR_BRAKE_ROTOR_TEMP_CH13_CH16_CANID: + interfaces.brake_rotor_temp_interface.receiveBrakeRotorTempData(msg); + break; default: break; } From 16f666d02bbb9c912edcb44a689eb8593f60f7ef Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Tue, 5 May 2026 01:10:04 -0400 Subject: [PATCH 3/8] added brake rotor temps to debug prints --- lib/interfaces/include/BrakeRotorTemp.h | 3 +++ lib/interfaces/src/BrakeRotorTemp.cpp | 16 +++++++------- src/VCF_Tasks.cpp | 29 ++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lib/interfaces/include/BrakeRotorTemp.h b/lib/interfaces/include/BrakeRotorTemp.h index 11c1b78..39609e2 100644 --- a/lib/interfaces/include/BrakeRotorTemp.h +++ b/lib/interfaces/include/BrakeRotorTemp.h @@ -22,6 +22,9 @@ struct BrakeTempData_s { BrakeTempSensorData_s fr_sensor; }; +/** + * Interface to receive messages from the Izze Racing IRTS-60deg-v3 sensor + */ class BrakeRotorTemp { public: diff --git a/lib/interfaces/src/BrakeRotorTemp.cpp b/lib/interfaces/src/BrakeRotorTemp.cpp index 58fe7b5..3002b4c 100644 --- a/lib/interfaces/src/BrakeRotorTemp.cpp +++ b/lib/interfaces/src/BrakeRotorTemp.cpp @@ -21,7 +21,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<3>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_4_ro_fromS(unpacked_msg.brake_temp_channel_4_ro); // update FL outputs - _updateCalculatedValues(0); + _updateCalculatedValues(false); break; } @@ -38,7 +38,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<7>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_8_ro_fromS(unpacked_msg.brake_temp_channel_8_ro); // update FL outputs - _updateCalculatedValues(0); + _updateCalculatedValues(false); break; } @@ -55,7 +55,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<11>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_12_ro_fromS(unpacked_msg.brake_temp_channel_12_ro); // update FL outputs - _updateCalculatedValues(0); + _updateCalculatedValues(false); break; } @@ -72,7 +72,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<15>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_16_ro_fromS(unpacked_msg.brake_temp_channel_16_ro); // update FL outputs - _updateCalculatedValues(0); + _updateCalculatedValues(false); break; } @@ -89,7 +89,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<3>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_4_ro_fromS(unpacked_msg.brake_temp_channel_4_ro); // update FR outputs - _updateCalculatedValues(1); + _updateCalculatedValues(true); break; } @@ -106,7 +106,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<7>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_8_ro_fromS(unpacked_msg.brake_temp_channel_8_ro); // update FR outputs - _updateCalculatedValues(1); + _updateCalculatedValues(true); break; } @@ -123,7 +123,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<11>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_12_ro_fromS(unpacked_msg.brake_temp_channel_12_ro); // update FR outputs - _updateCalculatedValues(1); + _updateCalculatedValues(true); break; } @@ -140,7 +140,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { std::get<15>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_16_ro_fromS(unpacked_msg.brake_temp_channel_16_ro); // update FR outputs - _updateCalculatedValues(1); + _updateCalculatedValues(true); break; } diff --git a/src/VCF_Tasks.cpp b/src/VCF_Tasks.cpp index d15616e..e486b5a 100644 --- a/src/VCF_Tasks.cpp +++ b/src/VCF_Tasks.cpp @@ -20,6 +20,7 @@ #include #include "FlexCAN_T4.h" #include "Orbis_BR.h" +#include "BrakeRotorTemp.h" #include "WatchdogSystem.h" #include "Arduino.h" @@ -478,6 +479,32 @@ HT_TASK::TaskResponse debug_print(const unsigned long& sysMicros, const HT_TASK: Serial.print(DashboardInterfaceInstance::instance().get_dashboard_outputs().data_btn_is_pressed); Serial.print("\t"); Serial.println(BuzzerController::getInstance().buzzer_is_active(sys_time::hal_millis())); + /* Brake Rotor Temp Info */ + Serial.println("\nBrake Rotor Temps:"); + Serial.println("Sensor\tMax\tAvg\tCH0\tCH1\tCH2\tCH3\tCH4\tCH5\tCH6\tCH7\tCH8\tCH9\tCH10\tCH11\tCH12\tCH13\tCH14\tCH15"); + + // Sensor 1 + Serial.print("FL\t"); + Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fl_sensor.max_temp); Serial.print("\t"); + Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fl_sensor.avg_temp); Serial.print("\t"); + + for (int i = 0; i < 16; ++i) { + Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fl_sensor.channel_data[i]); + Serial.print("\t"); + } + Serial.println(); + + // Sensor 2 + Serial.print("FR\t"); + Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fr_sensor.max_temp); Serial.print("\t"); + Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fr_sensor.avg_temp); Serial.print("\t"); + + for (int i = 0; i < 16; ++i) { + Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fr_sensor.channel_data[i]); + Serial.print("\t"); + } + Serial.println(); + return HT_TASK::TaskResponse::YIELD; } @@ -595,7 +622,7 @@ void setup_all_interfaces() { VCRInterfaceInstance::create(); // Create CAN singletons - CANInterfacesInstance::create(DashboardInterfaceInstance::instance(), ACUInterfaceInstance::instance(), VCRInterfaceInstance::instance()); + CANInterfacesInstance::create(DashboardInterfaceInstance::instance(), ACUInterfaceInstance::instance(), VCRInterfaceInstance::instance(), BrakeRotorTempInstance::instance()); VCFCANInterfaceInstance::create(etl::delegate::create()); handle_CAN_setup(VCFCANInterfaceInstance::instance().TELEM_CAN, VCFInterfaceConstants::TELEM_CAN_BAUDRATE, &VCFCANInterfaceImpl::on_main_can_recv); handle_CAN_setup(VCFCANInterfaceInstance::instance().FRONT_AUX_CAN, VCFInterfaceConstants::FAUX_CAN_BAUDRATE, &VCFCANInterfaceImpl::on_faux_can_recv); From 0c1c948a488dcb84bca45481ebad79416a989b21 Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Tue, 5 May 2026 01:13:53 -0400 Subject: [PATCH 4/8] updated max and avg temp calcs --- lib/interfaces/include/BrakeRotorTemp.h | 2 +- lib/interfaces/src/BrakeRotorTemp.cpp | 38 ++++++++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/interfaces/include/BrakeRotorTemp.h b/lib/interfaces/include/BrakeRotorTemp.h index 39609e2..35a47d1 100644 --- a/lib/interfaces/include/BrakeRotorTemp.h +++ b/lib/interfaces/include/BrakeRotorTemp.h @@ -47,7 +47,7 @@ class BrakeRotorTemp private: BrakeTempData_s _temp_data; - void _updateCalculatedValues(bool sensor); + void _updateCalculatedValues(bool FR); }; using BrakeRotorTempInstance = etl::singleton; diff --git a/lib/interfaces/src/BrakeRotorTemp.cpp b/lib/interfaces/src/BrakeRotorTemp.cpp index 3002b4c..59cb33d 100644 --- a/lib/interfaces/src/BrakeRotorTemp.cpp +++ b/lib/interfaces/src/BrakeRotorTemp.cpp @@ -154,22 +154,26 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { * received. Will only update for the specified sensor. * @param sensor corresponds to which sensor was updated. FL = 0, FR = 1 */ -void BrakeRotorTemp::_updateCalculatedValues(bool sensor) { - // init iterators to assume FL updated - auto begin_iterator = _temp_data.fl_sensor.channel_data.begin(); - auto end_iterator = _temp_data.fl_sensor.channel_data.end(); - - if (sensor) { - // if FR was actually updated, then overwrite - begin_iterator = _temp_data.fr_sensor.channel_data.begin(); - end_iterator = _temp_data.fr_sensor.channel_data.end(); - } - - // update values for specific channel based on iterators - // update maximum value - _temp_data.fr_sensor.max_temp = *std::max_element(begin_iterator, end_iterator); +void BrakeRotorTemp::_updateCalculatedValues(bool FR) { + if (FR) { // check if FR needs to be updated + auto begin_iterator = _temp_data.fr_sensor.channel_data.begin(); + auto end_iterator = _temp_data.fr_sensor.channel_data.end(); - // update avg value - float sum = std::accumulate(begin_iterator, end_iterator, 0.0f); // find sum - _temp_data.fr_sensor.avg_temp = sum / static_cast(BrakeRotorTempDefaultParams::channels_within_brake_temp_sensor); + // update maximum value + _temp_data.fr_sensor.max_temp = *std::max_element(begin_iterator, end_iterator); + + // update avg value + float sum = std::accumulate(begin_iterator, end_iterator, 0.0f); // find sum + _temp_data.fr_sensor.avg_temp = sum / static_cast(BrakeRotorTempDefaultParams::channels_within_brake_temp_sensor); + } else { // otherwise update FL + auto begin_iterator = _temp_data.fl_sensor.channel_data.begin(); + auto end_iterator = _temp_data.fl_sensor.channel_data.end(); + + // update maximum value + _temp_data.fl_sensor.max_temp = *std::max_element(begin_iterator, end_iterator); + + // update avg value + float sum = std::accumulate(begin_iterator, end_iterator, 0.0f); // find sum + _temp_data.fl_sensor.avg_temp = sum / static_cast(BrakeRotorTempDefaultParams::channels_within_brake_temp_sensor); + } } \ No newline at end of file From f3123ebd2019561342ec6ae0b6c440a2b022cc8c Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Thu, 7 May 2026 12:42:12 -0400 Subject: [PATCH 5/8] added brake rotor temps to ethernet msg --- lib/interfaces/include/VCFEthernetInterface.h | 6 +++++- lib/interfaces/src/VCFEthernetInterface.cpp | 9 ++++++++- platformio.ini | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/interfaces/include/VCFEthernetInterface.h b/lib/interfaces/include/VCFEthernetInterface.h index 3bb32ce..0eea5f1 100644 --- a/lib/interfaces/include/VCFEthernetInterface.h +++ b/lib/interfaces/include/VCFEthernetInterface.h @@ -7,6 +7,7 @@ #include "ADCInterface.h" #include "DashboardInterface.h" #include "PedalsSystem.h" +#include "BrakeRotorTemp.h" namespace VCFEthernetInterface { @@ -17,7 +18,10 @@ namespace VCFEthernetInterface * @return A populated instance of the outgoing protoc struct. */ // hytech_msgs_VCFData_s make_vcf_data_msg(VCFData_s &shared_state); - hytech_msgs_VCFData_s make_vcf_data_msg(ADCInterface &ADCInterfaceInstance, DashboardInterface &dashInstance, PedalsSystem &pedalsInstance); + hytech_msgs_VCFData_s make_vcf_data_msg(ADCInterface &ADCInterfaceInstance, + DashboardInterface &dashInstance, + PedalsSystem &pedalsInstance, + BrakeRotorTemp &brakeRotorTempInstance); /** * Function to take a populated protoc struct from VCR and update the VCF state. This is ONLY critical diff --git a/lib/interfaces/src/VCFEthernetInterface.cpp b/lib/interfaces/src/VCFEthernetInterface.cpp index fb8105e..1ebff14 100644 --- a/lib/interfaces/src/VCFEthernetInterface.cpp +++ b/lib/interfaces/src/VCFEthernetInterface.cpp @@ -4,7 +4,7 @@ #include "hytech_msgs_version.h" #include "device_fw_version.h" -hytech_msgs_VCFData_s VCFEthernetInterface::make_vcf_data_msg(ADCInterface &ADCInterfaceInstance, DashboardInterface &dashInstance, PedalsSystem &pedalsInstance) +hytech_msgs_VCFData_s VCFEthernetInterface::make_vcf_data_msg(ADCInterface &ADCInterfaceInstance, DashboardInterface &dashInstance, PedalsSystem &pedalsInstance, BrakeRotorTemp &brakeRotorTempInstance) { hytech_msgs_VCFData_s out; @@ -17,6 +17,7 @@ hytech_msgs_VCFData_s VCFEthernetInterface::make_vcf_data_msg(ADCInterface &ADCI out.has_vcf_ethernet_link_data = true; out.has_vcf_shutdown_data = true; out.has_brake_pressure_data = true; + out.has_brake_rotor_temp_data = true; // Load cells out.front_loadcell_data.FL_loadcell_analog = static_cast(ADCInterfaceInstance.get_filtered_FL_load_cell()); @@ -64,6 +65,12 @@ hytech_msgs_VCFData_s VCFEthernetInterface::make_vcf_data_msg(ADCInterface &ADCI out.brake_pressure_data.front_brake_pressure = ADCInterfaceInstance.get_brake_pressure_front().conversion; out.brake_pressure_data.rear_brake_pressure = ADCInterfaceInstance.get_brake_pressure_rear().conversion; + // Brake rotor temps + out.brake_rotor_temp_data.fl_max_brake_rotor_temp = brakeRotorTempInstance.getBrakeRotorTempData().fl_sensor.max_temp; + out.brake_rotor_temp_data.fl_avg_brake_rotor_temp = brakeRotorTempInstance.getBrakeRotorTempData().fl_sensor.avg_temp; + out.brake_rotor_temp_data.fr_max_brake_rotor_temp = brakeRotorTempInstance.getBrakeRotorTempData().fr_sensor.max_temp; + out.brake_rotor_temp_data.fr_avg_brake_rotor_temp = brakeRotorTempInstance.getBrakeRotorTempData().fr_sensor.avg_temp; + // Shutdown Senses out.vcf_shutdown_data.d_inertia_switch_out_read = ADCInterfaceInstance.shdn_d().conversion; out.vcf_shutdown_data.d_inertia_switch = ADCInterfaceInstance.shdn_d().conversion > SHDN_HIGH_THRESHOLD ? true : false; diff --git a/platformio.ini b/platformio.ini index b265965..64b246e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ lib_deps_shared = https://github.com/hytech-racing/shared_firmware_systems.git https://github.com/hytech-racing/shared_firmware_types.git https://github.com/hytech-racing/HT_SCHED#c13cff762c59dd82a8c273e3e98fd1a80622656d - https://github.com/hytech-racing/HT_proto/releases/download/2026-04-02T21_09_09/hytech_msgs_pb_lib.tar.gz + https://github.com/hytech-racing/HT_proto/releases/download/2026-05-07T16_36_28/hytech_msgs_pb_lib.tar.gz https://github.com/hytech-racing/HT_CAN/releases/download/250/can_lib.tar.gz etlcpp/Embedded Template Library From 1d9e3b132b009b26ee1308a1a3c8b4bee0651984 Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Thu, 7 May 2026 17:48:37 -0400 Subject: [PATCH 6/8] updated CI check stuff --- lib/interfaces/include/DashboardInterface.h | 4 ++-- lib/interfaces/src/BrakeRotorTemp.cpp | 16 ++++++++-------- src/VCF_Tasks.cpp | 7 +++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/interfaces/include/DashboardInterface.h b/lib/interfaces/include/DashboardInterface.h index cd25ff7..2fc64a7 100644 --- a/lib/interfaces/include/DashboardInterface.h +++ b/lib/interfaces/include/DashboardInterface.h @@ -44,14 +44,14 @@ class DashboardInterface DashInputState_s get_dashboard_outputs(); // Stores outputs - DashInputState_s DashboardInterface::get_dashboard_stored_state(); + DashInputState_s get_dashboard_stored_state(); /** * Syncs stored outputs with last read outputs. * Used to store previous state of buttons to determine if they are clicked or not. * In other words, to find the falling edge. */ - void DashboardInterface::sync_dashboard_stored_state(); + void sync_dashboard_stored_state(); // Receiving void receive_ACU_OK(const CAN_message_t &can_msg); diff --git a/lib/interfaces/src/BrakeRotorTemp.cpp b/lib/interfaces/src/BrakeRotorTemp.cpp index 59cb33d..e852449 100644 --- a/lib/interfaces/src/BrakeRotorTemp.cpp +++ b/lib/interfaces/src/BrakeRotorTemp.cpp @@ -12,7 +12,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FL_BRAKE_ROTOR_TEMP_CH1_CH4_t unpacked_msg; - Unpack_FL_BRAKE_ROTOR_TEMP_CH1_CH4_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FL_BRAKE_ROTOR_TEMP_CH1_CH4_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<0>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_1_ro_fromS(unpacked_msg.brake_temp_channel_1_ro); @@ -29,7 +29,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FL_BRAKE_ROTOR_TEMP_CH5_CH8_t unpacked_msg; - Unpack_FL_BRAKE_ROTOR_TEMP_CH5_CH8_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FL_BRAKE_ROTOR_TEMP_CH5_CH8_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<4>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_5_ro_fromS(unpacked_msg.brake_temp_channel_5_ro); @@ -46,7 +46,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FL_BRAKE_ROTOR_TEMP_CH9_CH12_t unpacked_msg; - Unpack_FL_BRAKE_ROTOR_TEMP_CH9_CH12_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FL_BRAKE_ROTOR_TEMP_CH9_CH12_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<8>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_9_ro_fromS(unpacked_msg.brake_temp_channel_9_ro); @@ -63,7 +63,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FL_BRAKE_ROTOR_TEMP_CH13_CH16_t unpacked_msg; - Unpack_FL_BRAKE_ROTOR_TEMP_CH13_CH16_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FL_BRAKE_ROTOR_TEMP_CH13_CH16_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<12>(_temp_data.fl_sensor.channel_data) = HYTECH_brake_temp_channel_13_ro_fromS(unpacked_msg.brake_temp_channel_13_ro); @@ -80,7 +80,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FR_BRAKE_ROTOR_TEMP_CH1_CH4_t unpacked_msg; - Unpack_FR_BRAKE_ROTOR_TEMP_CH1_CH4_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FR_BRAKE_ROTOR_TEMP_CH1_CH4_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<0>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_1_ro_fromS(unpacked_msg.brake_temp_channel_1_ro); @@ -97,7 +97,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FR_BRAKE_ROTOR_TEMP_CH5_CH8_t unpacked_msg; - Unpack_FR_BRAKE_ROTOR_TEMP_CH5_CH8_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FR_BRAKE_ROTOR_TEMP_CH5_CH8_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<4>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_5_ro_fromS(unpacked_msg.brake_temp_channel_5_ro); @@ -114,7 +114,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FR_BRAKE_ROTOR_TEMP_CH9_CH12_t unpacked_msg; - Unpack_FR_BRAKE_ROTOR_TEMP_CH9_CH12_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FR_BRAKE_ROTOR_TEMP_CH9_CH12_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<8>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_9_ro_fromS(unpacked_msg.brake_temp_channel_9_ro); @@ -131,7 +131,7 @@ void BrakeRotorTemp::receiveBrakeRotorTempData(const CAN_message_t &msg) { { // unpack the msg FR_BRAKE_ROTOR_TEMP_CH13_CH16_t unpacked_msg; - Unpack_FR_BRAKE_ROTOR_TEMP_CH13_CH16_hytech(&unpacked_msg, msg.buf, msg.len); + Unpack_FR_BRAKE_ROTOR_TEMP_CH13_CH16_hytech(&unpacked_msg, msg.buf, msg.len); // NOLINT array decay to pointer // copy data over to interface data std::get<12>(_temp_data.fr_sensor.channel_data) = HYTECH_brake_temp_channel_13_ro_fromS(unpacked_msg.brake_temp_channel_13_ro); diff --git a/src/VCF_Tasks.cpp b/src/VCF_Tasks.cpp index e486b5a..2be3a6b 100644 --- a/src/VCF_Tasks.cpp +++ b/src/VCF_Tasks.cpp @@ -168,7 +168,6 @@ HT_TASK::TaskResponse send_dash_data(const unsigned long& sysMicros, const HT_TA HT_TASK::TaskResponse enqueue_front_suspension_data(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo) { - CANInterfaces can_interface = CANInterfacesInstance::instance(); FRONT_SUSPENSION_t msg_out; msg_out.fr_load_cell = ADCInterfaceInstance::instance().get_filtered_FR_load_cell(); @@ -208,7 +207,7 @@ HT_TASK::TaskResponse init_handle_send_vcf_ethernet_data(const unsigned long& sy } HT_TASK::TaskResponse run_handle_send_vcf_ethernet_data(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo) { - hytech_msgs_VCFData_s msg = VCFEthernetInterface::make_vcf_data_msg(ADCInterfaceInstance::instance(), DashboardInterfaceInstance::instance(), PedalsSystemInstance::instance()); + hytech_msgs_VCFData_s msg = VCFEthernetInterface::make_vcf_data_msg(ADCInterfaceInstance::instance(), DashboardInterfaceInstance::instance(), PedalsSystemInstance::instance(), BrakeRotorTempInstance::instance()); if(handle_ethernet_socket_send_pb (EthernetIPDefsInstance::instance().drivebrain_ip, EthernetIPDefsInstance::instance().VCFData_port, @@ -488,7 +487,7 @@ HT_TASK::TaskResponse debug_print(const unsigned long& sysMicros, const HT_TASK: Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fl_sensor.max_temp); Serial.print("\t"); Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fl_sensor.avg_temp); Serial.print("\t"); - for (int i = 0; i < 16; ++i) { + for (size_t i = 0; i < BrakeRotorTempDefaultParams::channels_within_brake_temp_sensor; ++i) { Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fl_sensor.channel_data[i]); Serial.print("\t"); } @@ -499,7 +498,7 @@ HT_TASK::TaskResponse debug_print(const unsigned long& sysMicros, const HT_TASK: Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fr_sensor.max_temp); Serial.print("\t"); Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fr_sensor.avg_temp); Serial.print("\t"); - for (int i = 0; i < 16; ++i) { + for (size_t i = 0; i < BrakeRotorTempDefaultParams::channels_within_brake_temp_sensor; ++i) { Serial.print(BrakeRotorTempInstance::instance().getBrakeRotorTempData().fr_sensor.channel_data[i]); Serial.print("\t"); } From 19cc772dd17d6378ee57ee2a5d4ff3008cad2dea Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Sat, 9 May 2026 22:14:53 -0400 Subject: [PATCH 7/8] updated hashes --- platformio.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 64b246e..56541f4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -6,8 +6,8 @@ [common] lib_deps_shared = nanopb/Nanopb@0.4.91 - https://github.com/hytech-racing/shared_firmware_systems.git - https://github.com/hytech-racing/shared_firmware_types.git + https://github.com/hytech-racing/shared_firmware_systems.git#af96a631bd76ac4da2084c6fa4faa62ca1bac9d1 + https://github.com/hytech-racing/shared_firmware_types.git#956ce41b93d93975a56d33aa3abd7efac7706533 https://github.com/hytech-racing/HT_SCHED#c13cff762c59dd82a8c273e3e98fd1a80622656d https://github.com/hytech-racing/HT_proto/releases/download/2026-05-07T16_36_28/hytech_msgs_pb_lib.tar.gz https://github.com/hytech-racing/HT_CAN/releases/download/250/can_lib.tar.gz @@ -52,7 +52,7 @@ lib_deps = ${common.lib_deps_shared} arkhipenko/TaskScheduler@^3.8.5 https://github.com/ssilverman/QNEthernet#v0.26.0 - https://github.com/hytech-racing/shared_firmware_interfaces.git + https://github.com/hytech-racing/shared_firmware_interfaces.git#d9f195a0e5640cd99411deb97c960edb7b455659 blemasle/MCP23017@^2.0.0 https://github.com/adafruit/Adafruit_NeoPixel.git https://github.com/KSU-MS/pio-git-hash-gen#7998b5b3f8a2464209b0e73338717998bcf511ee From 187dfe03edf289ced15ba3d52513e067f9a0bee3 Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Sat, 9 May 2026 22:41:53 -0400 Subject: [PATCH 8/8] updated CAN lib --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index e06de1b..c2dd462 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ lib_deps_shared = https://github.com/hytech-racing/shared_firmware_types.git#956ce41b93d93975a56d33aa3abd7efac7706533 https://github.com/hytech-racing/HT_SCHED#c13cff762c59dd82a8c273e3e98fd1a80622656d https://github.com/hytech-racing/HT_proto/releases/download/2026-05-07T16_36_28/hytech_msgs_pb_lib.tar.gz - https://github.com/hytech-racing/HT_CAN/releases/download/250/can_lib.tar.gz + https://github.com/hytech-racing/HT_CAN/releases/download/254/can_lib.tar.gz etlcpp/Embedded Template Library ; Teensy41 Environment. This environment is the primary environment for uploading code to the car.