From e9f077427fae5adbf85fd7ea4bb54e4e74a1fb43 Mon Sep 17 00:00:00 2001 From: Krzysztof Wojciechowski Date: Sat, 25 May 2024 12:58:16 +0000 Subject: [PATCH 1/5] Fix loading of the camera info parameters on startup --- image_publisher/src/image_publisher.cpp | 33 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/image_publisher/src/image_publisher.cpp b/image_publisher/src/image_publisher.cpp index 1f8068de4..7d7dd8f5c 100644 --- a/image_publisher/src/image_publisher.cpp +++ b/image_publisher/src/image_publisher.cpp @@ -71,36 +71,49 @@ ImagePublisher::ImagePublisher( auto param_change_callback = [this](std::vector parameters) -> rcl_interfaces::msg::SetParametersResult { + RCLCPP_INFO(get_logger(), "param_change_callback"); + + bool call_init = false; + bool call_reconfigure = false; + auto result = rcl_interfaces::msg::SetParametersResult(); result.successful = true; for (auto parameter : parameters) { if (parameter.get_name() == "filename") { filename_ = parameter.as_string(); RCLCPP_INFO(get_logger(), "Reset filename as '%s'", filename_.c_str()); - ImagePublisher::onInit(); - return result; + call_init = true; } else if (parameter.get_name() == "flip_horizontal") { flip_horizontal_ = parameter.as_bool(); RCLCPP_INFO(get_logger(), "Reset flip_horizontal as '%d'", flip_horizontal_); - ImagePublisher::onInit(); - return result; + call_init = true; } else if (parameter.get_name() == "flip_vertical") { flip_vertical_ = parameter.as_bool(); RCLCPP_INFO(get_logger(), "Reset flip_vertical as '%d'", flip_vertical_); - ImagePublisher::onInit(); - return result; + call_init = true; } else if (parameter.get_name() == "frame_id") { frame_id_ = parameter.as_string(); RCLCPP_INFO(get_logger(), "Reset frame_id as '%s'", frame_id_.c_str()); } else if (parameter.get_name() == "publish_rate") { publish_rate_ = parameter.as_double(); RCLCPP_INFO(get_logger(), "Reset publish_rate as '%lf'", publish_rate_); + call_reconfigure = true; } else if (parameter.get_name() == "camera_info_url") { camera_info_url_ = parameter.as_string(); - RCLCPP_INFO(get_logger(), "Reset camera_info_url as '%s'", camera_info_url_.c_str()); + RCLCPP_INFO(get_logger(), "Reset camera_info_rul as '%s'", camera_info_url_.c_str()); + call_reconfigure = true; } } - ImagePublisher::reconfigureCallback(); + // reconfigureCallback() is called within onInit() so there is no need to call it twice + if (call_reconfigure && !call_init) + { + ImagePublisher::reconfigureCallback(); + } + else if (call_init) + { + ImagePublisher::onInit(); + } + return result; }; on_set_parameters_callback_handle_ = this->add_on_set_parameters_callback(param_change_callback); @@ -224,9 +237,7 @@ void ImagePublisher::onInit() camera_info_.p = {1, 0, static_cast(camera_info_.width / 2), 0, 0, 1, static_cast(camera_info_.height / 2), 0, 0, 0, 1, 0}; - timer_ = this->create_wall_timer( - std::chrono::milliseconds(static_cast(1000 / publish_rate_)), - std::bind(&ImagePublisher::doWork, this)); + ImagePublisher::reconfigureCallback(); } } // namespace image_publisher From c5ae2209f1dd8214338bb523bf95936024596b25 Mon Sep 17 00:00:00 2001 From: Krzysztof Wojciechowski Date: Sat, 25 May 2024 13:24:28 +0000 Subject: [PATCH 2/5] Fix linter errors --- image_publisher/src/image_publisher.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/image_publisher/src/image_publisher.cpp b/image_publisher/src/image_publisher.cpp index 7d7dd8f5c..0b8a47f20 100644 --- a/image_publisher/src/image_publisher.cpp +++ b/image_publisher/src/image_publisher.cpp @@ -108,8 +108,7 @@ ImagePublisher::ImagePublisher( if (call_reconfigure && !call_init) { ImagePublisher::reconfigureCallback(); - } - else if (call_init) + } else if (call_init) { ImagePublisher::onInit(); } From c31514d3cdcc068c5933164c777f6ec38d96e8e2 Mon Sep 17 00:00:00 2001 From: Krzysztof Wojciechowski Date: Sat, 25 May 2024 13:32:13 +0000 Subject: [PATCH 3/5] Else bracket in the same line --- image_publisher/src/image_publisher.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/image_publisher/src/image_publisher.cpp b/image_publisher/src/image_publisher.cpp index 0b8a47f20..5839ef46f 100644 --- a/image_publisher/src/image_publisher.cpp +++ b/image_publisher/src/image_publisher.cpp @@ -108,8 +108,7 @@ ImagePublisher::ImagePublisher( if (call_reconfigure && !call_init) { ImagePublisher::reconfigureCallback(); - } else if (call_init) - { + } else if (call_init) { ImagePublisher::onInit(); } From 2d58d0e8e9ddca5f65900e7c6062c09d1f5f46e7 Mon Sep 17 00:00:00 2001 From: Krzysztof Wojciechowski Date: Sat, 25 May 2024 13:56:12 +0000 Subject: [PATCH 4/5] Apply ament_uncrustify --- image_publisher/src/image_publisher.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/image_publisher/src/image_publisher.cpp b/image_publisher/src/image_publisher.cpp index 5839ef46f..0e70750ff 100644 --- a/image_publisher/src/image_publisher.cpp +++ b/image_publisher/src/image_publisher.cpp @@ -105,11 +105,10 @@ ImagePublisher::ImagePublisher( } } // reconfigureCallback() is called within onInit() so there is no need to call it twice - if (call_reconfigure && !call_init) - { - ImagePublisher::reconfigureCallback(); + if (call_reconfigure && !call_init) { + ImagePublisher::reconfigureCallback(); } else if (call_init) { - ImagePublisher::onInit(); + ImagePublisher::onInit(); } return result; From 149ed41afe74944242e124668e9433bc5626ae19 Mon Sep 17 00:00:00 2001 From: Krzysztof Wojciechowski Date: Mon, 27 May 2024 12:05:04 +0000 Subject: [PATCH 5/5] Remove callback log --- image_publisher/src/image_publisher.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/image_publisher/src/image_publisher.cpp b/image_publisher/src/image_publisher.cpp index 0e70750ff..757559ba9 100644 --- a/image_publisher/src/image_publisher.cpp +++ b/image_publisher/src/image_publisher.cpp @@ -71,8 +71,6 @@ ImagePublisher::ImagePublisher( auto param_change_callback = [this](std::vector parameters) -> rcl_interfaces::msg::SetParametersResult { - RCLCPP_INFO(get_logger(), "param_change_callback"); - bool call_init = false; bool call_reconfigure = false;