Robotics StackExchange | Archived questions

ROS2 one shot timer (python)

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 createjumpcallback but I'm not exactly sure what it is supposed to be used for.

All the best,

Asked by wipsy on 2021-03-08 09:51:06 UTC

Comments

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

Asked by wipsy on 2021-03-08 09:57:39 UTC

Answers

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

Asked by charlie92 on 2021-03-25 11:26:16 UTC

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.

Asked by wipsy on 2021-03-26 03:57:57 UTC

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

Asked by masynthetic on 2021-07-29 04:48:55 UTC

Comments