Skip to content

Commit 8f2e1b8

Browse files
Minor cleanup
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
1 parent 7676a41 commit 8f2e1b8

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

rclrs/src/clock.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ impl Clock {
4343
})
4444
}
4545

46-
pub fn rcl_clock(&self) -> Arc<Mutex<rcl_clock_t>> {
47-
self._rcl_clock.clone()
48-
}
49-
5046
pub fn clock_type(&self) -> ClockType {
5147
self._type
5248
}
@@ -68,17 +64,26 @@ impl Clock {
6864
}
6965
}
7066

71-
pub fn now(&self) -> Result<Time, RclrsError> {
67+
pub fn now(&self) -> Time {
7268
let mut clock = self._rcl_clock.lock().unwrap();
7369
let mut time_point: i64 = 0;
7470
unsafe {
75-
// SAFETY: No preconditions for this function
76-
rcl_clock_get_now(&mut *clock, &mut time_point).ok()?;
71+
// SAFETY: The function will only fail if the clock is not initialized
72+
rcl_clock_get_now(&mut *clock, &mut time_point);
7773
}
78-
Ok(Time {
74+
Time {
7975
nsec: time_point,
8076
clock_type: self._type,
81-
})
77+
}
78+
}
79+
80+
pub fn set_ros_time_override(&self, nanoseconds: i64) {
81+
let mut clock = self._rcl_clock.lock().unwrap();
82+
// SAFETY: Safe if clock jump callbacks are not edited, which is guaranteed
83+
// by the mutex
84+
unsafe {
85+
rcl_set_ros_time_override(&mut *clock, nanoseconds);
86+
}
8287
}
8388

8489
/// Helper function to initialize a default clock, same behavior as `rcl_init_generic_clock`.

rclrs/src/time_source.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,8 @@ impl TimeSource {
136136
}
137137

138138
fn update_clock(clock: &Arc<Mutex<Clock>>, nanoseconds: i64) {
139-
let clock = clock.lock().unwrap().rcl_clock();
140-
let mut clock = clock.lock().unwrap();
141-
// SAFETY: Safe if clock jump callbacks are not edited, which is guaranteed
142-
// by the mutex
143-
unsafe {
144-
rcl_set_ros_time_override(&mut *clock, nanoseconds);
145-
}
139+
let clock = clock.lock().unwrap();
140+
clock.set_ros_time_override(nanoseconds);
146141
}
147142

148143
fn update_all_clocks(clocks: &Arc<Mutex<Vec<Arc<Mutex<Clock>>>>>, nanoseconds: i64) {

0 commit comments

Comments
 (0)