@@ -29,12 +29,14 @@ use async_std::future::timeout;
29
29
use rosidl_runtime_rs:: Message ;
30
30
31
31
use crate :: {
32
- rcl_bindings:: * , Client , ClientOptions , ClientState , Clock , ContextHandle , ExecutorCommands ,
33
- IntoAsyncServiceCallback , IntoAsyncSubscriptionCallback , IntoNodeServiceCallback ,
34
- IntoNodeSubscriptionCallback , LogParams , Logger , ParameterBuilder , ParameterInterface ,
35
- ParameterVariant , Parameters , Promise , Publisher , PublisherOptions , PublisherState , RclrsError ,
36
- Service , ServiceOptions , ServiceState , Subscription , SubscriptionOptions , SubscriptionState ,
37
- TimeSource , ToLogParams , Worker , WorkerOptions , WorkerState , ENTITY_LIFECYCLE_MUTEX ,
32
+ rcl_bindings:: * , AnyTimerCallback , Client , ClientOptions , ClientState , Clock , ContextHandle ,
33
+ ExecutorCommands , IntoAsyncServiceCallback , IntoAsyncSubscriptionCallback ,
34
+ IntoNodeServiceCallback , IntoNodeSubscriptionCallback , IntoNodeTimerOneshotCallback ,
35
+ IntoNodeTimerRepeatingCallback , IntoTimerOptions , LogParams , Logger , ParameterBuilder ,
36
+ ParameterInterface , ParameterVariant , Parameters , Promise , Publisher , PublisherOptions ,
37
+ PublisherState , RclrsError , Service , ServiceOptions , ServiceState , Subscription ,
38
+ SubscriptionOptions , SubscriptionState , TimeSource , Timer , TimerState , ToLogParams , Worker ,
39
+ WorkerOptions , WorkerState , ENTITY_LIFECYCLE_MUTEX ,
38
40
} ;
39
41
40
42
/// A processing unit that can communicate with other nodes. See the API of
@@ -893,6 +895,70 @@ impl NodeState {
893
895
)
894
896
}
895
897
898
+ /// Create a [`Timer`] with a repeating callback.
899
+ ///
900
+ /// See also:
901
+ /// * [`Self::create_timer_oneshot`]
902
+ /// * [`Self::create_timer_inert`]
903
+ pub fn create_timer_repeating < ' a , Args > (
904
+ & self ,
905
+ options : impl IntoTimerOptions < ' a > ,
906
+ callback : impl IntoNodeTimerRepeatingCallback < Args > ,
907
+ ) -> Result < Timer , RclrsError > {
908
+ self . create_timer ( options, callback. into_node_timer_repeating_callback ( ) )
909
+ }
910
+
911
+ /// Create a [`Timer`] whose callback will be triggered once after the period
912
+ /// of the timer has elapsed. After that you will need to use
913
+ /// [`Timer::set_repeating`] or [`Timer::set_oneshot`] or else nothing will happen
914
+ /// the following times that the `Timer` elapses.
915
+ ///
916
+ /// See also:
917
+ /// * [`Self::create_timer_repeating`]
918
+ /// * [`Self::create_time_inert`]
919
+ pub fn create_timer_oneshot < ' a , Args > (
920
+ & self ,
921
+ options : impl IntoTimerOptions < ' a > ,
922
+ callback : impl IntoNodeTimerOneshotCallback < Args > ,
923
+ ) -> Result < Timer , RclrsError > {
924
+ self . create_timer ( options, callback. into_node_timer_oneshot_callback ( ) )
925
+ }
926
+
927
+ /// Create a [`Timer`] without a callback. Nothing will happen when this
928
+ /// `Timer` elapses until you use [`Timer::set_callback`] or a related method.
929
+ ///
930
+ /// See also:
931
+ /// * [`Self::create_timer_repeating`]
932
+ /// * [`Self::create_timer_oneshot`]
933
+ pub fn create_timer_inert < ' a > (
934
+ & self ,
935
+ options : impl IntoTimerOptions < ' a > ,
936
+ ) -> Result < Timer , RclrsError > {
937
+ self . create_timer ( options, AnyTimerCallback :: Inert )
938
+ }
939
+
940
+ /// Used internally to create a [`Timer`].
941
+ ///
942
+ /// Downstream users should instead use:
943
+ /// * [`Self::create_timer_repeating`]
944
+ /// * [`Self::create_timer_oneshot`]
945
+ /// * [`Self::create_timer_inert`]
946
+ fn create_timer < ' a > (
947
+ & self ,
948
+ options : impl IntoTimerOptions < ' a > ,
949
+ callback : AnyTimerCallback < Node > ,
950
+ ) -> Result < Timer , RclrsError > {
951
+ let options = options. into_timer_options ( ) ;
952
+ let clock = options. clock . as_clock ( self ) ;
953
+ TimerState :: create (
954
+ options. period ,
955
+ clock,
956
+ callback,
957
+ self . commands . async_worker_commands ( ) ,
958
+ & self . handle . context_handle ,
959
+ )
960
+ }
961
+
896
962
/// Returns the ROS domain ID that the node is using.
897
963
///
898
964
/// The domain ID controls which nodes can send messages to each other, see the [ROS 2 concept article][1].
0 commit comments