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 6378180..9a31cd5 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){ @@ -650,6 +653,41 @@ bool RelayBoardV3::service_set_safety_field(std::shared_ptr req, + std::shared_ptr res) +{ + 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{ + 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();