Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awesomebytes/a2768843199a10c08dce4213107e94af to your computer and use it in GitHub Desktop.
Save awesomebytes/a2768843199a10c08dce4213107e94af to your computer and use it in GitHub Desktop.
rostopic pub in a launchfile with a complex message (PointCloud2)

How to publish with rostopic pub in a launchfile with a complex message

Using the dictionary syntax: http://wiki.ros.org/ROS/YAMLCommandLine#Command-line_and_messages_.28dictionaries.29 We avoid the problem of requiring double quotes inside of the args field. (I found no way to realiably escape the quotes, for double quote I used " and for single quote I used ' but I still was getting errors).

<launch>
    <!-- Publishing a dummy empty pointcloud (but with x y z fields described to avoid
    errors like: Failed to find match for field 'x'. ) -->
    <node name="dummy_pointcloud_pub" pkg="rostopic" type="rostopic"
    args="pub -s /dummy_pointcloud sensor_msgs/PointCloud2 '{header: 
    {stamp: now, frame_id: base_link},
    height: 0, 
    width: 0, 
    fields: [{name: 'x', offset: 0, datatype: 7, count: 1},
            {name: 'y', offset: 4, datatype: 7, count: 1},
            {name: 'z', offset: 8, datatype: 7, count: 1}], 
    is_bigendian: false,
    point_step: 0, 
    row_step: 0, 
    data: '', 
    is_dense: false}' -r 15" />
</launch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment