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

ROS2 one shot timer (python)

asked 2021-03-08 08:51:54 -0500

wipsy gravatar image

Hi, I'm trying to achieve a simple one shot timer function that is restarted each time with a different interval (for some playback function), but do not find any information about how to achieve that. Timer does not take any oneshot flag anymore, and It seems that no sleep function has been implemented yet, in case I'd like to replace my timer by a while loop.

Cannot use other python sleep functions, since I'd like to use the simulated time function (I know, i'm asking a lot).

Is there a proper way to achieve that ?

NB: I've found the create_jump_callback but I'm not exactly sure what it is supposed to be used for.

All the best,

edit retag flag offensive close merge delete

Comments

NB2 : some forum messages mention Duration as well, but the only duration I found had no sleep method either

wipsy gravatar image wipsy  ( 2021-03-08 08:57:39 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-07-29 04:48:55 -0500

masynthetic gravatar image

if you're still looking for a good solution to this using timer.cancel() to stop a timer and timer.reset() is working well for me whereas destroy and create caused an error when creating the same timer after the first destroy

edit flag offensive delete link more
0

answered 2021-03-25 11:26:16 -0500

charlie92 gravatar image

I think one way to do it, is to call self.destroy_timer at the end of your timer callback function, and then if you need again the timer with different rate create it again there

edit flag offensive delete link more

Comments

Thanks a lot for giving me that answer. I think I'll end with that method, or using the timer reset function after changing it duration, but I'm afraid it is not the most accurate way of doing things.

wipsy gravatar image wipsy  ( 2021-03-26 03:57:57 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-03-08 08:51:06 -0500

Seen: 3,082 times

Last updated: Jul 29 '21