Skip to content

Commit 3f3c1ec

Browse files
committed
fix: move parameters from handlers to operators
Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
1 parent e5ef1f0 commit 3f3c1ec

7 files changed

+91
-107
lines changed

system/emergency_handler/config/emergency_handler.param.yaml

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
ros__parameters:
55
update_rate: 10
66
timeout_hazard_status: 0.5
7-
use_parking_after_stopped: false
87
use_comfortable_stop: false
98

10-
# setting whether to turn hazard lamp on for each situation
11-
turning_hazard_on:
12-
emergency: true
13-
149
# emergency stop operator class
1510
emergency_stop_operator:
1611
target_acceleration: -2.5
1712
target_jerk: -1.5
13+
turning_hazard_on: true
14+
use_parking_after_stopped: false
1815

1916
# comfortable stop operator class
2017
comfortable_stop_operator:

system/emergency_handler/launch/emergency_handler.launch.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<arg name="input_hazard_status" default="/system/emergency/hazard_status"/>
44
<arg name="input_odometry" default="/localization/kinematic_state"/>
55
<arg name="input_control_mode" default="/vehicle/status/control_mode"/>
6-
<arg name="output_gear" default="/system/emergency/gear_cmd"/>
7-
<arg name="output_hazard" default="/system/emergency/hazard_lights_cmd"/>
86
<arg name="output_mrm_state" default="/system/fail_safe/mrm_state"/>
97

108
<arg name="config_file" default="$(find-pkg-share emergency_handler)/config/emergency_handler.param.yaml"/>
119

1210
<!-- emergency stop operator class-->
1311
<arg name="input_control_command" default="/control/command/control_cmd"/>
1412
<arg name="output_emergency_command" default="/system/emergency/control_cmd"/>
13+
<arg name="output_hazard" default="/system/emergency/hazard_lights_cmd"/>
14+
<arg name="output_gear" default="/system/emergency/gear_cmd"/>
1515

1616
<!-- comfortable stop operator class -->
1717
<arg name="output_velocity_limit" default="/planning/scenario_planning/max_velocity_candidates"/>
@@ -22,15 +22,15 @@
2222
<remap from="~/input/hazard_status" to="$(var input_hazard_status)"/>
2323
<remap from="~/input/odometry" to="$(var input_odometry)"/>
2424
<remap from="~/input/control_mode" to="$(var input_control_mode)"/>
25-
<remap from="~/output/gear" to="$(var output_gear)"/>
26-
<remap from="~/output/hazard" to="$(var output_hazard)"/>
2725
<remap from="~/output/mrm/state" to="$(var output_mrm_state)"/>
2826

2927
<param from="$(var config_file)"/>
3028

3129
<!-- emergency stop operator class -->
3230
<remap from="~/input/control/control_cmd" to="$(var input_control_command)"/>
3331
<remap from="~/output/mrm/emergency_stop/control_cmd" to="$(var output_emergency_command)"/>
32+
<remap from="~/output/gear" to="$(var output_gear)"/>
33+
<remap from="~/output/hazard" to="$(var output_hazard)"/>
3434

3535
<!-- comfortable stop operator class -->
3636
<remap from="~/output/velocity_limit" to="$(var output_velocity_limit)"/>

system/emergency_handler/schema/emergency_handler.schema.json

+22-21
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,11 @@
1616
"description": "If the input `hazard_status` topic cannot be received for more than `timeout_hazard_status`, vehicle will make an emergency stop.",
1717
"default": 0.5
1818
},
19-
"use_parking_after_stopped": {
20-
"type": "boolean",
21-
"description": "If this parameter is true, it will publish PARKING shift command.",
22-
"default": "false"
23-
},
2419
"use_comfortable_stop": {
2520
"type": "boolean",
2621
"description": "If this parameter is true, operate comfortable stop when latent faults occur.",
2722
"default": "false"
2823
},
29-
"turning_hazard_on": {
30-
"type": "object",
31-
"properties": {
32-
"emergency": {
33-
"type": "boolean",
34-
"description": "If this parameter is true, hazard lamps will be turned on during emergency state.",
35-
"default": "true"
36-
}
37-
},
38-
"required": ["emergency"]
39-
},
4024
"emergency_stop_operator": {
4125
"type": "object",
4226
"properties": {
@@ -47,11 +31,26 @@
4731
},
4832
"target_jerk": {
4933
"type": "number",
50-
"description": "Target jerk for emergency stop [m/s^3] ",
34+
"description": "Target jerk for emergency stop [m/s^3]",
5135
"default": -1.5
36+
},
37+
"turning_hazard_on": {
38+
"type": "boolean",
39+
"description": "Whether to turn on hazard lamps when emergency_stop is being operated",
40+
"default": "true"
41+
},
42+
"use_parking_after_stopped": {
43+
"type": "boolean",
44+
"description": "Whether to enable GearCommand::PARK after emergency_stop succeeded",
45+
"default": "false"
5246
}
5347
},
54-
"required": ["target_acceleration", "target_jerk"]
48+
"required": [
49+
"target_acceleration",
50+
"target_jerk",
51+
"turning_hazard_on",
52+
"use_parking_after_stopped"
53+
]
5554
},
5655
"comfortable_stop_operator": {
5756
"type": "object",
@@ -72,15 +71,17 @@
7271
"default": -0.3
7372
}
7473
},
75-
"required": ["min_acceleration", "max_jerk", "min_jerk"]
74+
"required": [
75+
"min_acceleration",
76+
"max_jerk",
77+
"min_jerk"
78+
]
7679
}
7780
},
7881
"required": [
7982
"update_rate",
8083
"timeout_hazard_status",
81-
"use_parking_after_stopped",
8284
"use_comfortable_stop",
83-
"turning_hazard_on",
8485
"emergency_stop",
8586
"comfortable_stop"
8687
],

system/emergency_handler/src/emergency_handler_core.cpp

-54
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ EmergencyHandler::EmergencyHandler() : Node("emergency_handler")
2626
// Parameter
2727
param_.update_rate = declare_parameter<int>("update_rate");
2828
param_.timeout_hazard_status = declare_parameter<double>("timeout_hazard_status");
29-
param_.use_parking_after_stopped = declare_parameter<bool>("use_parking_after_stopped");
3029
param_.use_comfortable_stop = declare_parameter<bool>("use_comfortable_stop");
31-
param_.turning_hazard_on.emergency = declare_parameter<bool>("turning_hazard_on.emergency");
3230

3331
using std::placeholders::_1;
3432

@@ -39,15 +37,10 @@ EmergencyHandler::EmergencyHandler() : Node("emergency_handler")
3937
std::bind(&EmergencyHandler::onHazardStatusStamped, this, _1));
4038
sub_odom_ = create_subscription<nav_msgs::msg::Odometry>(
4139
"~/input/odometry", rclcpp::QoS{1}, std::bind(&EmergencyHandler::onOdometry, this, _1));
42-
// subscribe control mode
4340
sub_control_mode_ = create_subscription<autoware_auto_vehicle_msgs::msg::ControlModeReport>(
4441
"~/input/control_mode", rclcpp::QoS{1}, std::bind(&EmergencyHandler::onControlMode, this, _1));
4542

4643
// Publisher
47-
pub_hazard_cmd_ = create_publisher<autoware_auto_vehicle_msgs::msg::HazardLightsCommand>(
48-
"~/output/hazard", rclcpp::QoS{1});
49-
pub_gear_cmd_ =
50-
create_publisher<autoware_auto_vehicle_msgs::msg::GearCommand>("~/output/gear", rclcpp::QoS{1});
5144
pub_mrm_state_ =
5245
create_publisher<autoware_adapi_v1_msgs::msg::MrmState>("~/output/mrm/state", rclcpp::QoS{1});
5346

@@ -88,51 +81,6 @@ void EmergencyHandler::onControlMode(
8881
control_mode_ = msg;
8982
}
9083

91-
autoware_auto_vehicle_msgs::msg::HazardLightsCommand EmergencyHandler::createHazardCmdMsg()
92-
{
93-
using autoware_auto_vehicle_msgs::msg::HazardLightsCommand;
94-
HazardLightsCommand msg;
95-
96-
// Check emergency
97-
const bool is_emergency = isEmergency();
98-
99-
if (hazard_status_stamped_->status.emergency_holding) {
100-
// turn hazard on during emergency holding
101-
msg.command = HazardLightsCommand::ENABLE;
102-
} else if (is_emergency && param_.turning_hazard_on.emergency) {
103-
// turn hazard on if vehicle is in emergency state and
104-
// turning hazard on if emergency flag is true
105-
msg.command = HazardLightsCommand::ENABLE;
106-
107-
} else {
108-
msg.command = HazardLightsCommand::NO_COMMAND;
109-
}
110-
return msg;
111-
}
112-
113-
void EmergencyHandler::publishControlCommands()
114-
{
115-
using autoware_auto_vehicle_msgs::msg::GearCommand;
116-
117-
// Create timestamp
118-
const auto stamp = this->now();
119-
120-
// Publish hazard command
121-
pub_hazard_cmd_->publish(createHazardCmdMsg());
122-
123-
// Publish gear
124-
{
125-
GearCommand msg;
126-
msg.stamp = stamp;
127-
if (param_.use_parking_after_stopped && isStopped()) {
128-
msg.command = GearCommand::PARK;
129-
} else {
130-
msg.command = GearCommand::DRIVE;
131-
}
132-
pub_gear_cmd_->publish(msg);
133-
}
134-
}
135-
13684
void EmergencyHandler::publishMrmState()
13785
{
13886
mrm_state_.stamp = this->now();
@@ -269,8 +217,6 @@ void EmergencyHandler::onTimer()
269217
// Update Emergency State
270218
updateMrmState();
271219

272-
// Publish control commands
273-
publishControlCommands();
274220
operateMrm();
275221
publishMrmState();
276222
}

system/emergency_handler/src/emergency_handler_core.hpp

-17
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include <autoware_adapi_v1_msgs/msg/mrm_state.hpp>
2424
#include <autoware_auto_system_msgs/msg/hazard_status_stamped.hpp>
2525
#include <autoware_auto_vehicle_msgs/msg/control_mode_report.hpp>
26-
#include <autoware_auto_vehicle_msgs/msg/gear_command.hpp>
27-
#include <autoware_auto_vehicle_msgs/msg/hazard_lights_command.hpp>
2826

2927
// ROS 2 core
3028
#include <rclcpp/rclcpp.hpp>
@@ -39,18 +37,12 @@
3937
namespace emergency_handler
4038
{
4139

42-
struct HazardLampPolicy
43-
{
44-
bool emergency;
45-
};
46-
4740
struct Param
4841
{
4942
int update_rate;
5043
double timeout_hazard_status;
5144
bool use_parking_after_stopped;
5245
bool use_comfortable_stop;
53-
HazardLampPolicy turning_hazard_on{};
5446
};
5547

5648
class EmergencyHandler : public rclcpp::Node
@@ -76,16 +68,7 @@ class EmergencyHandler : public rclcpp::Node
7668
void onControlMode(const autoware_auto_vehicle_msgs::msg::ControlModeReport::ConstSharedPtr msg);
7769

7870
// Publisher
79-
rclcpp::Publisher<autoware_auto_vehicle_msgs::msg::HazardLightsCommand>::SharedPtr
80-
pub_hazard_cmd_;
81-
rclcpp::Publisher<autoware_auto_vehicle_msgs::msg::GearCommand>::SharedPtr pub_gear_cmd_;
82-
83-
autoware_auto_vehicle_msgs::msg::HazardLightsCommand createHazardCmdMsg();
84-
autoware_auto_vehicle_msgs::msg::GearCommand createGearCmdMsg();
85-
void publishControlCommands();
86-
8771
rclcpp::Publisher<autoware_adapi_v1_msgs::msg::MrmState>::SharedPtr pub_mrm_state_;
88-
8972
autoware_adapi_v1_msgs::msg::MrmState mrm_state_;
9073
void publishMrmState();
9174

system/emergency_handler/src/emergency_stop_operator.cpp

+45-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ EmergencyStopOperator::EmergencyStopOperator(rclcpp::Node * node) : node_(node)
2323
params_.target_acceleration =
2424
node_->declare_parameter<double>("emergency_stop_operator.target_acceleration");
2525
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");
2628

2729
// Subscriber
2830
sub_control_cmd_ = node_->create_subscription<AckermannControlCommand>(
2931
"~/input/control/control_cmd", 1,
3032
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));
3135

3236
// Publisher
3337
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});
3541

3642
// Initialize
3743
is_prev_control_cmd_subscribed_ = false;
@@ -43,14 +49,24 @@ void EmergencyStopOperator::onControlCommand(AckermannControlCommand::ConstShare
4349
is_prev_control_cmd_subscribed_ = true;
4450
}
4551

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+
4658
void EmergencyStopOperator::onTimer()
4759
{
48-
pub_control_cmd_->publish(calcNextControlCmd());
60+
publishControlCmd();
61+
publishHazardLightCmd();
62+
publishGearCmd();
4963
}
5064

5165
bool EmergencyStopOperator::operate()
5266
{
53-
pub_control_cmd_->publish(calcNextControlCmd());
67+
publishControlCmd();
68+
publishHazardLightCmd();
69+
publishGearCmd();
5470

5571
// Currently, EmergencyStopOperator does not return false
5672
return true;
@@ -64,7 +80,7 @@ bool EmergencyStopOperator::cancel()
6480
return true;
6581
}
6682

67-
AckermannControlCommand EmergencyStopOperator::calcNextControlCmd()
83+
void EmergencyStopOperator::publishControlCmd()
6884
{
6985
AckermannControlCommand control_cmd;
7086
auto now = node_->now();
@@ -105,7 +121,31 @@ AckermannControlCommand EmergencyStopOperator::calcNextControlCmd()
105121
// lateral: keep previous lateral command
106122
}
107123

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);
109149
}
110150

111151
} // namespace emergency_handler::emergency_stop_operator

0 commit comments

Comments
 (0)