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

How to publish a two-dimensional array msg with int8 type?

asked 2013-07-13 16:06:11 -0500

Bholms gravatar image

I now have a two-dimensional array of size nxn where n < 10 with int8 or int16 type array elements. I need to publish this array to a topic. I defined my own msg header, a simple int8 type msg such as the following:

int8 num

Can I do something like this: Let's say A is a two-dimensional array A = [1 2; 1 3];

ros::Publisher pub = n.advertise<test1::int8>("Chatter", 1000);
pub.publish(A);

In the callback function of the subscriber:

void chatterCallback(const test1::num& msg)
{
    ROS_INFO(...);
}

Is there any problem with this approach?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2013-07-13 19:13:17 -0500

I am not sure whether the approach u have mentioned will work or not.

Since ROS currently supports declaration of only 1D array in custom message types you can do the following:

array1d.msg

int8[] a;

and then declare another message array2d.msg

array1d[] b;

This will create vector inside a vector and can be used as 2d array.

Hope this helps...

edit flag offensive delete link more

Comments

what do you mean by declaring "array1d.msg"?

Bholms gravatar image Bholms  ( 2013-07-14 18:38:18 -0500 )edit
2

Its just name of the message...

ayush_dewan gravatar image ayush_dewan  ( 2013-07-14 19:15:07 -0500 )edit
felix k gravatar image felix k  ( 2013-07-16 23:28:11 -0500 )edit

Are you sure this idea of vector inside a vector works? I tried implementing this in my case for ROS action and I cannot read the message at the client. The result is an empty message.

nimish gravatar image nimish  ( 2020-12-21 06:42:57 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-07-13 16:06:11 -0500

Seen: 12,466 times

Last updated: Jul 13 '13