@@ -55,6 +55,20 @@ pub fn default_callback(step: crate::default::SimStep) -> SimOverride {
5555 }
5656}
5757
58+ fn set_msg_timing < T : CuMsgPayload > ( clock : & RobotClock , msg : & mut CuMsg < T > ) {
59+ let tov = clock. now ( ) ;
60+ let perf = cu29:: curuntime:: perf_now ( clock) ;
61+ msg. tov = tov. into ( ) ;
62+ msg. metadata . process_time . start = perf. into ( ) ;
63+ msg. metadata . process_time . end = perf. into ( ) ;
64+ }
65+
66+ fn set_process_timing < T : CuMsgPayload > ( clock : & RobotClock , msg : & mut CuMsg < T > ) {
67+ let perf = cu29:: curuntime:: perf_now ( clock) ;
68+ msg. metadata . process_time . start = perf. into ( ) ;
69+ msg. metadata . process_time . end = perf. into ( ) ;
70+ }
71+
5872#[ cfg( not( target_arch = "wasm32" ) ) ]
5973#[ cfg_attr( feature = "bevymon" , allow( dead_code) ) ]
6074pub fn setup_native_copper ( mut commands : Commands ) {
@@ -228,11 +242,8 @@ pub fn run_copper_callback<T: Send + Sync + 'static>(
228242 }
229243
230244 let analog_value = ( angle_radians / ( 2.0 * std:: f32:: consts:: PI ) * 4096.0 ) as u16 ;
231- let now = clock. now ( ) ;
232245 output. set_payload ( ADSReadingPayload { analog_value } ) ;
233- output. tov = now. into ( ) ;
234- output. metadata . process_time . start = now. into ( ) ;
235- output. metadata . process_time . end = now. into ( ) ;
246+ set_msg_timing ( & clock, output) ;
236247 SimOverride :: ExecutedBySim
237248 }
238249 crate :: default:: SimStep :: Balpos ( _) => SimOverride :: ExecutedBySim ,
@@ -241,11 +252,8 @@ pub fn run_copper_callback<T: Send + Sync + 'static>(
241252 let ( cart_transform, _, _) =
242253 bindings. single_mut ( ) . expect ( "Failed to get cart transform" ) ;
243254 let ticks = ( cart_transform. translation . x * 2000.0 ) as i32 ;
244- let now = clock. now ( ) ;
245255 output. set_payload ( EncoderPayload { ticks } ) ;
246- output. tov = now. into ( ) ;
247- output. metadata . process_time . start = now. into ( ) ;
248- output. metadata . process_time . end = now. into ( ) ;
256+ set_msg_timing ( & clock, output) ;
249257 SimOverride :: ExecutedBySim
250258 }
251259 crate :: default:: SimStep :: Railpos ( _) => SimOverride :: ExecutedBySim ,
@@ -255,7 +263,6 @@ pub fn run_copper_callback<T: Send + Sync + 'static>(
255263 bindings. single_mut ( ) . expect ( "Failed to get cart force" ) ;
256264 let maybe_motor_actuation = input. payload ( ) ;
257265 let override_motor = drag_state. override_motor ;
258- let now = clock. now ( ) ;
259266 if override_motor {
260267 if let Some ( motor_actuation) = maybe_motor_actuation
261268 && !motor_actuation. power . get :: < ratio > ( ) . is_nan ( )
@@ -269,15 +276,13 @@ pub fn run_copper_callback<T: Send + Sync + 'static>(
269276 . metadata
270277 . set_status ( format ! ( "Applied force: {force_magnitude}" ) ) ;
271278 }
272- output. metadata . process_time . start = now. into ( ) ;
273- output. metadata . process_time . end = now. into ( ) ;
279+ set_process_timing ( & clock, output) ;
274280 return SimOverride :: ExecutedBySim ;
275281 }
276282 if let Some ( motor_actuation) = maybe_motor_actuation {
277283 if motor_actuation. power . get :: < ratio > ( ) . is_nan ( ) {
278284 cart_force. 0 = Vector :: ZERO ;
279- output. metadata . process_time . start = now. into ( ) ;
280- output. metadata . process_time . end = now. into ( ) ;
285+ set_process_timing ( & clock, output) ;
281286 return SimOverride :: ExecutedBySim ;
282287 }
283288 let total_mass = motor_model:: total_mass_kg ( ) ;
@@ -291,13 +296,11 @@ pub fn run_copper_callback<T: Send + Sync + 'static>(
291296 output
292297 . metadata
293298 . set_status ( format ! ( "Applied force: {force_magnitude}" ) ) ;
294- output. metadata . process_time . start = now. into ( ) ;
295- output. metadata . process_time . end = now. into ( ) ;
299+ set_process_timing ( & clock, output) ;
296300 SimOverride :: ExecutedBySim
297301 } else {
298302 cart_force. 0 = Vector :: ZERO ;
299- output. metadata . process_time . start = now. into ( ) ;
300- output. metadata . process_time . end = now. into ( ) ;
303+ set_process_timing ( & clock, output) ;
301304 SimOverride :: Errored ( "Safety Mode." . into ( ) )
302305 }
303306 }
0 commit comments