From e27bf112030b21f158ebee495bdf44c54b403dbb Mon Sep 17 00:00:00 2001 From: Pradheep Date: Fri, 20 Sep 2024 10:02:47 +0200 Subject: [PATCH 1/2] set safety modes --- include/neo_relayboard_v3/RelayBoardV3.h | 3 +++ src/RelayBoardV3.cpp | 33 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/neo_relayboard_v3/RelayBoardV3.h b/include/neo_relayboard_v3/RelayBoardV3.h index 9f352d2..67b1906 100644 --- a/include/neo_relayboard_v3/RelayBoardV3.h +++ b/include/neo_relayboard_v3/RelayBoardV3.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,7 @@ class RelayBoardV3 : public RelayBoardV3Base{ rclcpp::Service::SharedPtr srv_shutdown_platform; rclcpp::Service::SharedPtr srv_set_safety_field; rclcpp::Service::SharedPtr srv_set_leds; + rclcpp::Service::SharedPtr srv_set_safety_mode; bool is_shutdown = false; @@ -93,6 +95,7 @@ class RelayBoardV3 : public RelayBoardV3Base{ bool service_stop_charging(std::shared_ptr req, std::shared_ptr res); bool service_shutdown_platform(std::shared_ptr req, std::shared_ptr res); bool service_set_safety_field(std::shared_ptr req, std::shared_ptr res); + bool service_set_safety_mode(std::shared_ptr req, std::shared_ptr res); bool service_set_leds(std::shared_ptr req, std::shared_ptr res); }; diff --git a/src/RelayBoardV3.cpp b/src/RelayBoardV3.cpp index 70235c1..f4319f8 100644 --- a/src/RelayBoardV3.cpp +++ b/src/RelayBoardV3.cpp @@ -21,6 +21,8 @@ #include #include #include +#include + #include #include @@ -71,6 +73,7 @@ void RelayBoardV3::main(){ srv_stop_charging = nh->create_service("stop_charging", std::bind(&RelayBoardV3::service_stop_charging, this, std::placeholders::_1, std::placeholders::_2)); srv_shutdown_platform = nh->create_service("shutdown_platform", std::bind(&RelayBoardV3::service_shutdown_platform, this, std::placeholders::_1, std::placeholders::_2)); srv_set_safety_field = nh->create_service("set_safety_field", std::bind(&RelayBoardV3::service_set_safety_field, this, std::placeholders::_1, std::placeholders::_2)); + srv_set_safety_mode = nh->create_service("set_safety_mode", std::bind(&RelayBoardV3::service_set_safety_mode, this, std::placeholders::_1, std::placeholders::_2)); srv_set_leds = nh->create_service("set_leds", std::bind(&RelayBoardV3::service_set_leds, this, std::placeholders::_1, std::placeholders::_2)); if(board_init_interval_ms > 0){ @@ -645,6 +648,36 @@ bool RelayBoardV3::service_set_safety_field(std::shared_ptr req, + std::shared_ptr res) +{ + pilot::safety_mode_e mode; + + switch(req->set_safety_mode.mode) { + case neo_msgs2::msg::SafetyMode::SM_NONE: + mode = pilot::safety_mode_e::NONE; + case neo_msgs2::msg::SafetyMode::SM_APPROACHING: + mode = pilot::safety_mode_e::APPROACHING; + case neo_msgs2::msg::SafetyMode::SM_DEPARTING: + mode = pilot::safety_mode_e::DEPARTING; + case neo_msgs2::msg::SafetyMode::SM_WORKING: + mode = pilot::safety_mode_e::WORKING; + case neo_msgs2::msg::SafetyMode::SM_HANDLING: + mode = pilot::safety_mode_e::HANDLING; + } + + try{ + safety_interface->set_safety_mode(mode, req->station); + res->success = true; + return true; + }catch(const std::exception &err){ + log(WARN) << "Service call failed with: " << err.what(); + res->success = false; + return false; + } +} + bool RelayBoardV3::service_shutdown_platform(std::shared_ptr req, std::shared_ptr res){ try{ platform_interface->shutdown(); From defdaa9f9572b490504c0bdddd65478c1b55b6b8 Mon Sep 17 00:00:00 2001 From: Pradheep Date: Fri, 20 Sep 2024 10:12:32 +0200 Subject: [PATCH 2/2] adding the missing breaks --- src/RelayBoardV3.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/RelayBoardV3.cpp b/src/RelayBoardV3.cpp index f4319f8..ee895cd 100644 --- a/src/RelayBoardV3.cpp +++ b/src/RelayBoardV3.cpp @@ -652,19 +652,24 @@ bool RelayBoardV3::service_set_safety_mode( std::shared_ptr req, std::shared_ptr res) { - pilot::safety_mode_e mode; + pilot::safety_mode_e mode = pilot::safety_mode_e::NONE; switch(req->set_safety_mode.mode) { case neo_msgs2::msg::SafetyMode::SM_NONE: mode = pilot::safety_mode_e::NONE; + break; case neo_msgs2::msg::SafetyMode::SM_APPROACHING: mode = pilot::safety_mode_e::APPROACHING; + break; case neo_msgs2::msg::SafetyMode::SM_DEPARTING: mode = pilot::safety_mode_e::DEPARTING; + break; case neo_msgs2::msg::SafetyMode::SM_WORKING: mode = pilot::safety_mode_e::WORKING; + break; case neo_msgs2::msg::SafetyMode::SM_HANDLING: mode = pilot::safety_mode_e::HANDLING; + break; } try{