Ask Your Question
2

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:

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

2 Answers

Sort by » oldest newest most voted
0

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:

MyPoseList.msg

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

Comments

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
astur gravatar imageastur ( 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.

Martin Günther gravatar imageMartin 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 imageMartin Günther ( 2015-03-09 05:58:53 -0600 )edit
0

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

Stats

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

Seen: 3,852 times

Last updated: Mar 04 '17