@@ -23,15 +23,21 @@ EmergencyStopOperator::EmergencyStopOperator(rclcpp::Node * node) : node_(node)
23
23
params_.target_acceleration =
24
24
node_->declare_parameter <double >(" emergency_stop_operator.target_acceleration" );
25
25
params_.target_jerk = node_->declare_parameter <double >(" emergency_stop_operator.target_jerk" );
26
+ params_.turning_hazard_on = node_->declare_parameter <bool >(" emergency_stop_operator.turning_hazard_on" );
27
+ params_.use_parking_after_stopped = node_->declare_parameter <bool >(" emergency_stop_operator.use_parking_after_stopped" );
26
28
27
29
// Subscriber
28
30
sub_control_cmd_ = node_->create_subscription <AckermannControlCommand>(
29
31
" ~/input/control/control_cmd" , 1 ,
30
32
std::bind (&EmergencyStopOperator::onControlCommand, this , std::placeholders::_1));
33
+ sub_odom_ = node_->create_subscription <nav_msgs::msg::Odometry>(
34
+ " ~/input/odometry" , rclcpp::QoS{1 }, std::bind (&EmergencyStopOperator::onOdometry, this , std::placeholders::_1));
31
35
32
36
// Publisher
33
37
pub_control_cmd_ =
34
- node_->create_publisher <AckermannControlCommand>(" ~/output/mrm/emergency_stop/control_cmd" , 1 );
38
+ node_->create_publisher <AckermannControlCommand>(" ~/output/mrm/emergency_stop/control_cmd" , rclcpp::QoS{1 });
39
+ pub_hazard_light_cmd_ = node_->create_publisher <HazardLightsCommand>(" ~/output/hazard" , rclcpp::QoS{1 });
40
+ pub_gear_cmd_ = node_->create_publisher <GearCommand>(" ~/output/gear" , rclcpp::QoS{1 });
35
41
36
42
// Initialize
37
43
is_prev_control_cmd_subscribed_ = false ;
@@ -43,14 +49,24 @@ void EmergencyStopOperator::onControlCommand(AckermannControlCommand::ConstShare
43
49
is_prev_control_cmd_subscribed_ = true ;
44
50
}
45
51
52
+ void EmergencyStopOperator::onOdometry (const nav_msgs::msg::Odometry::ConstSharedPtr msg)
53
+ {
54
+ constexpr auto th_stopped_velocity = 0.001 ;
55
+ is_stopped_ = msg->twist .twist .linear .x < th_stopped_velocity;
56
+ }
57
+
46
58
void EmergencyStopOperator::onTimer ()
47
59
{
48
- pub_control_cmd_->publish (calcNextControlCmd ());
60
+ publishControlCmd ();
61
+ publishHazardLightCmd ();
62
+ publishGearCmd ();
49
63
}
50
64
51
65
bool EmergencyStopOperator::operate ()
52
66
{
53
- pub_control_cmd_->publish (calcNextControlCmd ());
67
+ publishControlCmd ();
68
+ publishHazardLightCmd ();
69
+ publishGearCmd ();
54
70
55
71
// Currently, EmergencyStopOperator does not return false
56
72
return true ;
@@ -64,7 +80,7 @@ bool EmergencyStopOperator::cancel()
64
80
return true ;
65
81
}
66
82
67
- AckermannControlCommand EmergencyStopOperator::calcNextControlCmd ()
83
+ void EmergencyStopOperator::publishControlCmd ()
68
84
{
69
85
AckermannControlCommand control_cmd;
70
86
auto now = node_->now ();
@@ -105,7 +121,31 @@ AckermannControlCommand EmergencyStopOperator::calcNextControlCmd()
105
121
// lateral: keep previous lateral command
106
122
}
107
123
108
- return control_cmd;
124
+ pub_control_cmd_->publish (control_cmd);
125
+ }
126
+
127
+ void EmergencyStopOperator::publishHazardLightCmd ()
128
+ {
129
+ HazardLightsCommand hazard_light_cmd;
130
+ hazard_light_cmd.stamp = node_->now ();
131
+ if (params_.turning_hazard_on ) {
132
+ hazard_light_cmd.command = HazardLightsCommand::ENABLE;
133
+ } else {
134
+ hazard_light_cmd.command = HazardLightsCommand::NO_COMMAND;
135
+ }
136
+ pub_hazard_light_cmd_->publish (hazard_light_cmd);
137
+ }
138
+
139
+ void EmergencyStopOperator::publishGearCmd ()
140
+ {
141
+ GearCommand gear_cmd;
142
+ gear_cmd.stamp = node_->now ();
143
+ if (params_.use_parking_after_stopped && is_stopped_) {
144
+ gear_cmd.command = GearCommand::PARK;
145
+ } else {
146
+ gear_cmd.command = GearCommand::DRIVE;
147
+ }
148
+ pub_gear_cmd_->publish (gear_cmd);
109
149
}
110
150
111
151
} // namespace emergency_handler::emergency_stop_operator
0 commit comments