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

How do I reset a rospy Timer?

asked 2013-08-08 14:04:13 -0600

Thomas D gravatar image

updated 2014-01-28 17:17:37 -0600

ngrennan gravatar image

How do I reset a rospy Timer? I want to have a Python node that sends out a message like cmd_vel as a step function to test a controller, but I also want to use dynamic reconfigure to be able to change the dt for when the step function should increase. For example, I would like to do one run where my velocities increase by the step amount every 1 second, then do a second run where my velocities increase by the step amount every 5 seconds. I want to use the exact same callback function for modifying the cmd_vel output message but I want that callback function to be invoked at different times. The code I have so far that does not work is

def reset_timers(self):
    try:
        del self.output
    except AttributeError:
        rospy.loginfo("self.output exception caught")
    self.output = rospy.Timer(rospy.Duration(self.output_dt), self.output_callback)

Note that the function reset_timers is called when the Python class is initialized and whenever self.output_dt is modified by dynamic reconfigure.

The behavior I see when using this code is that the timers are additive. Using the previous example, if I change dt from 1 second to 5 seconds, then the timer goes to the callback function every 1 second and every 5 seconds. If I modify self.output_dt often enough then each one of those times is used to invoke the callback and I end up outputting a new message with an increased velocity very rapidly.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-08-10 21:50:14 -0600

BennyRe gravatar image

In http://www.ros.org/wiki/rospy/Overview/Time it says

To stop the Timer from firing, call shutdown().

I did not check if it works, so sorry if I'm wrong.

edit flag offensive delete link more

Comments

That was exactly the right answer and my output looks the way that I want it to now. Thanks @BennyRe! Should this be part of the documentation at: http://docs.ros.org/hydro/api/rospy/h...

Thomas D gravatar image Thomas D  ( 2013-08-12 03:57:17 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-08-08 14:04:13 -0600

Seen: 5,815 times

Last updated: Aug 10 '13