Skip to content

Commit

Permalink
Thermistor Auto Shutoff is now configurable (#672)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
tabiosg and wilsonchen02 committed Apr 3, 2024
1 parent e43120e commit 1ee7125
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/esw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,6 @@ default_network_iface: "enp0s31f6"
auton_led_driver:
port: "/dev/ttyACM0"
baud: 115200

science:
shutoff_temp: 50.0f
6 changes: 5 additions & 1 deletion src/esw/fw/science/Core/Inc/heater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace mrover {

constexpr static float DEFAULT_MAX_HEATER_TEMP = 50.0f;

class Heater {
public:
Heater() = default;
Expand All @@ -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);

Expand All @@ -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
6 changes: 6 additions & 0 deletions src/esw/fw/science/Core/Inc/science.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 9 additions & 3 deletions src/esw/fw/science/Core/Src/heater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand Down
10 changes: 10 additions & 0 deletions src/esw/science_bridge/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <mrover/Spectral.h>
#include <ros/ros.h>
#include <unordered_map>
#include "params_utils.hpp"

std::unique_ptr<mrover::CanDevice> scienceCanDevice;

Expand Down Expand Up @@ -93,6 +94,15 @@ auto main(int argc, char** argv) -> int {
};

scienceCanDevice = std::make_unique<mrover::CanDevice>(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<ros::ServiceServer> services;
services.reserve(scienceDeviceByName.size() + 1);

Expand Down
6 changes: 5 additions & 1 deletion src/util/messaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand All @@ -183,7 +187,7 @@ namespace mrover {
};

using InBoundScienceMessage = std::variant<
EnableScienceDeviceCommand, HeaterAutoShutOffCommand>;
EnableScienceDeviceCommand, HeaterAutoShutOffCommand, ConfigThermistorAutoShutOffCommand>;

using OutBoundScienceMessage = std::variant<
HeaterStateData, SpectralData, ThermistorData>;
Expand Down

0 comments on commit 1ee7125

Please sign in to comment.