Skip to content

Commit

Permalink
feat: implement service for clear MRM behavior (#1511)
Browse files Browse the repository at this point in the history
* implement service for clear MRM behavior

* clang format

Signed-off-by: Tomohito Ando <[email protected]>
  • Loading branch information
saka1-s authored and TomohitoAndo committed Nov 21, 2024
1 parent 16c64c3 commit babdfaa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions system/mrm_handler/include/mrm_handler/mrm_handler_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <diagnostic_msgs/msg/diagnostic_array.hpp>
#include <nav_msgs/msg/odometry.hpp>
#include <std_srvs/srv/trigger.hpp>

struct HazardLampPolicy
{
Expand Down Expand Up @@ -95,6 +96,9 @@ class MrmHandler : public rclcpp::Node

void onOperationModeAvailability(
const tier4_system_msgs::msg::OperationModeAvailability::ConstSharedPtr msg);
void onRecoverMrm(
const std_srvs::srv::Trigger::Request::SharedPtr,
const std_srvs::srv::Trigger::Response::SharedPtr response);

// Publisher

Expand All @@ -119,6 +123,9 @@ class MrmHandler : public rclcpp::Node
rclcpp::CallbackGroup::SharedPtr client_mrm_emergency_stop_group_;
rclcpp::Client<tier4_system_msgs::srv::OperateMrm>::SharedPtr client_mrm_emergency_stop_;

// Services
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr service_recover_mrm_;

bool requestMrmBehavior(
const autoware_adapi_v1_msgs::msg::MrmState::_behavior_type & mrm_behavior,
RequestType request_type) const;
Expand Down
18 changes: 18 additions & 0 deletions system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ MrmHandler::MrmHandler(const rclcpp::NodeOptions & options) : Node("mrm_handler"
"~/output/mrm/emergency_stop/operate", rmw_qos_profile_services_default,
client_mrm_emergency_stop_group_);

// Services
service_recover_mrm_ = create_service<std_srvs::srv::Trigger>(
"/system/clear_mrm",
std::bind(&MrmHandler::onRecoverMrm, this, std::placeholders::_1, std::placeholders::_2),
rmw_qos_profile_services_default);

// Initialize
mrm_state_.stamp = this->now();
mrm_state_.state = autoware_adapi_v1_msgs::msg::MrmState::NORMAL;
Expand Down Expand Up @@ -582,5 +588,17 @@ bool MrmHandler::isArrivedAtGoal()
return state->mode == OperationModeState::STOP;
}

void MrmHandler::onRecoverMrm(
const std_srvs::srv::Trigger::Request::SharedPtr,
const std_srvs::srv::Trigger::Response::SharedPtr response)
{
if (!param_.is_mrm_recoverable) {
is_mrm_holding_ = false;
response->success = true;
} else {
response->success = false;
}
}

#include <rclcpp_components/register_node_macro.hpp>
RCLCPP_COMPONENTS_REGISTER_NODE(MrmHandler)

0 comments on commit babdfaa

Please sign in to comment.