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

Revision history [back]

click to hide/show revision 1
initial version
string sent = "Hello robot";
ros::Publisher cmd_vel_pub("try", sent);

That is not a valid way to instantiate a rosserial ros::Publisher instance. wiki/rosserial/Overview/Publishers and Subscribers - Publishing to a topic includes an example:

std_msgs::String str_msg;
ros::Publisher pub("foo", &str_msg);

The second argument to the ctor is a std_msgs::String instance (ie: a rosserial message class), not a regular (std::)string. That is why you get the compiler error.


From the way you've structured your code, I also get the impression that you are thinking of a Publisher as a "high-level" TCP/IP socket: your string sent contains your payload, and you're trying to get cmd_vel_pub to send it to somewhere for you. That is not how this is supposed to work.

Typical flow of control in a regular ROS node (so not in rosserial) is as follows: init the framework, create a NodeHandle, advertise a Publisher (by specifying it's message type and topic name), init a message class instance and then start your processing loop (which is probably a while-loop with one or more Publisher::publish(..) calls and a ros::spinOnce() and ros::Rate::sleep()). For rosserial this is similar, but not identical.

So in your case, you'd init everything (framework, nodehandle, publisher), then enter some while loop and start sending std_msgs::String instances (which you can set to "Hello robot").

If you're really just starting out, it would probably be a good idea to pick up a book or two (wiki/Books) and follow the basic tutorials. The structure of and control flow in a rosserial program will probably make a lot more sense then.

string sent = "Hello robot";
ros::Publisher cmd_vel_pub("try", sent);

That is not a valid way to instantiate a rosserial ros::Publisher instance. wiki/rosserial/Overview/Publishers and Subscribers - Publishing to a topic includes an example:

std_msgs::String str_msg;
ros::Publisher pub("foo", &str_msg);

The second argument to the ctor is a std_msgs::String instance (ie: a rosserial message class), not a regular (std::)string. That is why you get the compiler error.


From the way you've structured your code, I also get the impression that you are thinking of a Publisher as a "high-level" TCP/IP socket: your string sent contains your payload, and you're trying to get cmd_vel_pub to send it to somewhere for you. That is not how this is supposed to work.

Typical flow of control in a regular ROS node (so not in rosserial) is as follows: init the framework, create a NodeHandle, advertise a Publisher (by specifying it's message type and topic name), init a message class instance and then start your processing loop (which is probably a while-loop with one or more Publisher::publish(..) calls and a ros::spinOnce() and ros::Rate::sleep()). For rosserial this is similar, but not identical.

So in your case, you'd init everything (framework, nodehandle, publisher), then enter some while loop and start sending std_msgs::String instances (which you can set to "Hello robot").

If you're really just starting out, it would probably be a good idea to pick up a book or two (wiki/Books) : "A Gentle Introduction to ROS" is free) and follow the basic tutorials. The structure of and control flow in a rosserial program will probably make a lot more sense then.

string sent = "Hello robot";
ros::Publisher cmd_vel_pub("try", sent);

That is not a valid way to instantiate a rosserial ros::Publisher instance. wiki/rosserial/Overview/Publishers and Subscribers - Publishing to a topic includes an example:

std_msgs::String str_msg;
ros::Publisher pub("foo", &str_msg);

The second argument to the ctor is a std_msgs::String instance (ie: a rosserial message class), not a regular (std::)string. That is why you get the compiler error.


From the way you've structured your code, I also get the impression that you are thinking of a Publisher as a "high-level" TCP/IP socket: your string sent contains your payload, and you're trying to get cmd_vel_pub to send it to somewhere for you. That is not how this is supposed to work.

Typical flow of control in a regular ROS node (so not in rosserial) is as follows: init the framework, create a NodeHandle, advertise a Publisher (by specifying it's message type and topic name), init a message class instance and then start your processing loop (which is probably a while-loop with one or more Publisher::publish(..) calls and a ros::spinOnce() and ros::Rate::sleep()). For rosserial this is similar, but not identical.

So in your case, you'd init everything (framework, nodehandle, publisher), then enter some while loop and start sending std_msgs::String instances (which you can set to "Hello robot").

If you're really just starting out, it would probably be a good idea to pick up a book or two (wiki/Books: "A Gentle Introduction to ROS" is free) and follow the basic tutorials. The structure of and control flow in a rosserial program will probably make a lot more sense then.


Edit:

So I have modified my code in this way: [..] But it has not builded yet. Now I have errors related to Windows socket or stuff like that. [..] I have included all the libraries I need to.

Well, what you post is a linker error, so it would seem that something is missing.

Have you followed wiki/rosserial_windows/Tutorials/Hello World from Windows? WindowsSocket is a class distributed with rosserial_windows, so something is not configured correctly.