ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Publish multiarray Python msg

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:

file.msg

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 close merge delete

Sort by » oldest newest most voted

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:

MyPoseList.msg

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.
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

Values.msg

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

Points.msg

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

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.

( 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.

( 2015-03-09 05:58:53 -0600 )edit

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

I did not find similar to them in your test code

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

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).

more