@@ -198,16 +198,23 @@ class TimerBase
198198 set_on_reset_callback (rcl_event_callback_t callback, const void * user_data);
199199};
200200
201+ struct TimerInfo
202+ {
203+ Time expected_call_time;
204+ Time actual_call_time;
205+ };
201206
202207using VoidCallbackType = std::function<void ()>;
203208using TimerCallbackType = std::function<void (TimerBase &)>;
209+ using TimerInfoCallbackType = std::function<void (const TimerInfo &)>;
204210
205211// / Generic timer. Periodically executes a user-specified callback.
206212template <
207213 typename FunctorT,
208214 typename std::enable_if<
209215 rclcpp::function_traits::same_arguments<FunctorT, VoidCallbackType>::value ||
210- rclcpp::function_traits::same_arguments<FunctorT, TimerCallbackType>::value
216+ rclcpp::function_traits::same_arguments<FunctorT, TimerCallbackType>::value ||
217+ rclcpp::function_traits::same_arguments<FunctorT, TimerInfoCallbackType>::value
211218 >::type * = nullptr
212219>
213220class GenericTimer : public TimerBase
@@ -259,7 +266,7 @@ class GenericTimer : public TimerBase
259266 bool
260267 call () override
261268 {
262- rcl_ret_t ret = rcl_timer_call (timer_handle_.get ());
269+ rcl_ret_t ret = rcl_timer_call_with_info (timer_handle_.get (), &timer_call_info_ );
263270 if (ret == RCL_RET_TIMER_CANCELED) {
264271 return false ;
265272 }
@@ -305,6 +312,21 @@ class GenericTimer : public TimerBase
305312 callback_ (*this );
306313 }
307314
315+
316+ template <
317+ typename CallbackT = FunctorT,
318+ typename std::enable_if<
319+ rclcpp::function_traits::same_arguments<CallbackT, TimerInfoCallbackType>::value
320+ >::type * = nullptr
321+ >
322+ void
323+ execute_callback_delegate ()
324+ {
325+ const TimerInfo info{Time{timer_call_info_.expected_call_time , clock_->get_clock_type ()},
326+ Time{timer_call_info_.actual_call_time , clock_->get_clock_type ()}};
327+ callback_ (info);
328+ }
329+
308330 // / Is the clock steady (i.e. is the time between ticks constant?)
309331 /* * \return True if the clock used by this timer is steady. */
310332 bool
@@ -317,6 +339,7 @@ class GenericTimer : public TimerBase
317339 RCLCPP_DISABLE_COPY (GenericTimer)
318340
319341 FunctorT callback_;
342+ rcl_timer_call_info_t timer_call_info_;
320343};
321344
322345template <
0 commit comments