ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
i would love to solve the same problem, let's try to ask it better. :)
So, i want to publish an array of strings, namely string_list, that at the state of my knowledge (tell me if someone knows other, better solutions) is possible to create through:
std::vector<std::string> string_list
Then, in order to publish it, i created the publisher
ros::Publisher string_list_pub = n.advertise<std::vector<std::string>>("/string_list",1)
i would love to post the error message,bu it is a mess, I am actually facing many problems now while doing it, not totally related to that... but i would love to have your opinion: is it right, at least? Is it better to create a new custom message (with a std::vector<std::string> field ) so that i can build up the publisher like
ros::Publisher string_list_pub = n.advertise<my_pkg::cst_msg>("/string_list",1)
In general, how do you use arrays of strings, and how do you manage publishers/listeners definition?
thank you
2 | Suggested edit |
i would love to solve the same problem, let's try to ask it better. :)
So, i want to publish an array of strings, namely string_list, that at the state of my knowledge (tell me if someone knows other, better solutions) is possible to create through:
std::vector<std::string> string_list
Then, in order to publish it, i created the publisher
ros::Publisher string_list_pub = n.advertise<std::vector<std::string>>("/string_list",1)
i would love to post the error message,bu it is a mess, I am actually facing many problems now while doing it, not totally related to that... but i would love to have your opinion: is it right, at least? Is it better to create a new custom message (with a std::vector<std::string> field ) so that i can build up the publisher like
ros::Publisher string_list_pub = n.advertise<my_pkg::cst_msg>("/string_list",1)
In general, how do you use arrays of strings, and how do you manage publishers/listeners definition?
thank you
UPDATE
I solved in that way:
I first created a new message, adding the string_array.msg file within the dir my_pkg/msg/ , cotaining the field string[]
string[] strings
then, i used it including the generated header (of course after having added the due lines in the CMakeList and having run the catkin_make)
#include <my_pkg/string_array.h>
Note that such a message can be accessed in the standard vector way, just remember to access the proper field
string_array names
names.strings[i] = ...
names.strings.size();
names.strings.push_back();
if(names.strings[i].compare("pippo")==0) ....
finally, create the publisher and subscriber in the common way
ros::Publisher name_list_pub = n.advertise<my_pkg::string_array>("topic",bufferlength);
Ciao
3 | No.3 Revision |
i would love to solve the same problem, let's try to ask it better. :)
So, i want to publish an array of strings, string, namely string_list, that at the state of my knowledge (tell me if someone knows other, better solutions) is possible to create through:i do that:
std::vector<std::string> string_list
Then, in order Since is not possible (someone correct me if i am wrong) to publish it, i created the publisherit like it is, create a custom message, creating a .msg file into then msg directory of your package, like:
ros::Publisher string_list_pub = n.advertise<std::vector<std::string>>("/string_list",1)
std::vector<std::string> strings
i would love and do everything needed for compiling it and generate the headers (have a look to post wiki.ros).
then, include the error message,bu it is a mess, I am actually facing many problems now while doing it, not totally related to that... but i would love to have header in your opinion: is it right, at least? Is it better to .cpp file and create a new custom message (with a std::vector<std::string> field ) so that i can build up the publisher likepublisher
ros::Publisher string_list_pub = n.advertise<my_pkg::cst_msg>("/string_list",1)
In general, how do you use arrays of strings, and how do you manage publishers/listeners definition?
thank you
UPDATE
I solved in that way:
I first created a new message, adding the string_array.msg file within the dir my_pkg/msg/ , cotaining the field string[]
string[] strings
then, i used it including the generated header (of course after having added the due lines in the CMakeList and having run the catkin_make)
#include <my_pkg/string_array.h>
Note that such a message can be accessed in the standard vector way, just remember to To access the proper fieldstring values, if a cst_msg msg
has been defined, do it as msg.strings[i]
string_array names
names.strings[i] = ...
names.strings.size();
names.strings.push_back();
if(names.strings[i].compare("pippo")==0) ....
finally, create the publisher and subscriber in the common way
ros::Publisher name_list_pub = n.advertise<my_pkg::string_array>("topic",bufferlength);
Ciao
4 | No.4 Revision |
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
has been defined, do it as msg.strings[i]cst_msg my_pkg::cst_msg msg
Ciao