From 1ee71258169aefaef3106a873986f81f2e160ee0 Mon Sep 17 00:00:00 2001 From: Guthrie <71603173+tabiosg@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:41:52 -0400 Subject: [PATCH] Thermistor Auto Shutoff is now configurable (#672) * Make changes to firmware side for thermistor auto shutoff temperature config rule * Refactor embedded firmware changes * Unsure why feed_watchdog was saved into a float instead of a uint32_t since HALGetTick returns uint32_t * Add custom changes for ROS end * Allow code to build --------- Co-authored-by: wilsonchen02 --- config/esw.yaml | 3 +++ src/esw/fw/science/Core/Inc/heater.hpp | 6 +++++- src/esw/fw/science/Core/Inc/science.hpp | 6 ++++++ src/esw/fw/science/Core/Src/heater.cpp | 12 +++++++++--- src/esw/science_bridge/main.cpp | 10 ++++++++++ src/util/messaging.hpp | 6 +++++- 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/config/esw.yaml b/config/esw.yaml index dc53ab2dd..f6927b8a7 100644 --- a/config/esw.yaml +++ b/config/esw.yaml @@ -598,3 +598,6 @@ default_network_iface: "enp0s31f6" auton_led_driver: port: "/dev/ttyACM0" baud: 115200 + +science: + shutoff_temp: 50.0f \ No newline at end of file diff --git a/src/esw/fw/science/Core/Inc/heater.hpp b/src/esw/fw/science/Core/Inc/heater.hpp index 60b8fc62b..6cab4eab9 100644 --- a/src/esw/fw/science/Core/Inc/heater.hpp +++ b/src/esw/fw/science/Core/Inc/heater.hpp @@ -11,6 +11,8 @@ namespace mrover { + constexpr static float DEFAULT_MAX_HEATER_TEMP = 50.0f; + class Heater { public: Heater() = default; @@ -27,6 +29,7 @@ namespace mrover { void turn_off_if_watchdog_not_fed(); + void change_shutoff_temp(float shutoff_temp); void set_auto_shutoff(bool enable); @@ -37,7 +40,8 @@ namespace mrover { Pin m_heater_pin; bool m_state {}; bool m_auto_shutoff_enabled {}; - float m_last_time_received_message {}; + uint32_t m_last_time_received_message {}; + float m_max_heater_temp {DEFAULT_MAX_HEATER_TEMP}; }; } // namespace mrover diff --git a/src/esw/fw/science/Core/Inc/science.hpp b/src/esw/fw/science/Core/Inc/science.hpp index a2c4ba5ca..50e945c76 100644 --- a/src/esw/fw/science/Core/Inc/science.hpp +++ b/src/esw/fw/science/Core/Inc/science.hpp @@ -76,6 +76,12 @@ namespace mrover { } } + void feed(ConfigThermistorAutoShutOffCommand const& message) { + for (int i = 0; i < 6; ++i) { + m_heaters.at(i).change_shutoff_temp(message.shutoff_temp); + } + } + public: Science() = default; diff --git a/src/esw/fw/science/Core/Src/heater.cpp b/src/esw/fw/science/Core/Src/heater.cpp index c72444a56..80c5c5b97 100644 --- a/src/esw/fw/science/Core/Src/heater.cpp +++ b/src/esw/fw/science/Core/Src/heater.cpp @@ -5,9 +5,11 @@ #include "heater.hpp" + + + namespace mrover { - constexpr static float MAX_HEATER_TEMP = 50.0f; constexpr static int MAX_HEATER_WATCHDOG_TICK = 1000; Heater::Heater(DiagTempSensor const& diag_temp_sensor, Pin const& heater_pin) @@ -27,7 +29,7 @@ namespace mrover { } void Heater::enable_if_possible(bool enable) { - if (enable && m_auto_shutoff_enabled && get_temp() >= MAX_HEATER_TEMP) { + if (enable && m_auto_shutoff_enabled && get_temp() >= m_max_heater_temp) { // The only time you don't service the request is if auto_shutoff is enabled // and they want to turn it on when past the heater temp m_state = false; @@ -43,7 +45,7 @@ namespace mrover { void Heater::update_temp_and_auto_shutoff_if_applicable() { m_diag_temp_sensor.update_science_temp(); - if (m_state && m_auto_shutoff_enabled && (get_temp() >= MAX_HEATER_TEMP)) { + if (m_state && m_auto_shutoff_enabled && (get_temp() >= m_max_heater_temp)) { m_state = false; m_heater_pin.write(GPIO_PIN_RESET); } @@ -59,6 +61,10 @@ namespace mrover { } } + void Heater::change_shutoff_temp(float shutoff_temp) { + m_max_heater_temp = shutoff_temp; + } + void Heater::feed_watchdog() { m_last_time_received_message = HAL_GetTick(); } diff --git a/src/esw/science_bridge/main.cpp b/src/esw/science_bridge/main.cpp index 1d76ed47c..cbc35d87b 100644 --- a/src/esw/science_bridge/main.cpp +++ b/src/esw/science_bridge/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "params_utils.hpp" std::unique_ptr scienceCanDevice; @@ -93,6 +94,15 @@ auto main(int argc, char** argv) -> int { }; scienceCanDevice = std::make_unique(nh, "jetson", "science"); + + + float shutoff_temp = 50.0f; // DEFAULT + if (nh.hasParam("science/shutoff_temp")) { + nh.getParam("science/shutoff_temp", shutoff_temp); + } + + scienceCanDevice->publish_message(mrover::InBoundScienceMessage{mrover::ConfigThermistorAutoShutOffCommand{.shutoff_temp = shutoff_temp}}); + std::vector services; services.reserve(scienceDeviceByName.size() + 1); diff --git a/src/util/messaging.hpp b/src/util/messaging.hpp index d3b8bc3cc..51a74e728 100644 --- a/src/util/messaging.hpp +++ b/src/util/messaging.hpp @@ -158,6 +158,10 @@ namespace mrover { bool enable_auto_shutoff{}; }; + struct ConfigThermistorAutoShutOffCommand : BaseCommand { + float shutoff_temp{}; + }; + struct HeaterStateInfo { [[maybe_unused]] std::uint8_t _ignore : 2 {}; std::uint8_t on : 6 {}; @@ -183,7 +187,7 @@ namespace mrover { }; using InBoundScienceMessage = std::variant< - EnableScienceDeviceCommand, HeaterAutoShutOffCommand>; + EnableScienceDeviceCommand, HeaterAutoShutOffCommand, ConfigThermistorAutoShutOffCommand>; using OutBoundScienceMessage = std::variant< HeaterStateData, SpectralData, ThermistorData>;