Skip to content

Add support for Clock sleep_for/sleep_until #604

@balthasarschuess

Description

@balthasarschuess

I think we should add support for Clock.sleep_for and Clock.sleep_until.
This should work well in conjunction with use_sim_time:=true and I see an opportunity to set rclrs apart.

Right now in any ros client lib sleeping on the ros clock in a single threaded executor callback deadlocks if use_sim_time:=true.
As the clock subscription is spun by the same executor as the clock subscription.
For me this is a huge pitfall as the code behaves very differently between simulation and system time mode, this drawback is effectively an implementation detail of the library, and it would be very nice if this could be avoided for rclrs users.

For async subscriptions, we could provide async_sleep_for and async_sleep_until, that would not block and therefore progress the clock and wake up processing in time. However, in cases where the synchronization through the single threaded executor is desired, the user has to add additional synchronization logic that needs to be async aware to not run into the same problem, but more complex.
Another option would be to use queues and an additional thread.

I think while using use_sim_time, we should subscribe to the /clock topic with a new node, that is spun by an additional executor.
However, adding one additional node per (node/process) incurs additional topic advertisement costs that scale in quadratic fashion due to the decentralized design of ros2.

Can anyone think of a better solution? Maybe we can make Clock.sleep_for spin the /clock subscription in the background somehow?

As a first step I'd be already happy if async sleep_for would be supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions