Skip to content

Commit d32f0ab

Browse files
committed
feat: add publisher of mrm state
Signed-off-by: TetsuKawa <kawaguchitnon@icloud.com>
1 parent 81f51f5 commit d32f0ab

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<launch>
22
<arg name="mrm_stop_operator_param_path" default="$(find-pkg-share mrm_stop_operator)/config/mrm_stop_operator.param.yaml"/>
3+
<arg name="input_mrm_request" default="/system/mrm_request"/>
4+
<arg name="input_odometry" default="/localization/kinematic_state"/>
5+
<arg name="output_max_velocity" default="/planning/scenario_planning/max_velocity_candidates"/>
6+
<arg name="output_max_velocity_clear_command" default="/planning/scenario_planning/clear_velocity_limit"/>
7+
<arg name="output_mrm_state" default="/system/fail_safe/mrm_state"/>
38

49
<node pkg="mrm_stop_operator" exec="mrm_stop_operator_node" name="mrm_stop_operator" output="screen">
510
<param from="$(var mrm_stop_operator_param_path)"/>
611

7-
<remap from="~/input/mrm_request" to="/system/mrm_request"/>
8-
<remap from="~/output/velocity_limit" to="/planning/scenario_planning/max_velocity_candidates"/>
9-
<remap from="~/output/velocity_limit_clear_command" to="/planning/scenario_planning/clear_velocity_limit"/>
12+
<remap from="~/input/mrm_request" to="$(var input_mrm_request)"/>
13+
<remap from="~/input/odometry" to="$(var input_odometry)"/>
14+
<remap from="~/output/velocity_limit" to="$(var output_max_velocity)"/>
15+
<remap from="~/output/velocity_limit_clear_command" to="$(var output_max_velocity_clear_command)"/>
16+
<remap from="~/output/mrm_state" to="$(var output_mrm_state)"/>
1017
</node>
1118
</launch>

system/mrm_stop_operator/package.xml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<depend>rclcpp_components</depend>
1717
<depend>tier4_planning_msgs</depend>
1818
<depend>tier4_system_msgs</depend>
19+
<depend>nav_msgs</depend>
20+
1921

2022
<test_depend>ament_lint_auto</test_depend>
2123
<test_depend>autoware_lint_common</test_depend>

system/mrm_stop_operator/src/mrm_stop_operator.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,29 @@ MrmStopOperator::MrmStopOperator(const rclcpp::NodeOptions & node_options)
3030
"~/input/mrm_request", 10,
3131
std::bind(&MrmStopOperator::onMrmRequest, this, std::placeholders::_1));
3232

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+
3341
// Publisher
3442
pub_velocity_limit_ = create_publisher<tier4_planning_msgs::msg::VelocityLimit>(
3543
"~/output/velocity_limit", rclcpp::QoS{10}.transient_local());
3644
pub_velocity_limit_clear_command_ =
3745
create_publisher<tier4_planning_msgs::msg::VelocityLimitClearCommand>(
3846
"~/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+
3951

4052
// 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));
4156

4257
// Service
4358

@@ -67,12 +82,45 @@ void MrmStopOperator::onMrmRequest(const tier4_system_msgs::msg::MrmBehavior::Co
6782
pub_velocity_limit_->publish(velocity_limit);
6883

6984
last_mrm_request_ = *msg;
85+
current_mrm_state_.behavior = *msg;
86+
current_mrm_state_.state = tier4_system_msgs::msg::MrmState::MRM_OPERATING;
7087
}
7188
}
7289

7390
void MrmStopOperator::initState()
7491
{
7592
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+
}
76124
}
77125

78126
} // namespace mrm_stop_operator

system/mrm_stop_operator/src/mrm_stop_operator.hpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <tier4_planning_msgs/msg/velocity_limit.hpp>
2222
#include <tier4_planning_msgs/msg/velocity_limit_clear_command.hpp>
2323
#include <tier4_system_msgs/msg/mrm_behavior.hpp>
24+
#include <tier4_system_msgs/msg/mrm_state.hpp>
25+
#include <nav_msgs/msg/odometry.hpp>
2426

2527
namespace mrm_stop_operator
2628
{
@@ -44,6 +46,7 @@ class MrmStopOperator : public rclcpp::Node
4446

4547
// Subscriber
4648
rclcpp::Subscription<tier4_system_msgs::msg::MrmBehavior>::SharedPtr sub_mrm_request_;
49+
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr sub_odom_;
4750

4851
void onMrmRequest(const tier4_system_msgs::msg::MrmBehavior::ConstSharedPtr msg);
4952

@@ -53,17 +56,23 @@ class MrmStopOperator : public rclcpp::Node
5356
rclcpp::Publisher<tier4_planning_msgs::msg::VelocityLimit>::SharedPtr pub_velocity_limit_;
5457
rclcpp::Publisher<tier4_planning_msgs::msg::VelocityLimitClearCommand>::SharedPtr
5558
pub_velocity_limit_clear_command_;
56-
59+
rclcpp::Publisher<tier4_system_msgs::msg::MrmState>::SharedPtr pub_mrm_state_;
5760
// Service
5861

5962
// Client
6063

6164
// Timer
65+
rclcpp::TimerBase::SharedPtr timer_;
66+
67+
rclcpp::CallbackGroup::SharedPtr sub_odm_group_;
6268

6369
// State
6470
tier4_system_msgs::msg::MrmBehavior last_mrm_request_;
71+
tier4_system_msgs::msg::MrmState current_mrm_state_;
6572

6673
void initState();
74+
void onTimer();
75+
bool isStopped();
6776

6877
// Diagnostics
6978
};

0 commit comments

Comments
 (0)