Skip to content

Conversation

@minggangw
Copy link
Member

@minggangw minggangw commented Dec 16, 2025

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

Fix: #1330

Copilot AI review requested due to automatic review settings December 16, 2025 07:51
Copy link

Copilot AI left a 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.

Comment on lines +7 to +45
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);
});
Copy link

Copilot AI Dec 16, 2025

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.

Copilot uses AI. Check for mistakes.

const assert = require('assert');
const rclnodejs = require('../index.js');
const { Clock, ClockType, Time, Duration } = rclnodejs;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable Time.

Suggested change
const { Clock, ClockType, Time, Duration } = rclnodejs;
const { Clock, ClockType, Duration } = rclnodejs;

Copilot uses AI. Check for mistakes.
@coveralls
Copy link

coveralls commented Dec 16, 2025

Coverage Status

coverage: 80.44% (-0.05%) from 80.485%
when pulling cc951c6 on minggangw:fix-1330-11
into e6e95c1 on RobotWebTools:develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing rcl functions in rclnodejs

2 participants