From 77fa02f7023b736bca55eb2f2c97ceb4cd7a45da Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Fri, 2 Feb 2024 21:43:35 -0500 Subject: [PATCH] support compressed transport, update docs (#13) * galactic is EOL, update to Iron in README * parameter name is image_transport, no underscore * update subscriber example to actually support image_transport --- README.md | 12 ++++++------ src/my_subscriber.cpp | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 931d142..572fd45 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ Install needed dependencies: ``` $ cd ~/image_transport_tutorials_ws/ -$ source /opt/ros/galactic/setup.bash -$ rosdep install -i --from-path src --rosdistro galactic -y +$ source /opt/ros/iron/setup.bash +$ rosdep install -i --from-path src --rosdistro iron -y $ colcon build ``` -Make sure to include the correct setup file (in the above example it is for Galactic on Ubuntu and for bash). +Make sure to include the correct setup file (in the above example it is for Iron on Ubuntu and for bash). ## Writing a Simple Image Publisher (C++) Description: This tutorial shows how to create a publisher node that will continually publish an image. @@ -239,13 +239,13 @@ Notice that `compressed_image_transport` is not a dependency of your package; `i The easiest way to add the "compressed" transport is to install the package: ``` -$ sudo apt-get install ros-galactic-compressed-image-transport +$ sudo apt-get install ros-iron-compressed-image-transport ``` Or install all the transport plugins at once: ``` -$ sudo apt-get install ros-galactic-image-transport-plugins +$ sudo apt-get install ros-iron-image-transport-plugins ``` But you can also build from source. @@ -256,7 +256,7 @@ The key is that `image_transport` subscribers check the parameter `_image_transp Let's set this parameter and start a subscriber node with name "compressed_listener": ``` -$ ros2 run image_transport_tutorials my_subscriber --ros-args --remap __name:=compressed_listener -p _image_transport:=compressed +$ ros2 run image_transport_tutorials my_subscriber --ros-args --remap __name:=compressed_listener -p image_transport:=compressed ``` You should see an identical image window pop up. diff --git a/src/my_subscriber.cpp b/src/my_subscriber.cpp index 9d320d5..858f856 100644 --- a/src/my_subscriber.cpp +++ b/src/my_subscriber.cpp @@ -35,10 +35,13 @@ int main(int argc, char ** argv) rclcpp::init(argc, argv); rclcpp::NodeOptions options; rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("image_listener", options); + // TransportHints does not actually declare the parameter + node->declare_parameter("image_transport", "raw"); cv::namedWindow("view"); cv::startWindowThread(); image_transport::ImageTransport it(node); - image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback); + image_transport::TransportHints hints(node.get()); + image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback, &hints); rclcpp::spin(node); cv::destroyWindow("view");