You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement Clock::sleep_for and Clock::sleep_until #1730
I'm planning to work on this right now, wanted to open this issue to track work and hold discussion.
I think it makes sense to mostly implement in C++ so that we can take advantage of std::condition_variable. To implement in rcl in pure C this would require using pthread API which wouldn't port to Windows easily. Downside to this is that we'll need to implement in rclpy separately.
I'm having some trouble using this feature in practice given the API that we defined.
The can sleep forever part is the troublesome bit. If there is no /clock signal, or something else is misconfigured, there's no way that I know of to get back the program execution without shutting down the entire context. I wonder if it would be a better API to return a Future, or have a real_time_timeout optional parameter, such that there is a guaranteed return from the function, so that a caller can still do processing, while knowing that timing is not coming through. What do you think @sloretz ?
The can sleep forever part is the troublesome bit. If there is no /clock signal, or something else is misconfigured, there's no way that I know of to get back the program execution without shutting down the entire context. I wonder if it would be a better API to return a Future, or have a real_time_timeout optional parameter, such that there is a guaranteed return from the function, so that a caller can still do processing, while knowing that timing is not coming through.
That's interesting. I would have thought sleepimg forever is a desirable feature, like when running nodes against slower-than-real-time simulations. What you describe kind of sounds like "sleep until either of these times are reached on these two clocks". Maybe that use case would be better served with two timers, one using each clock, whose callbacks set a single condition variable?
Alternatively - instead of "sleep until either of these times are reached" - perhaps exposing a "cancel/interrupt" of some sort would work. Not sure if we would want to expose the condition_variable that is used in sleeping, but a notify call to that could be used to interrupt sleep (as long as it's not in a while loop).
I think I have a reasonable way to move forward with the behavior I want to implement in rosbag2, but it's still worth possibly thinking about an interrupt mechanism here.
Activity
[-]Clock `sleep_for` and `sleep_until` functionality[/-][+]Implement `Clock::sleep_for` and `Clock::sleep_until`[/+]emersonknapp commentedon Jul 27, 2021
I'm planning to work on this right now, wanted to open this issue to track work and hold discussion.
I think it makes sense to mostly implement in C++ so that we can take advantage of
std::condition_variable. To implement inrclin pure C this would require usingpthreadAPI which wouldn't port to Windows easily. Downside to this is that we'll need to implement inrclpyseparately.emersonknapp commentedon Jul 29, 2021
Wow, I forgot that I opened #1730 back in March. Related/identical issue
clalancette commentedon Aug 19, 2021
(assigned to Emerson since he is actively working on it)
emersonknapp commentedon Dec 11, 2021
I'm having some trouble using this feature in practice given the API that we defined.
The
can sleep foreverpart is the troublesome bit. If there is no/clocksignal, or something else is misconfigured, there's no way that I know of to get back the program execution without shutting down the entire context. I wonder if it would be a better API to return a Future, or have areal_time_timeoutoptional parameter, such that there is a guaranteed return from the function, so that a caller can still do processing, while knowing that timing is not coming through. What do you think @sloretz ?sloretz commentedon Dec 11, 2021
That's interesting. I would have thought sleepimg forever is a desirable feature, like when running nodes against slower-than-real-time simulations. What you describe kind of sounds like "sleep until either of these times are reached on these two clocks". Maybe that use case would be better served with two timers, one using each clock, whose callbacks set a single condition variable?
emersonknapp commentedon Dec 21, 2021
Alternatively - instead of "sleep until either of these times are reached" - perhaps exposing a "cancel/interrupt" of some sort would work. Not sure if we would want to expose the
condition_variablethat is used in sleeping, but anotifycall to that could be used to interrupt sleep (as long as it's not in a while loop).I think I have a reasonable way to move forward with the behavior I want to implement in rosbag2, but it's still worth possibly thinking about an interrupt mechanism here.