ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Publish multiarray Python msg

asked 2015-03-09 03:33:50 -0600

astur gravatar image

When I press a button of my joystick, I save one point [x y z r p y] if I press again I save another point.

Here, I save two points:

[[0.29845908995953135, 0.210860533103541, 1.2190388918130415, -2.746641670660039, -0.8329844111292952, 2.842403460148573], [0.29843708899253263, 0.2220901105357484, 1.2190362691066245, -2.7466506780478976, -0.8329799064852043, 2.842416429478355]]

I want to publish something like this:


int32 points
float32[points][0] vector
float32[points][1] vector
float32[points][2] vector
float32[points][3] vector
float32[points][4] vector
float32[points][5] vector

If I use std_msgs/Float32MultiArray.msg

MultiArrayLayout  layout        
float32[][0]  vector
float32[][1]  vector
float32[][2]  vector
float32[][3]  vector
float32[][4]  vector
float32[][5]  vector

So, Currently only support 1-dimensional array types. How solve this?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-03-09 04:35:53 -0600

You should probably use ROS data types instead of trying to just have a multi-dimensional array of floats. This would make it much easier to directly interpret what's inside each message.

What you really want to do is send a list of poses (= translation + orientation), correct? In that case, your message could look like this:


Header header
geometry_msgs/Pose[] poses

To get the x dimension of the first pose, you would write mymsg.poses[0].position.x.

Two more things:

  • Rotations are encoded as quaternions in ROS, not as Euler angles (roll-pitch-yaw). The Pose message has a orientation field that's a quaternion. Please search other answers here that explain how to convert between quaternions and Euler angles.
  • A pose doesn't mean anything if you don't know at what time and in what reference frame it is specified, that's why you need the header field. It would perhaps be better to remove the header field and instead use PoseStamped messages; that way, you could specify a different time stamp for each pose.
edit flag offensive delete link more


Is there any other solution to use multiarrays?

I don't want to covert quaternions and also get time and reference frame, so if no other solution i will create my own msg


float32 x
float32 y
float32 z
float32 r
float32 p
float32 y


Values[] vector
astur gravatar image astur  ( 2015-03-09 05:23:36 -0600 )edit

MultiArrays are meant for multi-dimensional arrays, usually of a fixed size, like images with RGB channels (640x480x3). Just look at the comments in MultiArrayLayout.msg. In your case, a list of message types (Pose[] or Values[]) is better.

Martin Günther gravatar image Martin Günther  ( 2015-03-09 05:57:49 -0600 )edit

Re your own message: Sure, as a quick and dirty hack, that's fine. You can still do it properly later.

Martin Günther gravatar image Martin Günther  ( 2015-03-09 05:58:53 -0600 )edit

@ Martin Günther, Do those problems have any solution?? First one and Second one.

Please your opinion because I gave up.

I did not find similar to them in your test code

Redhwan gravatar image Redhwan  ( 2022-05-12 03:46:44 -0600 )edit

answered 2017-03-04 09:51:44 -0600

130s gravatar image

updated 2017-03-04 10:02:35 -0600

To add some info for those who reached this thread searching for the usage of *MultiArray message types, they may be useful for rapid prototyping but are not meant for long-term usage and the wiki page of std_msgs now recommends you to create your own message types for complicated data structure (e.g. sensor output).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-03-09 03:33:50 -0600

Seen: 5,096 times

Last updated: Mar 04 '17