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

Very Confusing Float64MultiArray Error [closed]

asked 2022-12-15 05:30:58 -0500

distro gravatar image

updated 2022-12-15 11:48:10 -0500

I get rospy.exceptions.ROSSerializationException: field data[] must be float type in terminal When I rostopic echo a topic recieving Float64MultiArray message. This is a snippet of my python code:

M = Float64MultiArray()
Tab=np.zeros((11521,10))
Values in Tab are manipulated,some are int, some are float.
M.data=(Tab.astype(float)).tolist()
pub.publish(M)

I don't get it, M.data is of type float. is Tab too big?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by distro
close date 2022-12-28 02:44:28.811739

Comments

Did you try creating the array by setting explicitly the type: Tab=np.zeros((11521,10),dtype=np.float64)?

AlessioParmeggiani gravatar image AlessioParmeggiani  ( 2022-12-15 14:56:05 -0500 )edit

@AlessioParmeggiani This still gives the same error

distro gravatar image distro  ( 2022-12-15 20:23:38 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-12-18 10:20:30 -0500

Mike Scheutzow gravatar image

The .tolist() call is not doing what you think it is. If you want to flatten a 2d np.ndarray to a 1d list, use the ravel() method of ndarray.

M.data = Tab.astype(float).ravel()

For a good discussion, see:

https://stackoverflow.com/questions/2...

edit flag offensive delete link more

Comments

@Mike Scheutzow This flattens all elements to a list like [x y z d]. I want to publish this [ [x y],[z d] ]. Maybe it's not possible?

distro gravatar image distro  ( 2022-12-18 13:45:14 -0500 )edit

You can easily adapt it in a few lines though, why is it a problem? Flatten it to 1D list, then create a 2D list with np.reshape

ljaniec gravatar image ljaniec  ( 2022-12-18 15:20:07 -0500 )edit

@ljaniec "facepalm" thanks! I'll try that

distro gravatar image distro  ( 2022-12-18 17:22:41 -0500 )edit

I want to publish this [ [x y],[z d] ]

No, that is not possible with this message. From the message definition: data must be a 1d array of float64.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-12-19 08:21:34 -0500 )edit

Good note, the ROS message definition matters here. This transformation should be in the subscriber callback if wanted.

ljaniec gravatar image ljaniec  ( 2022-12-19 15:31:11 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-12-15 05:30:58 -0500

Seen: 83 times

Last updated: Dec 18 '22