From 6f338712e8f9706c190d349daece4894e9d385e2 Mon Sep 17 00:00:00 2001 From: RBT22 <43723477+RBT22@users.noreply.github.com> Date: Fri, 23 Jun 2023 10:12:49 +0200 Subject: [PATCH] correct error message (#3631) (#5) * correct error message * clean up * cleanup * remove header Co-authored-by: Joshua Wallace --- .../bt_action_server_impl.hpp | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp b/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp index 90ac293228c..72db2449bd3 100644 --- a/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp +++ b/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp @@ -68,16 +68,22 @@ BtActionServer::BtActionServer( }; if (!node->has_parameter("error_code_names")) { - std::string error_codes_str; - for (const auto & error_code : error_code_names) { - error_codes_str += error_code + "\n"; + const rclcpp::ParameterValue value = node->declare_parameter( + "error_code_names", + rclcpp::PARAMETER_STRING_ARRAY); + if (value.get_type() == rclcpp::PARAMETER_NOT_SET) { + std::string error_codes_str; + for (const auto & error_code : error_code_names) { + error_codes_str += "\n" + error_code; + } + RCLCPP_WARN_STREAM( + logger_, "Error_code parameters were not set. Using default values of: " + << error_codes_str + "\n" + << "Make sure these match your BT and there are not other sources of error codes you" + "reported to your application"); + rclcpp::Parameter error_code_names_param("error_code_names", error_code_names); + node->set_parameter(error_code_names_param); } - RCLCPP_WARN_STREAM( - logger_, "Error_code parameters were not set. Using default values of: " - << error_codes_str - << "Make sure these match your BT and there are not other sources of error codes you want " - "reported to your application"); - node->declare_parameter("error_code_names", error_code_names); } }