Skip to content

Commit b404c8f

Browse files
authored
fix(mrm_handler): fix bug in operation mode availability timeout (#6513)
* fix operation mode availability timeout Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
1 parent 8bdb542 commit b404c8f

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

system/mrm_handler/include/mrm_handler/mrm_handler_core.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class MrmHandler : public rclcpp::Node
144144
// Heartbeat
145145
rclcpp::Time stamp_operation_mode_availability_;
146146
std::optional<rclcpp::Time> stamp_autonomous_become_unavailable_ = std::nullopt;
147+
bool is_operation_mode_availability_timeout;
148+
void checkOperationModeAvailabilityTimeout();
147149

148150
// Algorithm
149151
bool is_emergency_holding_ = false;

system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp

+31-12
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ MrmHandler::MrmHandler() : Node("mrm_handler")
9494
mrm_state_.stamp = this->now();
9595
mrm_state_.state = autoware_adapi_v1_msgs::msg::MrmState::NORMAL;
9696
mrm_state_.behavior = autoware_adapi_v1_msgs::msg::MrmState::NONE;
97+
is_operation_mode_availability_timeout = false;
9798

9899
// Timer
99100
const auto update_period_ns = rclcpp::Rate(param_.update_rate).period();
@@ -376,24 +377,29 @@ bool MrmHandler::isDataReady()
376377
return true;
377378
}
378379

379-
void MrmHandler::onTimer()
380+
void MrmHandler::checkOperationModeAvailabilityTimeout()
380381
{
381-
if (!isDataReady()) {
382-
return;
383-
}
384-
const bool is_operation_mode_availability_timeout =
382+
if (
385383
(this->now() - stamp_operation_mode_availability_).seconds() >
386-
param_.timeout_operation_mode_availability;
387-
if (is_operation_mode_availability_timeout) {
384+
param_.timeout_operation_mode_availability) {
385+
is_operation_mode_availability_timeout = true;
388386
RCLCPP_WARN_THROTTLE(
389387
this->get_logger(), *this->get_clock(), std::chrono::milliseconds(1000).count(),
390-
"heartbeat operation_mode_availability is timeout");
391-
mrm_state_.state = autoware_adapi_v1_msgs::msg::MrmState::MRM_OPERATING;
392-
publishHazardCmd();
393-
publishGearCmd();
388+
"operation_mode_availability is timeout");
389+
} else {
390+
is_operation_mode_availability_timeout = false;
391+
}
392+
}
393+
394+
void MrmHandler::onTimer()
395+
{
396+
if (!isDataReady()) {
394397
return;
395398
}
396399

400+
// Check whether operation_mode_availability is timeout
401+
checkOperationModeAvailabilityTimeout();
402+
397403
// Update Emergency State
398404
updateMrmState();
399405

@@ -495,6 +501,9 @@ autoware_adapi_v1_msgs::msg::MrmState::_behavior_type MrmHandler::getCurrentMrmB
495501

496502
// State machine
497503
if (mrm_state_.behavior == MrmState::NONE) {
504+
if (is_operation_mode_availability_timeout) {
505+
return MrmState::EMERGENCY_STOP;
506+
}
498507
if (operation_mode_availability_->pull_over) {
499508
if (param_.use_pull_over) {
500509
return MrmState::PULL_OVER;
@@ -511,6 +520,9 @@ autoware_adapi_v1_msgs::msg::MrmState::_behavior_type MrmHandler::getCurrentMrmB
511520
return MrmState::EMERGENCY_STOP;
512521
}
513522
if (mrm_state_.behavior == MrmState::PULL_OVER) {
523+
if (is_operation_mode_availability_timeout) {
524+
return MrmState::EMERGENCY_STOP;
525+
}
514526
if (operation_mode_availability_->pull_over) {
515527
if (param_.use_pull_over) {
516528
return MrmState::PULL_OVER;
@@ -527,6 +539,9 @@ autoware_adapi_v1_msgs::msg::MrmState::_behavior_type MrmHandler::getCurrentMrmB
527539
return MrmState::EMERGENCY_STOP;
528540
}
529541
if (mrm_state_.behavior == MrmState::COMFORTABLE_STOP) {
542+
if (is_operation_mode_availability_timeout) {
543+
return MrmState::EMERGENCY_STOP;
544+
}
530545
if (isStopped() && operation_mode_availability_->pull_over) {
531546
if (param_.use_pull_over) {
532547
return MrmState::PULL_OVER;
@@ -543,6 +558,9 @@ autoware_adapi_v1_msgs::msg::MrmState::_behavior_type MrmHandler::getCurrentMrmB
543558
return MrmState::EMERGENCY_STOP;
544559
}
545560
if (mrm_state_.behavior == MrmState::EMERGENCY_STOP) {
561+
if (is_operation_mode_availability_timeout) {
562+
return MrmState::EMERGENCY_STOP;
563+
}
546564
if (isStopped() && operation_mode_availability_->pull_over) {
547565
if (param_.use_pull_over) {
548566
return MrmState::PULL_OVER;
@@ -569,7 +587,8 @@ bool MrmHandler::isStopped()
569587

570588
bool MrmHandler::isEmergency() const
571589
{
572-
return !operation_mode_availability_->autonomous || is_emergency_holding_;
590+
return !operation_mode_availability_->autonomous || is_emergency_holding_ ||
591+
is_operation_mode_availability_timeout;
573592
}
574593

575594
bool MrmHandler::isArrivedAtGoal()

0 commit comments

Comments
 (0)