From 5777bbee798910bc5fadf11925c7334332195943 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Wed, 10 May 2017 00:34:52 -0700 Subject: [PATCH] add method to reset a timer in TimerBase (#326) --- rclcpp/include/rclcpp/timer.hpp | 4 ++++ rclcpp/src/rclcpp/timer.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/rclcpp/include/rclcpp/timer.hpp b/rclcpp/include/rclcpp/timer.hpp index 1e15be7..73c1d74 100644 --- a/rclcpp/include/rclcpp/timer.hpp +++ b/rclcpp/include/rclcpp/timer.hpp @@ -55,6 +55,10 @@ public: void cancel(); + RCLCPP_PUBLIC + void + reset(); + RCLCPP_PUBLIC virtual void execute_callback() = 0; diff --git a/rclcpp/src/rclcpp/timer.cpp b/rclcpp/src/rclcpp/timer.cpp index 1128bbf..e15d683 100644 --- a/rclcpp/src/rclcpp/timer.cpp +++ b/rclcpp/src/rclcpp/timer.cpp @@ -40,6 +40,14 @@ TimerBase::cancel() } } +void +TimerBase::reset() +{ + if (rcl_timer_reset(&timer_handle_) != RCL_RET_OK) { + throw std::runtime_error(std::string("Couldn't reset timer: ") + rcl_get_error_string_safe()); + } +} + bool TimerBase::is_ready() {