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

I believe there is a race condition between setting up the publisher and attempting to publish the message.

For example if you add a 1 second delay between advertising the topic and publishing you should see a successfully published message:

usleep(1000000);

You could also latch the topic (meaning it will always publish the last message sent to new subscribers), but maybe not the best idea for velocity commands. Add true as the last parameter:

ros::Publisher Velocity_pub = n.advertise<geometry_msgs::Twist>("/RosAria/cmd_vel", 1000, true);

But, if you are going to adaptively change the velocity based on the position anyways, you might want to have a loop somewhere inside you're main function that calls ros::spinOnce() instead of the blocking ros::spin(). See the roscpp Tutorial.

I believe there is a race condition between setting up the publisher and attempting to publish the message.

For example if you add a 1 second delay between advertising the topic and publishing you should see a successfully published message:

usleep(1000000);

You could also latch the topic (meaning it will always publish the last message sent to new subscribers), but maybe not the best idea for velocity commands. Add true as the last parameter:

ros::Publisher Velocity_pub = n.advertise<geometry_msgs::Twist>("/RosAria/cmd_vel", 1000, true);

But, if you are going to adaptively change the velocity based on the position anyways, you might want to have a loop somewhere inside you're main function that calls ros::spinOnce() instead of the blocking ros::spin(). See the roscpp Tutorial.[roscpp Tutorial](http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber(c%2B%2B).