From 0b34026df03cd001e494c70c62b88a553c61dbd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Vrba?= Date: Mon, 9 Sep 2024 12:25:30 +0200 Subject: [PATCH] minor updates to parameter loading --- include/fog_lib/params.h | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/include/fog_lib/params.h b/include/fog_lib/params.h index cd3b3ec..34f7ab6 100644 --- a/include/fog_lib/params.h +++ b/include/fog_lib/params.h @@ -25,6 +25,11 @@ namespace fog_lib RCLCPP_ERROR_STREAM(node.get_logger(), "Could not load param '" << param_name << "': " << e.what()); return false; } + catch (const rclcpp::exceptions::UninitializedStaticallyTypedParameterException& e) + { + RCLCPP_ERROR_STREAM(node.get_logger(), "Could not load param '" << param_name << "': " << e.what()); + return false; + } return true; } @@ -48,30 +53,21 @@ namespace fog_lib RCLCPP_ERROR_STREAM(node.get_logger(), "Could not load param '" << param_name << "': " << e.what()); return false; } + catch (const rclcpp::exceptions::UninitializedStaticallyTypedParameterException& e) + { + RCLCPP_ERROR_STREAM(node.get_logger(), "Could not load param '" << param_name << "': " << e.what()); + return false; + } return true; } bool parse_param(const std::string& param_name, rclcpp::Duration& param_dest, rclcpp::Node& node) { - try - { - using T = double; -#ifdef ROS_FOXY - node.declare_parameter(param_name); // for Foxy -#else - node.declare_parameter(param_name); // for Galactic and newer -#endif - T tmp; - node.get_parameter(param_name, tmp); + double tmp; + const bool ok_out = parse_param(param_name, tmp, node); + if (ok_out) param_dest = rclcpp::Duration::from_seconds(tmp); - RCLCPP_INFO_STREAM(node.get_logger(), "Loaded '" << param_name << "' = " << tmp << "s"); - } - catch (const rclcpp::ParameterTypeException& e) - { - RCLCPP_ERROR_STREAM(node.get_logger(), "Could not load param '" << param_name << "': " << e.what()); - return false; - } - return true; + return ok_out; } template