diff --git a/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp b/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp index 4022bdaadebef..4133be8e15a63 100644 --- a/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp +++ b/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp @@ -115,12 +115,11 @@ void MrmHandler::publishHazardCmd() HazardLightsCommand msg; msg.stamp = this->now(); - if (is_emergency_holding_) { - // turn hazard on during emergency holding - msg.command = HazardLightsCommand::ENABLE; - } else if (isEmergency() && param_.turning_hazard_on.emergency) { - // turn hazard on if vehicle is in emergency state and - // turning hazard on if emergency flag is true + if ( + is_emergency_holding_ || // turn hazard on during emergency holding + (isEmergency() && // turn hazard on if emergency flag is true + param_.turning_hazard_on.emergency) // turn hazard on if vehicle is in emergency state + ) { msg.command = HazardLightsCommand::ENABLE; } else { msg.command = HazardLightsCommand::NO_COMMAND; @@ -185,13 +184,17 @@ void MrmHandler::operateMrm() if (current_mrm_behavior == mrm_state_.behavior) { return; } + // First: cancel the previous behavior if (!requestMrmBehavior(mrm_state_.behavior, RequestType::CANCEL)) { handleFailedRequest(); - } else if (requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) { - mrm_state_.behavior = current_mrm_behavior; - } else { + return; + } + // Second: call the current behavior + if (!requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) { handleFailedRequest(); + return; } + mrm_state_.behavior = current_mrm_behavior; return; } if (mrm_state_.state == MrmState::MRM_SUCCEEDED) {