Ask Your Question
3

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
4

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 imageBholms ( 2013-07-14 18:38:18 -0500 )edit
2

Its just name of the message...

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

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

Seen: 5,946 times

Last updated: Jul 13 '13