From 74fc8644821fdd5b46cbe5662d41cafa6a062243 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Mon, 23 Dec 2024 17:24:59 +0900 Subject: [PATCH 1/5] fix: bugprone-error Signed-off-by: kobayu858 --- .../src/mrm_handler/mrm_handler_core.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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..e95d8fc980a8a 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,12 +184,12 @@ void MrmHandler::operateMrm() if (current_mrm_behavior == mrm_state_.behavior) { return; } - if (!requestMrmBehavior(mrm_state_.behavior, RequestType::CANCEL)) { + if ( + !requestMrmBehavior(mrm_state_.behavior, RequestType::CANCEL) || + !requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) { handleFailedRequest(); - } else if (requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) { - mrm_state_.behavior = current_mrm_behavior; } else { - handleFailedRequest(); + mrm_state_.behavior = current_mrm_behavior; } return; } From cc46392b410d020eb3816ce00128c251ea039329 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Wed, 25 Dec 2024 14:22:41 +0900 Subject: [PATCH 2/5] refactor: if else Signed-off-by: kobayu858 --- system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 e95d8fc980a8a..3d6a52bfd3d86 100644 --- a/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp +++ b/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp @@ -184,12 +184,10 @@ void MrmHandler::operateMrm() if (current_mrm_behavior == mrm_state_.behavior) { return; } - if ( - !requestMrmBehavior(mrm_state_.behavior, RequestType::CANCEL) || - !requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) { - handleFailedRequest(); - } else { + if (requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) { mrm_state_.behavior = current_mrm_behavior; + } else { + handleFailedRequest(); } return; } From f06639ec79d3f2e8a42350d07ffdd8f4b631f191 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Thu, 26 Dec 2024 19:23:20 +0900 Subject: [PATCH 3/5] refactor: if Signed-off-by: kobayu858 --- .../mrm_handler/src/mrm_handler/mrm_handler_core.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 3d6a52bfd3d86..4133be8e15a63 100644 --- a/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp +++ b/system/mrm_handler/src/mrm_handler/mrm_handler_core.cpp @@ -184,11 +184,17 @@ void MrmHandler::operateMrm() if (current_mrm_behavior == mrm_state_.behavior) { return; } - if (requestMrmBehavior(current_mrm_behavior, RequestType::CALL)) { - mrm_state_.behavior = current_mrm_behavior; - } else { + // First: cancel the previous behavior + if (!requestMrmBehavior(mrm_state_.behavior, RequestType::CANCEL)) { + handleFailedRequest(); + 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) { From 5f417a9ba4c40cd24491d85a16c6e2f6252e5fec Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Thu, 26 Dec 2024 19:49:27 +0900 Subject: [PATCH 4/5] fix:bugprone-error Signed-off-by: kobayu858 --- .../src/main.cpp | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/planning/autoware_static_centerline_generator/src/main.cpp b/planning/autoware_static_centerline_generator/src/main.cpp index 811d57c6036ef..71a076ee86fe0 100644 --- a/planning/autoware_static_centerline_generator/src/main.cpp +++ b/planning/autoware_static_centerline_generator/src/main.cpp @@ -14,38 +14,46 @@ #include "static_centerline_generator_node.hpp" +#include #include #include int main(int argc, char * argv[]) { - rclcpp::init(argc, argv); - - // initialize node - rclcpp::NodeOptions node_options; - auto node = - std::make_shared( - node_options); - - // get ros parameter - const auto mode = node->declare_parameter("mode"); - - // process - if (mode == "AUTO") { - node->generate_centerline(); - node->validate(); - node->save_map(); - } else if (mode == "GUI") { - node->generate_centerline(); - } else if (mode == "VMB") { - // Do nothing - } else { - throw std::invalid_argument("The `mode` is invalid."); + try { + rclcpp::init(argc, argv); + + // initialize node + rclcpp::NodeOptions node_options; + auto node = + std::make_shared( + node_options); + + // get ros parameter + const auto mode = node->declare_parameter("mode"); + + // process + if (mode == "AUTO") { + node->generate_centerline(); + node->validate(); + node->save_map(); + } else if (mode == "GUI") { + node->generate_centerline(); + } else if (mode == "VMB") { + // Do nothing + } else { + throw std::invalid_argument("The `mode` is invalid."); + } + + // NOTE: spin node to keep showing debug path/trajectory in rviz with transient local + rclcpp::spin(node); + rclcpp::shutdown(); + } catch (const std::exception & e) { + std::cerr << "Exception in main(): " << e.what() << std::endl; + return {}; + } catch (...) { + std::cerr << "Unknown exception in main()" << std::endl; + return {}; } - - // NOTE: spin node to keep showing debug path/trajectory in rviz with transient local - rclcpp::spin(node); - rclcpp::shutdown(); - return 0; } From 7b599031b0082b66de67dd12282394fbd66f1885 Mon Sep 17 00:00:00 2001 From: kobayu858 Date: Thu, 26 Dec 2024 19:49:49 +0900 Subject: [PATCH 5/5] revert Signed-off-by: kobayu858 --- .../src/main.cpp | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/planning/autoware_static_centerline_generator/src/main.cpp b/planning/autoware_static_centerline_generator/src/main.cpp index 71a076ee86fe0..811d57c6036ef 100644 --- a/planning/autoware_static_centerline_generator/src/main.cpp +++ b/planning/autoware_static_centerline_generator/src/main.cpp @@ -14,46 +14,38 @@ #include "static_centerline_generator_node.hpp" -#include #include #include int main(int argc, char * argv[]) { - try { - rclcpp::init(argc, argv); - - // initialize node - rclcpp::NodeOptions node_options; - auto node = - std::make_shared( - node_options); - - // get ros parameter - const auto mode = node->declare_parameter("mode"); - - // process - if (mode == "AUTO") { - node->generate_centerline(); - node->validate(); - node->save_map(); - } else if (mode == "GUI") { - node->generate_centerline(); - } else if (mode == "VMB") { - // Do nothing - } else { - throw std::invalid_argument("The `mode` is invalid."); - } - - // NOTE: spin node to keep showing debug path/trajectory in rviz with transient local - rclcpp::spin(node); - rclcpp::shutdown(); - } catch (const std::exception & e) { - std::cerr << "Exception in main(): " << e.what() << std::endl; - return {}; - } catch (...) { - std::cerr << "Unknown exception in main()" << std::endl; - return {}; + rclcpp::init(argc, argv); + + // initialize node + rclcpp::NodeOptions node_options; + auto node = + std::make_shared( + node_options); + + // get ros parameter + const auto mode = node->declare_parameter("mode"); + + // process + if (mode == "AUTO") { + node->generate_centerline(); + node->validate(); + node->save_map(); + } else if (mode == "GUI") { + node->generate_centerline(); + } else if (mode == "VMB") { + // Do nothing + } else { + throw std::invalid_argument("The `mode` is invalid."); } + + // NOTE: spin node to keep showing debug path/trajectory in rviz with transient local + rclcpp::spin(node); + rclcpp::shutdown(); + return 0; }