Skip to content

Commit 4ef410e

Browse files
authored
Merge branch 'main' into fix_mrm_handler
2 parents a2d99b8 + d3886e4 commit 4ef410e

File tree

9 files changed

+34
-113
lines changed

9 files changed

+34
-113
lines changed

control/mpc_lateral_controller/src/mpc_lateral_controller.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ trajectory_follower::LateralOutput MpcLateralController::run(
243243
Trajectory predicted_traj;
244244
Float32MultiArrayStamped debug_values;
245245

246-
if (!m_is_ctrl_cmd_prev_initialized) {
246+
const bool is_under_control = input_data.current_operation_mode.is_autoware_control_enabled &&
247+
input_data.current_operation_mode.mode ==
248+
autoware_adapi_v1_msgs::msg::OperationModeState::AUTONOMOUS;
249+
250+
if (!m_is_ctrl_cmd_prev_initialized || !is_under_control) {
247251
m_ctrl_cmd_prev = getInitialControlCommand();
248252
m_is_ctrl_cmd_prev_initialized = true;
249253
}

system/emergency_handler/config/emergency_handler.param.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
ros__parameters:
55
update_rate: 10
66
timeout_hazard_status: 0.5
7-
timeout_takeover_request: 10.0
8-
use_takeover_request: false
97
use_parking_after_stopped: false
108
use_comfortable_stop: false
119

system/emergency_handler/include/emergency_handler/emergency_handler_core.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ struct Param
4545
{
4646
int update_rate;
4747
double timeout_hazard_status;
48-
double timeout_takeover_request;
49-
bool use_takeover_request;
5048
bool use_parking_after_stopped;
5149
bool use_comfortable_stop;
5250
HazardLampPolicy turning_hazard_on{};
@@ -135,8 +133,6 @@ class EmergencyHandler : public rclcpp::Node
135133
rclcpp::Time stamp_hazard_status_;
136134

137135
// Algorithm
138-
rclcpp::Time takeover_requested_time_;
139-
bool is_takeover_request_ = false;
140136
void transitionTo(const int new_state);
141137
void updateMrmState();
142138
void operateMrm();

system/emergency_handler/schema/emergency_handler.schema.json

-12
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
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-
"timeout_takeover_request": {
20-
"type": "number",
21-
"description": "Transition to MRR_OPERATING if the time from the last takeover request exceeds `timeout_takeover_request`.",
22-
"default": 10.0
23-
},
24-
"use_takeover_request": {
25-
"type": "boolean",
26-
"description": "If this parameter is true, the handler will record the time and make take over request to the driver when emergency state occurs.",
27-
"default": "false"
28-
},
2919
"use_parking_after_stopped": {
3020
"type": "boolean",
3121
"description": "If this parameter is true, it will publish PARKING shift command.",
@@ -51,8 +41,6 @@
5141
"required": [
5242
"update_rate",
5343
"timeout_hazard_status",
54-
"timeout_takeover_request",
55-
"use_takeover_request",
5644
"use_parking_after_stopped",
5745
"use_comfortable_stop",
5846
"turning_hazard_on"

system/emergency_handler/src/emergency_handler/emergency_handler_core.cpp

+4-24
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ EmergencyHandler::EmergencyHandler() : Node("emergency_handler")
2323
// Parameter
2424
param_.update_rate = declare_parameter<int>("update_rate");
2525
param_.timeout_hazard_status = declare_parameter<double>("timeout_hazard_status");
26-
param_.timeout_takeover_request = declare_parameter<double>("timeout_takeover_request");
27-
param_.use_takeover_request = declare_parameter<bool>("use_takeover_request");
2826
param_.use_parking_after_stopped = declare_parameter<bool>("use_parking_after_stopped");
2927
param_.use_comfortable_stop = declare_parameter<bool>("use_comfortable_stop");
3028
param_.turning_hazard_on.emergency = declare_parameter<bool>("turning_hazard_on.emergency");
@@ -375,41 +373,23 @@ void EmergencyHandler::updateMrmState()
375373

376374
// Get mode
377375
const bool is_auto_mode = control_mode_->mode == ControlModeReport::AUTONOMOUS;
378-
const bool is_takeover_done = control_mode_->mode == ControlModeReport::MANUAL;
379376

380377
// State Machine
381378
if (mrm_state_.state == MrmState::NORMAL) {
382379
// NORMAL
383380
if (is_auto_mode && is_emergency) {
384-
if (param_.use_takeover_request) {
385-
takeover_requested_time_ = this->get_clock()->now();
386-
is_takeover_request_ = true;
387-
return;
388-
} else {
389-
transitionTo(MrmState::MRM_OPERATING);
390-
return;
391-
}
381+
transitionTo(MrmState::MRM_OPERATING);
382+
return;
392383
}
393384
} else {
394385
// Emergency
395-
// Send recovery events if "not emergency" or "takeover done"
386+
// Send recovery events if "not emergency"
396387
if (!is_emergency) {
397388
transitionTo(MrmState::NORMAL);
398389
return;
399390
}
400-
// TODO(Kenji Miyake): Check if human can safely override, for example using DSM
401-
if (is_takeover_done) {
402-
transitionTo(MrmState::NORMAL);
403-
return;
404-
}
405391

406-
if (is_takeover_request_) {
407-
const auto time_from_takeover_request = this->get_clock()->now() - takeover_requested_time_;
408-
if (time_from_takeover_request.seconds() > param_.timeout_takeover_request) {
409-
transitionTo(MrmState::MRM_OPERATING);
410-
return;
411-
}
412-
} else if (mrm_state_.state == MrmState::MRM_OPERATING) {
392+
if (mrm_state_.state == MrmState::MRM_OPERATING) {
413393
// TODO(Kenji Miyake): Check MRC is accomplished
414394
if (isStopped()) {
415395
transitionTo(MrmState::MRM_SUCCEEDED);

system/mrm_handler/config/mrm_handler.param.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
timeout_operation_mode_availability: 0.5
77
use_emergency_holding: false
88
timeout_emergency_recovery: 5.0
9-
timeout_takeover_request: 10.0
10-
use_takeover_request: false
119
use_parking_after_stopped: false
1210
use_pull_over: false
1311
use_comfortable_stop: false

system/mrm_handler/include/mrm_handler/mrm_handler_core.hpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ struct Param
4949
double timeout_operation_mode_availability;
5050
bool use_emergency_holding;
5151
double timeout_emergency_recovery;
52-
double timeout_takeover_request;
53-
bool use_takeover_request;
5452
bool use_parking_after_stopped;
5553
bool use_pull_over;
5654
bool use_comfortable_stop;
@@ -106,9 +104,8 @@ class MrmHandler : public rclcpp::Node
106104
pub_hazard_cmd_;
107105
rclcpp::Publisher<autoware_auto_vehicle_msgs::msg::GearCommand>::SharedPtr pub_gear_cmd_;
108106

109-
autoware_auto_vehicle_msgs::msg::HazardLightsCommand createHazardCmdMsg();
110-
autoware_auto_vehicle_msgs::msg::GearCommand createGearCmdMsg();
111-
void publishControlCommands();
107+
void publishHazardCmd();
108+
void publishGearCmd();
112109

113110
rclcpp::Publisher<autoware_adapi_v1_msgs::msg::MrmState>::SharedPtr pub_mrm_state_;
114111

@@ -147,8 +144,6 @@ class MrmHandler : public rclcpp::Node
147144
void checkOperationModeAvailabilityTimeout();
148145

149146
// Algorithm
150-
rclcpp::Time takeover_requested_time_;
151-
bool is_takeover_request_ = false;
152147
bool is_emergency_holding_ = false;
153148
void transitionTo(const int new_state);
154149
void updateMrmState();

system/mrm_handler/schema/mrm_handler.schema.json

-12
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@
2626
"description": "If the duration of the EMERGENCY state is longer than `timeout_emergency_recovery`, it does not recover to the NORMAL state.",
2727
"default": 5.0
2828
},
29-
"timeout_takeover_request": {
30-
"type": "number",
31-
"description": "Transition to MRR_OPERATING if the time from the last takeover request exceeds `timeout_takeover_request`.",
32-
"default": 10.0
33-
},
34-
"use_takeover_request": {
35-
"type": "boolean",
36-
"description": "If this parameter is true, the handler will record the time and make take over request to the driver when emergency state occurs.",
37-
"default": "false"
38-
},
3929
"use_parking_after_stopped": {
4030
"type": "boolean",
4131
"description": "If this parameter is true, it will publish PARKING shift command.",
@@ -68,8 +58,6 @@
6858
"timeout_operation_mode_availability",
6959
"use_emergency_holding",
7060
"timeout_emergency_recovery",
71-
"timeout_takeover_request",
72-
"use_takeover_request",
7361
"use_parking_after_stopped",
7462
"use_pull_over",
7563
"use_comfortable_stop",

system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp

+23-49
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ MrmHandler::MrmHandler() : Node("mrm_handler")
2626
declare_parameter<double>("timeout_operation_mode_availability", 0.5);
2727
param_.use_emergency_holding = declare_parameter<bool>("use_emergency_holding", false);
2828
param_.timeout_emergency_recovery = declare_parameter<double>("timeout_emergency_recovery", 5.0);
29-
param_.timeout_takeover_request = declare_parameter<double>("timeout_takeover_request", 10.0);
30-
param_.use_takeover_request = declare_parameter<bool>("use_takeover_request", false);
3129
param_.use_parking_after_stopped = declare_parameter<bool>("use_parking_after_stopped", false);
3230
param_.use_pull_over = declare_parameter<bool>("use_pull_over", false);
3331
param_.use_comfortable_stop = declare_parameter<bool>("use_comfortable_stop", false);
@@ -164,48 +162,39 @@ void MrmHandler::onOperationModeState(
164162
operation_mode_state_ = msg;
165163
}
166164

167-
autoware_auto_vehicle_msgs::msg::HazardLightsCommand MrmHandler::createHazardCmdMsg()
165+
void MrmHandler::publishHazardCmd()
168166
{
169167
using autoware_auto_vehicle_msgs::msg::HazardLightsCommand;
170168
HazardLightsCommand msg;
171169

172-
// Check emergency
173-
const bool is_emergency = isEmergency();
174-
170+
msg.stamp = this->now();
175171
if (is_emergency_holding_) {
176172
// turn hazard on during emergency holding
177173
msg.command = HazardLightsCommand::ENABLE;
178-
} else if (is_emergency && param_.turning_hazard_on.emergency) {
174+
} else if (isEmergency() && param_.turning_hazard_on.emergency) {
179175
// turn hazard on if vehicle is in emergency state and
180176
// turning hazard on if emergency flag is true
181177
msg.command = HazardLightsCommand::ENABLE;
182178
} else {
183179
msg.command = HazardLightsCommand::NO_COMMAND;
184180
}
185-
return msg;
181+
182+
pub_hazard_cmd_->publish(msg);
186183
}
187184

188-
void MrmHandler::publishControlCommands()
185+
void MrmHandler::publishGearCmd()
189186
{
190187
using autoware_auto_vehicle_msgs::msg::GearCommand;
188+
GearCommand msg;
191189

192-
// Create timestamp
193-
const auto stamp = this->now();
194-
195-
// Publish hazard command
196-
pub_hazard_cmd_->publish(createHazardCmdMsg());
197-
198-
// Publish gear
199-
{
200-
GearCommand msg;
201-
msg.stamp = stamp;
202-
if (param_.use_parking_after_stopped && isStopped()) {
203-
msg.command = GearCommand::PARK;
204-
} else {
205-
msg.command = GearCommand::DRIVE;
206-
}
207-
pub_gear_cmd_->publish(msg);
190+
msg.stamp = this->now();
191+
if (param_.use_parking_after_stopped && isStopped()) {
192+
msg.command = GearCommand::PARK;
193+
} else {
194+
msg.command = GearCommand::DRIVE;
208195
}
196+
197+
pub_gear_cmd_->publish(msg);
209198
}
210199

211200
void MrmHandler::publishMrmState()
@@ -396,10 +385,13 @@ void MrmHandler::onTimer()
396385
// Update Emergency State
397386
updateMrmState();
398387

399-
// Publish control commands
400-
publishControlCommands();
388+
// Operate MRM
401389
operateMrm();
390+
391+
// Publish
402392
publishMrmState();
393+
publishHazardCmd();
394+
publishGearCmd();
403395
}
404396

405397
void MrmHandler::transitionTo(const int new_state)
@@ -441,41 +433,23 @@ void MrmHandler::updateMrmState()
441433

442434
// Get mode
443435
const bool is_auto_mode = control_mode_->mode == ControlModeReport::AUTONOMOUS;
444-
const bool is_takeover_done = control_mode_->mode == ControlModeReport::MANUAL;
445436

446437
// State Machine
447438
if (mrm_state_.state == MrmState::NORMAL) {
448439
// NORMAL
449440
if (is_auto_mode && is_emergency) {
450-
if (param_.use_takeover_request) {
451-
takeover_requested_time_ = this->get_clock()->now();
452-
is_takeover_request_ = true;
453-
return;
454-
} else {
455-
transitionTo(MrmState::MRM_OPERATING);
456-
return;
457-
}
441+
transitionTo(MrmState::MRM_OPERATING);
442+
return;
458443
}
459444
} else {
460445
// Emergency
461-
// Send recovery events if "not emergency" or "takeover done"
446+
// Send recovery events if "not emergency"
462447
if (!is_emergency) {
463448
transitionTo(MrmState::NORMAL);
464449
return;
465450
}
466-
// TODO(TetsuKawa): Check if human can safely override, for example using DSM
467-
if (is_takeover_done) {
468-
transitionTo(MrmState::NORMAL);
469-
return;
470-
}
471451

472-
if (is_takeover_request_) {
473-
const auto time_from_takeover_request = this->get_clock()->now() - takeover_requested_time_;
474-
if (time_from_takeover_request.seconds() > param_.timeout_takeover_request) {
475-
transitionTo(MrmState::MRM_OPERATING);
476-
return;
477-
}
478-
} else if (mrm_state_.state == MrmState::MRM_OPERATING) {
452+
if (mrm_state_.state == MrmState::MRM_OPERATING) {
479453
// TODO(TetsuKawa): Check MRC is accomplished
480454
if (mrm_state_.behavior == MrmState::PULL_OVER) {
481455
if (isStopped() && isArrivedAtGoal()) {

0 commit comments

Comments
 (0)