Skip to content

Commit cf38ae7

Browse files
committed
Correctly initialise clock type for ROSClocks instantiated directly
1 parent 9992b1f commit cf38ae7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

rclpy/rclpy/clock.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def now(self):
6060

6161
class ROSClock(Clock):
6262

63+
def __new__(cls):
64+
return super().__new__(Clock, clock_type=ClockType.ROS_TIME)
65+
6366
@property
6467
def ros_time_is_active(self):
6568
return _rclpy.rclpy_clock_get_ros_time_override_is_enabled(self._clock_handle)

rclpy/test/test_clock.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def test_clock_construction(self):
3838
assert clock.clock_type == ClockType.ROS_TIME
3939
assert isinstance(clock, ROSClock)
4040

41+
# Direct instantiation of a ROSClock is also possible.
42+
clock = ROSClock()
43+
assert clock.clock_type == ClockType.ROS_TIME
44+
4145
def test_clock_now(self):
4246
# System time should be roughly equal to time.time()
4347
# There will still be differences between them, with the bound depending on the scheduler.

0 commit comments

Comments
 (0)