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

How to publish an array of strings?

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

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 -0500

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 image mhharshal  ( 2016-12-04 04:30:14 -0500 )edit
3

" 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 image NEngelhard  ( 2016-12-04 04:32:24 -0500 )edit
-2

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

fracchie gravatar image

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

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

Question Tools

2 followers

Stats

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

Seen: 4,304 times

Last updated: Feb 27 '18