Ask Your Question
0

Publish an length unknown vector message on a topic

asked 2013-02-26 04:30:08 -0500

mateo_7_7 gravatar image

hi, i'm trying to publish a self-defined message composed by 4 vector whose length is unknown. my .cpp code (incomplete) could be the following:

std::vector <int> l,d,r,u;
   data_pub_ = it_.advertise<rd_ctrl::proc_data>("data", 1);
//vectors u,d,l,r computation
data.u=u;
data.d=d;
data.l=l;
data.r=r;
data_pub_.publish(data);

if it works (i don't know...if there are errors please tell me), how can i define the .msg file? thank you very much for your help!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-02-26 05:18:11 -0500

For creating a msg file,create a folder "msg" in ur package directory. In directory create msg file name.msg with following content:

int32[] l

int32[] d

int32[] r

int32[] u

Also make changes in CMakelist.txt for compiling msg files. If u ur not sure of vector size u can just declare a variable of message type and publish it without assigning them a value.

edit flag offensive delete link more

Comments

1

I followed this way to create a message containing an array with unknown size.

But when I assigned some value to the array in the program and publish, it gave "Segmentation fault (core dumped)" when running.

Should I have to declare the size of the array in the program? How can it be done?

shan333 gravatar imageshan333 ( 2013-02-27 21:09:54 -0500 )edit

I followed this way to create a message containing an array with unknown size.

shan333 gravatar imageshan333 ( 2013-02-27 21:09:55 -0500 )edit
1

U need to first allot memory. Do it using msg.a.resize(size of vector) or u can push elements into it using " msg.a.push_back(integer value) .

ayush_dewan gravatar imageayush_dewan ( 2013-02-27 21:57:01 -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-02-26 04:30:08 -0500

Seen: 1,083 times

Last updated: Feb 26 '13