Note: This tutorial assumes that you have completed the previous tutorials: Writing a Simple Image Publisher, Writing a Simple Image Subscriber.

Running the Simple Image Publisher and Subscriber with Different Transports

Description: This tutorial discusses running the simple image publisher and subscriber using multiple transports.

Tutorial Level: BEGINNER

Next Tutorial: Managing Transport Plugins

Running the Publisher

Make sure that a roscore is up and running:

$ roscore

In a previous tutorial we made a publisher node called "my_publisher"; now run the node with an image file as the command-line argument:

$ rosrun learning_image_transport my_publisher path/to/some/image.jpg

To check that your node is running properly, list the topics being published:

$ rostopic list -v

Look for /camera/image in the output, which should look something like:

Published topics:
 * /rosout [roslib/Log] 1 publisher
 * /camera/image [sensor_msgs/Image] 1 publisher
 * /rosout_agg [roslib/Log] 1 publisher

Subscribed topics:
 * /time [unknown type] 2 subscribers
 * /rosout [roslib/Log] 1 subscriber

If you have non-default transport plugins built, you may see additional published topics in the /camera/image/ namespace.

Running the Subscriber

In the last tutorial, we made a subscriber node called "my_subscriber"; now run it:

$ rosrun learning_image_transport my_subscriber

You should see a window pop up with the image you gave to the publisher.

Let's look at the node graph:

$ rxgraph

transport_graph.png

Changing the Transport Used

Currently our nodes are communicating raw sensor_msgs/Image messages, so we are not gaining anything over using ros::Publisher and ros::Subscriber. Let's change that by introducing a new transport:

$ rosmake compressed_image_transport

The compressed_image_transport package provides plugins for the "compressed" transport, which sends images over the wire in either JPEG- or PNG-compressed form. Notice that compressed_image_transport is not a dependency of your package; image_transport will automatically discover all transport plugins built in your ROS system.

Shut down your publisher node and restart it. If you list the published topics again, you should see a new one:

 * /camera/image/compressed [sensor_msgs/CompressedImage] 1 publisher

Now let's start up a new subscriber, this one using compressed transport. The key is that image_transport subscribers check the parameter ~image_transport for the name of a transport to use in place of "raw". Let's set this parameter and start a subscriber node with name "compressed_listener":

$ rosparam set /compressed_listener/image_transport compressed
$ rosrun learning_image_transport my_subscriber __name:=compressed_listener

You should see an identical image window pop up. Let's check the node graph again:

$ rxgraph

transport_graph_with_compressed.png

compressed_listener is listening to a separate topic carrying JPEG-compressed versions of the same images published on /camera/image.

Note that if you just want the compressed image, you can change the parameter globally in-line:

$ rosrun learning_image_transport my_subscriber _image_transport:=compressed

Changing Transport-Specific Behavior

For a particular transport, we may want to tweak settings such as compression level, bit rate, etc. Transport plugins can expose such settings through dynamic_reconfigure. For example, /camera/image/compressed allows you to change the compression format and quality on the fly; see the package documentation for full details.

For now let's adjust the JPEG quality. By default, "compressed" transport uses JPEG compression at 80% quality; let's change it to 15%:

$ rosrun dynamic_reconfigure reconfigure_gui

Now pick /camera/image/compressed in the drop-down menu and move the jpeg_quality slider down to 15%. Do you see the compression artifacts in your second view window?

Dynamic Reconfigure has updated the dynamically reconfigurable parameter /camera/image/compressed/jpeg_quality. You can verify this by running:

$ rosparam get /camera/image/compressed/jpeg_quality

This should display 15.

Wiki: image_transport/Tutorials/ExaminingImagePublisherSubscriber (last edited 2012-01-11 01:31:58 by kanderson)