Ask Your Question
-1

How to publish an array of strings?

asked 2016-12-04 00:40:03 -0600

mhharshal gravatar image

operation=['addition','subtraction','multiplication','division']

I want to publish each element in the array from one node and subscribe those elements by other node. What should be the proper python syntax for publishing and subscribing ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-12-04 04:19:48 -0600

NEngelhard gravatar image

Read The Friendly Manual: Publishers and Subscribers

edit flag offensive delete link more

Comments

I was able to publish simple data such as integers, but when I tried for arrays, ros was giving some error. How can we publish it properly?

mhharshal gravatar imagemhharshal ( 2016-12-04 04:30:14 -0600 )edit
2

" ros was giving some error. " It would be easier if you'd tell exactly(!) which error is returned. And do you want to publish an array or "each element in the array"?

NEngelhard gravatar imageNEngelhard ( 2016-12-04 04:32:24 -0600 )edit
-2

answered 2018-02-25 13:32:36 -0600

fracchie gravatar image

updated 2018-02-27 13:22:12 -0600

to publish an array of string, namely string_list, i do that:

std::vector<std::string> string_list

Since is not possible (someone correct me if i am wrong) to publish it like it is, create a custom message, creating a .msg file into then msg directory of your package, like:

std::vector<std::string> strings

and do everything needed for compiling it and generate the headers (have a look to wiki.ros). then, include the header in your .cpp file and create the publisher

 ros::Publisher string_list_pub = n.advertise<my_pkg::cst_msg>("/string_list",1)

To access the string values, if a my_pkg::cst_msg msg has been defined, do it as msg.strings[i]

Ciao

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-12-04 00:40:03 -0600

Seen: 1,509 times

Last updated: Feb 27 '18