@@ -30,14 +30,29 @@ MrmStopOperator::MrmStopOperator(const rclcpp::NodeOptions & node_options)
30
30
" ~/input/mrm_request" , 10 ,
31
31
std::bind (&MrmStopOperator::onMrmRequest, this , std::placeholders::_1));
32
32
33
+ sub_odm_group_ =
34
+ create_callback_group (rclcpp::CallbackGroupType::MutuallyExclusive, false );
35
+ rclcpp::SubscriptionOptions odm_options = rclcpp::SubscriptionOptions ();
36
+ odm_options.callback_group = sub_odm_group_;
37
+ auto not_executed_callback = []([[maybe_unused]] const typename nav_msgs::msg::Odometry::ConstSharedPtr msg) {};
38
+ sub_odom_ = create_subscription<nav_msgs::msg::Odometry>(
39
+ " ~/input/odometry" , 10 , not_executed_callback, odm_options);
40
+
33
41
// Publisher
34
42
pub_velocity_limit_ = create_publisher<tier4_planning_msgs::msg::VelocityLimit>(
35
43
" ~/output/velocity_limit" , rclcpp::QoS{10 }.transient_local ());
36
44
pub_velocity_limit_clear_command_ =
37
45
create_publisher<tier4_planning_msgs::msg::VelocityLimitClearCommand>(
38
46
" ~/output/velocity_limit_clear_command" , rclcpp::QoS{10 }.transient_local ());
47
+ pub_mrm_state_ =
48
+ create_publisher<tier4_system_msgs::msg::MrmState>(
49
+ " ~/output/mrm_state" , rclcpp::QoS{1 }.transient_local ());
50
+
39
51
40
52
// Timer
53
+ const auto update_period_ns = rclcpp::Rate (10 ).period ();
54
+ timer_ = rclcpp::create_timer (
55
+ this , get_clock (), update_period_ns, std::bind (&MrmStopOperator::onTimer, this ));
41
56
42
57
// Service
43
58
@@ -67,12 +82,45 @@ void MrmStopOperator::onMrmRequest(const tier4_system_msgs::msg::MrmBehavior::Co
67
82
pub_velocity_limit_->publish (velocity_limit);
68
83
69
84
last_mrm_request_ = *msg;
85
+ current_mrm_state_.behavior = *msg;
86
+ current_mrm_state_.state = tier4_system_msgs::msg::MrmState::MRM_OPERATING;
70
87
}
71
88
}
72
89
73
90
void MrmStopOperator::initState ()
74
91
{
75
92
last_mrm_request_.type = tier4_system_msgs::msg::MrmBehavior::NONE;
93
+ current_mrm_state_.state = tier4_system_msgs::msg::MrmState::NORMAL;
94
+ current_mrm_state_.behavior .type = tier4_system_msgs::msg::MrmBehavior::NONE;
95
+ }
96
+
97
+ void MrmStopOperator::onTimer ()
98
+ {
99
+ if (current_mrm_state_.state == tier4_system_msgs::msg::MrmState::MRM_OPERATING) {
100
+ if (current_mrm_state_.behavior .type == tier4_system_msgs::msg::MrmBehavior::COMFORTABLE_STOP) {
101
+ if (isStopped ()) {
102
+ current_mrm_state_.state = tier4_system_msgs::msg::MrmState::MRM_SUCCEEDED;
103
+ } else {
104
+ // nothing to do
105
+ }
106
+ } else {
107
+ // TODO
108
+ }
109
+ }
110
+ }
111
+
112
+ bool MrmStopOperator::isStopped ()
113
+ {
114
+ constexpr auto th_stopped_velocity = 0.001 ;
115
+ auto current_odom = std::make_shared<nav_msgs::msg::Odometry>();
116
+ rclcpp::MessageInfo message_info;
117
+
118
+ const bool success = sub_odom_->take (*current_odom, message_info);
119
+ if (success) {
120
+ return current_odom->twist .twist .linear .x < th_stopped_velocity;
121
+ } else {
122
+ return false ;
123
+ }
76
124
}
77
125
78
126
} // namespace mrm_stop_operator
0 commit comments