From fda1ffb38483f621af36bff690c633047610f49c Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Mon, 30 Oct 2023 16:54:25 +0100 Subject: [PATCH 1/2] added tests without any proper parametes to reproduce the issue --- imu_sensor_broadcaster/CMakeLists.txt | 2 +- .../test/imu_sensor_broadcaster_no_params.yaml | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 imu_sensor_broadcaster/test/imu_sensor_broadcaster_no_params.yaml diff --git a/imu_sensor_broadcaster/CMakeLists.txt b/imu_sensor_broadcaster/CMakeLists.txt index 3b09d9e72e..7b9800f409 100644 --- a/imu_sensor_broadcaster/CMakeLists.txt +++ b/imu_sensor_broadcaster/CMakeLists.txt @@ -54,7 +54,7 @@ if(BUILD_TESTING) add_rostest_with_parameters_gmock(test_load_imu_sensor_broadcaster test/test_load_imu_sensor_broadcaster.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/imu_sensor_broadcaster_params.yaml) + ${CMAKE_CURRENT_SOURCE_DIR}/test/imu_sensor_broadcaster_no_params.yaml) target_include_directories(test_load_imu_sensor_broadcaster PRIVATE include) target_link_libraries(test_load_imu_sensor_broadcaster imu_sensor_broadcaster diff --git a/imu_sensor_broadcaster/test/imu_sensor_broadcaster_no_params.yaml b/imu_sensor_broadcaster/test/imu_sensor_broadcaster_no_params.yaml new file mode 100644 index 0000000000..a60e5fe45e --- /dev/null +++ b/imu_sensor_broadcaster/test/imu_sensor_broadcaster_no_params.yaml @@ -0,0 +1,6 @@ +test_imu_sensor_broadcaster: + ros__parameters: + + test: "hello" + #sensor_name: "imu_sensor" + #frame_id: "imu_sensor_frame" From 30f9593f6a504c522dad1eddbed51a85ee04ee33 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Mon, 30 Oct 2023 18:43:34 +0100 Subject: [PATCH 2/2] separate param listener and parameter intialization --- imu_sensor_broadcaster/src/imu_sensor_broadcaster.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/imu_sensor_broadcaster/src/imu_sensor_broadcaster.cpp b/imu_sensor_broadcaster/src/imu_sensor_broadcaster.cpp index 04a28e5368..0861817b98 100644 --- a/imu_sensor_broadcaster/src/imu_sensor_broadcaster.cpp +++ b/imu_sensor_broadcaster/src/imu_sensor_broadcaster.cpp @@ -27,8 +27,7 @@ controller_interface::CallbackReturn IMUSensorBroadcaster::on_init() { try { - param_listener_ = std::make_shared(get_node()); - params_ = param_listener_->get_params(); + param_listener_ = std::make_shared(get_node(), "", false); } catch (const std::exception & e) { @@ -43,6 +42,10 @@ controller_interface::CallbackReturn IMUSensorBroadcaster::on_init() controller_interface::CallbackReturn IMUSensorBroadcaster::on_configure( const rclcpp_lifecycle::State & /*previous_state*/) { + if (!param_listener_->are_params_initialized()) + { + param_listener_->initialize_parameters(); + } params_ = param_listener_->get_params(); imu_sensor_ = std::make_unique(