How to publish a topic on NAO (c++)?

asked 2014-10-14 17:22:11 -0500

Luz_Fernandez gravatar image


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; = "hello world";

        return 0;


edit retag flag offensive close merge delete


can you try removing the return 0; and putting ros::spin(); instead?

Mehdi. gravatar image Mehdi.  ( 2014-10-15 04:53:37 -0500 )edit

Do not remove the return statement. Just add ros::spin() or ros::spinOnce() directly before it.

BennyRe gravatar image BennyRe  ( 2014-10-15 05:36:59 -0500 )edit