0
$\begingroup$

Rosanswers logo

Can anybody give me an example of geometry_msgs/PoseArray message using rostopic pub? I keep on getting errors when i try and interpret the syntax from the ROS documentation, a solid example would be really helpful.

Thanks!


Originally posted by Ben12345 on ROS Answers with karma: 98 on 2017-01-09

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Here's an example with the Bash multiline syntax:

rostopic pub /test geometry_msgs/PoseArray "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
poses:
- position:
    x: 1.0
    y: 2.0
    z: 3.0
  orientation:
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0
- position:
    x: 4.0
    y: 5.0
    z: 6.0
  orientation:
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0"

Here's an example using the YAML command line dictionary syntax:

rostopic pub /test geometry_msgs/PoseArray "{header: auto, poses: [{position: [1,2,3]}, {position: [4,5,6]}]}"\

You can also use the -f option to read the message contents from a YAML file. For example, imagine tmp.yaml had the following contents:

poses:
- position:
    x: 1.0
    y: 2.0
    z: 3.0
  orientation:
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0
- position:
    x: 4.0
    y: 5.0
    z: 6.0
  orientation:
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0

This could be published using

rostopic pub /test geometry_msgs/PoseArray -f tmp.yaml

Note that when reading from a file if you would like to publish the message continuously at a set rate, you need to have multiple messages in the file separated by --- lines.

Personally when the messages get this complicated, I generally just write a short Python script to publish the desired message at whatever rate I want to avoid having to mess with this complicated syntax at the command line.


Originally posted by jarvisschultz with karma: 9031 on 2017-01-09

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.