How to publish a topic on NAO (c++)?
Hello,
It's my first time programming with ROS and NAO and I am trying to create a topic speech for NAO.
When I write this command in the console
rosrun proyects nao_test
the program run, but the NAO doesn't recieve the message that I send. This is my code and I think that something is missing
#include "ros/ros.h"
#include "std_msgs/String.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "nao_test");
ros::NodeHandle n;
ros::Publisher speech_pub = n.advertise<std_msgs::String>("speech", 100);
std_msgs::String str;
str.data = "hello world";
speech_pub.publish(str);
return 0;
}
Thanks
can you try removing the return 0; and putting ros::spin(); instead?
Do not remove the return statement. Just add
ros::spin()
orros::spinOnce()
directly before it.