ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I create a public class variable called double last_cmd_vel_received
that gets initialized in my constructor to last_command_vel_received = 0
. Then, in the main()
function of my node I read in a ROS parameter called double watchdog_timeout
. For the main while loop I use ros::spinOnce()
and rate.sleep()
(where rate
is another ROS parameter value). In my class I have a public function called zeroVelocities()
that just sets all the actuator outputs to safe values. So, my main while loop looks something like the following:
...
while (nh.ok())
{
if (ros::WallTime::now().toSec() - my_class->last_cmd_vel_received > watchdog_timeout)
{
my_class->zeroVelocities();
}
ros::spinOnce();
rate.sleep();
}
...
In my callback function for the cmd_vel
topic (where the function is part of my class) I set last_cmd_vel_received = ros::WallTime::now().toSec()
. You can play with timeout values however you want, but I have found that 0.3
or so works well with my robots.