File tree 2 files changed +16
-16
lines changed
2 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,6 @@ impl Clock {
43
43
} )
44
44
}
45
45
46
- pub fn rcl_clock ( & self ) -> Arc < Mutex < rcl_clock_t > > {
47
- self . _rcl_clock . clone ( )
48
- }
49
-
50
46
pub fn clock_type ( & self ) -> ClockType {
51
47
self . _type
52
48
}
@@ -68,17 +64,26 @@ impl Clock {
68
64
}
69
65
}
70
66
71
- pub fn now ( & self ) -> Result < Time , RclrsError > {
67
+ pub fn now ( & self ) -> Time {
72
68
let mut clock = self . _rcl_clock . lock ( ) . unwrap ( ) ;
73
69
let mut time_point: i64 = 0 ;
74
70
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) ;
77
73
}
78
- Ok ( Time {
74
+ Time {
79
75
nsec : time_point,
80
76
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
+ }
82
87
}
83
88
84
89
/// Helper function to initialize a default clock, same behavior as `rcl_init_generic_clock`.
Original file line number Diff line number Diff line change @@ -136,13 +136,8 @@ impl TimeSource {
136
136
}
137
137
138
138
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) ;
146
141
}
147
142
148
143
fn update_all_clocks ( clocks : & Arc < Mutex < Vec < Arc < Mutex < Clock > > > > > , nanoseconds : i64 ) {
You can’t perform that action at this time.
0 commit comments