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

Sometimes when I publish to cmd_vel node got stuck

asked 2015-09-27 19:01:41 -0500

erivera1802 gravatar image

Hi! I am working with the ardrone_autonomy package for the Ar.Drone. I have already a code for the control signal and it works great, except for the part when I try to publish the commands in the cmd_vel topic. Normally it publish fast, which is what i need, but sometimes it kinda freeze, for 1 or 2 seconds, and goes back to publishing normally. I dont know why is that happening, und is very important for me to fix that delay, because in that 2 seconds the Drone could crash. Here is the relevant part of the code: Inside the main:

ros::init(argc, argv, "tracker");
ros::NodeHandle nh;
ros::Rate loop_rate(50);

Inside the callback:

ros::NodeHandle neu;
    ros::Publisher pub_empty_land;
    ros::Publisher pub_point=neu.advertise<geometry_msgs::Point>("color_position",1);
    ros::Publisher pub_control=neu.advertise<geometry_msgs::Twist>("/cmd_vel", 10);<float>(2);


I would appreciate your help Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-27 19:30:16 -0500

ahendrix gravatar image

Publishers should be persistent; you shouldn't be creating a new publisher on each callback. This is because publisher setup can take a few seconds under poor conditions, and this can cause messages to be dropped before the publisher is completely set up.

Instead, you should create your publisher in main(), and the callback should only be interpreting the data and using the existing publisher to publish a new message.

You should NEVER call ros::spinOnce() from inside a callback; spinOnce is the call which processes message callbacks in the first place. Most ROS nodes call ros::spin() or ros::spinOnce() from main.

If you're trying for consistent performance, calling cv::waitKey from within your callback is also a bad idea; you don't want to do anything within your callback which could create a significant delay.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-09-27 19:01:41 -0500

Seen: 646 times

Last updated: Sep 27 '15