ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

how to rostopic pub msg with array members

asked 2017-08-28 01:16:31 -0500

peigong gravatar image

When i want to publish msg like this:

Header header
  uint32 seq
  time stamp
  string frame_id
Point point
  float64 x
  float64 y
  float64 z

i can use the following cmd:

rostopic pub pt geometry_msgs/PointStamped '{stamp: now, frame_id: base_link}' '[1.0, 2.0, 3.0]'

or rostopic pub pt geometry_msgs/PointStamped '{stamp: now, frame_id: base_link}' '[1.0, 2.0, 3.0]'

what command should i use to publish msgs with array members like:

std_msgs/Header header
string[] joint_names
trajectory_msgs/MultiDOFJointTrajectoryPoint[] points 
       geometry_msgs/Transform[] transforms
       geometry_msgs/Twist[] velocities
       geometry_msgs/Twist[] accelerations
       duration time_from_start
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-08-28 02:22:06 -0500

rbbg gravatar image

You can do it just as you filled the Point. For instance, if you want to fill the joint_names of a MultiDofJointTrajectory:

rostopic pub mdjt trajectory_msgs/MultiDOFJointTrajectory  '{joint_names:[name1, name2]}'

have a look at this answer. It is a bit clunky (especially when the vectors you are trying to fill aren't simple types), so it's probably useful to play around a bit in a text editor. For a slightly more intricate example:

rostopic pub mdjt trajectory_msgs/MultiDOFJointTrajectory  '{joint_names:[name1, name2, name3], points:[{time_from_start: {secs: 1, nsecs: 100}}, {time_from_start: {secs: 100, nsecs: 300}}]}'

Good luck.

edit flag offensive delete link more


Thank you for your kind reply.

it works.

peigong gravatar image peigong  ( 2017-08-28 04:00:12 -0500 )edit

Question Tools



Asked: 2017-08-28 01:16:31 -0500

Seen: 5,107 times

Last updated: Aug 28 '17