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

Send a 2D array through topics in ROS2

asked 2020-10-27 15:37:39 -0500

jeferrandiz gravatar image

updated 2020-10-27 15:38:08 -0500

What is a proper way of sending 2D arrays through topics? I want to send small ones (4x6 for example) and so far I created an array msg (float64[]) and then use the .reshape function in order to send it as an unidimensional array. However, I do not know if there is a better way.

Thanks in advance for your help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-28 01:15:31 -0500

Yep I think your approach is good enough. You define an one dimensional array in msg and after you receive the msg in your callback you restructure this as a 2D array. One thing I can recommend though is that you add 2 additional fields such as width and height to your msg description, and when you recive your msg you can know the correct dimensions by receiving width and height

A good use case will be to check how sensor_msgs::Image do this by something similar;

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-10-27 15:37:39 -0500

Seen: 1,468 times

Last updated: Oct 28 '20