-
Notifications
You must be signed in to change notification settings - Fork 83
Add ClockEvent support #1354
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
base: develop
Are you sure you want to change the base?
Add ClockEvent support #1354
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds ClockEvent support to rclnodejs, providing a synchronization mechanism for waiting until specific clock times are reached. This is useful for time-based coordination in ROS applications.
- Implements ClockEvent class with wait methods for steady, system, and ROS clocks
- Adds TypeScript type definitions for the new ClockEvent API
- Includes JavaScript and C++ implementation with async worker support
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| types/clock_event.d.ts | Adds TypeScript definitions for the ClockEvent class with wait methods and set/clear operations |
| types/index.d.ts | Adds reference to the new clock_event type definitions |
| src/clock_event.hpp | Defines the C++ ClockEvent class interface with template-based wait methods |
| src/clock_event.cpp | Implements ClockEvent functionality with async workers and native bindings |
| src/addon.cpp | Registers the ClockEvent bindings in the native module |
| lib/clock_event.js | JavaScript wrapper class that provides the public API for ClockEvent |
| index.js | Exports the ClockEvent class in the main module |
| binding.gyp | Adds clock_event.cpp to the build configuration |
| test/test-clock-event.js | Adds test cases for ClockEvent functionality |
| test/types/index.test-d.ts | Adds TypeScript type tests for ClockEvent |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| describe('ClockEvent', function () { | ||
| let node; | ||
| this.timeout(10000); | ||
|
|
||
| before(async function () { | ||
| await rclnodejs.init(); | ||
| node = rclnodejs.createNode('test_clock_event_node'); | ||
| rclnodejs.spin(node); | ||
| }); | ||
|
|
||
| after(function () { | ||
| rclnodejs.shutdown(); | ||
| }); | ||
|
|
||
| it('should wait until steady time', async function () { | ||
| const clock = new Clock(ClockType.STEADY_TIME); | ||
| const event = new rclnodejs.ClockEvent(); | ||
| const now = clock.now(); | ||
| const until = now.add(new Duration(1n, 0n)); // 1 second later | ||
|
|
||
| const start = Date.now(); | ||
| await event.waitUntilSteady(clock, until.nanoseconds); | ||
| const end = Date.now(); | ||
|
|
||
| assert(end - start >= 1000); | ||
| }); | ||
|
|
||
| it('should wait until system time', async function () { | ||
| const clock = new Clock(ClockType.SYSTEM_TIME); | ||
| const event = new rclnodejs.ClockEvent(); | ||
| const now = clock.now(); | ||
| const until = now.add(new Duration(1n, 0n)); // 1 second later | ||
|
|
||
| const start = Date.now(); | ||
| await event.waitUntilSystem(clock, until.nanoseconds); | ||
| const end = Date.now(); | ||
|
|
||
| assert(end - start >= 1000); | ||
| }); |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The waitUntilRos method lacks test coverage. While waitUntilSteady and waitUntilSystem are tested, there is no test case for waitUntilRos. Consider adding a test that validates the ROS clock wait behavior.
test/test-clock-event.js
Outdated
|
|
||
| const assert = require('assert'); | ||
| const rclnodejs = require('../index.js'); | ||
| const { Clock, ClockType, Time, Duration } = rclnodejs; |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable Time.
| const { Clock, ClockType, Time, Duration } = rclnodejs; | |
| const { Clock, ClockType, Duration } = rclnodejs; |
Co-authored-by: Copilot <[email protected]>
This PR adds ClockEvent support to rclnodejs, providing a synchronization mechanism for waiting until specific clock times are reached. This is useful for time-based coordination in ROS applications.
Fix: #1330