-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rate support #564
Comments
A quick thought: This could be a design challenge for a single threaded javascript implementation based on the rclpy Rate implementation. The classic use-cases for Rate that I'm aware of is an endless loop that uses a Rate to establish a regular frequency for the loop. Following a Rate#sleep() call in this endless loop is a call to spin_once() that fires all active callbacks. At issue is a deadlock that arises when using a Timer in the Rate implementation along with a spin_once() to trigger the Timer's callback. During Rate#sleep() the rate's timer.callback triggers an event which unblocks clients waiting in Rate#sleep() call. Unfortunately a deadlock situation arises as Timer.callback() will not be invoked unless the containing node is already spinning. Thus if the scenario is using spin_once() as in the code below, the Rate's timer is blocked forever waiting for its callback to be invoked by the spin_once(). But spin_once() will never be called.
|
I read the comment for the |
I came across this article which I think can help us to understand the event loop of Node.js deeply. Hope it's also useful for you 😄 |
Thx @minggangw. Assuming that rclnodejs Timer is a key component in the implementation of Rate, there is a need to handle Rate.timer timeout event outside of the current executor model when not spin()'ing. Alternatively, could you envision a parallel instance of rcl running in its own context either in a worker thread or on the main thread specifically for implementing Rate based on a rcl Timer? Maybe this is goofed thinking. A limitation for this approach is my understanding is that rclnodejs is a singleton which would preclude creating a new context for a Rate timer. Thoughts? |
I think the root cause is that Node.js doesn't support multi-thread, e.g. create a sub-thread, semaphore in JS... We have some limitations when using Node.js, I list some:
So, rclnodejs doesn't have a |
I've got a rate solution that I will submit in a PR soon. The design is really simple in that it runs a timer in a separate rcl context. My prototype seems to work properly with no deadlock when accompanied in a loop with spinOnce(). |
Support for creating a fixed rate is also missing in rclnodejs. This looks like it should be very simple to implement.
ros2/rclpy#443
The text was updated successfully, but these errors were encountered: