0
$\begingroup$

Rosanswers logo

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?


Originally posted by astur on ROS Answers with karma: 31 on 2015-03-09

Post score: 2

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.

Originally posted by Martin Günther with karma: 11816 on 2015-03-09

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by astur on 2015-03-09:
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

Comment by Martin Günther on 2015-03-09:
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.

Comment by Martin Günther on 2015-03-09:
Re your own message: Sure, as a quick and dirty hack, that's fine. You can still do it properly later.

Comment by Redhwan on 2022-05-12:
@ 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

$\endgroup$

Your Answer

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