Size: 991
Comment:
|
Size: 4155
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 7: | Line 7: |
## note.0= [[image_transport/Tutorials/Pu]] | ## note.0= [[image_transport/Tutorials/PublishingImages|Writing a Simple Image Publisher]] ## note.1= [[image_transport/Tutorials/SubscribingToImages|Writing a Simple Image Subscriber]] |
Line 11: | Line 12: |
## description = | ## description = This tutorial examines running the simple image publisher and subscriber using multiple transports. |
Line 15: | Line 16: |
## next.0.link= | ## next.0.link= [[image_transport/Tutorials/ManagingPlugins|Managing Transport Plugins]] |
Line 18: | Line 19: |
## level= (BeginnerCategory, IntermediateCategory, AdvancedCategory) | ## level= BeginnerCategory |
Line 26: | Line 27: |
=== Running the Publisher === | |
Line 27: | Line 29: |
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 }}} {{attachment:transport_graph.png}} === Changing the Transport Used === Currently our nodes are communicating raw <<MsgLink(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 }}} {{attachment: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`. === Changing Transport-Specific Behavior === |
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
Contents
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
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
compressed_listener is listening to a separate topic carrying JPEG-compressed versions of the same images published on /camera/image.