44 #ifndef ROBOT_ACTIVITY_ISOLATED_ASYNC_TIMER_H 45 #define ROBOT_ACTIVITY_ISOLATED_ASYNC_TIMER_H 90 const float& frequency,
91 bool stoppable =
true,
92 bool autostart =
true,
119 const float& frequency,
120 bool stoppable =
true,
121 bool autostart =
true,
122 bool oneshot =
false)
140 timer_ = std::make_shared<ros::Timer>();
152 ROS_DEBUG(
"IsolatedAsyncTimer destructor");
206 void setRate(
const float& frequency,
bool reset =
true)
243 auto last_loop_duration = ev.profile.last_duration.toSec();
244 if (ev.last_real.toSec() != 0 && last_loop_duration >
period_.
toSec())
248 "Missed it's desired rate of " <<
frequency_ <<
249 " [Hz], the loop actually took " << last_loop_duration
250 <<
" [s], which is " << lag <<
" [s] longer");
312 #endif // ROBOT_ACTIVITY_ISOLATED_ASYNC_TIMER_H std::atomic< bool > paused_
Atomic bool that determines whether timer is paused or not.
ros::TimerOptions timer_ops_
Timer options needed for.
ros::TimerCallback wrapTimerCallback(const ros::TimerCallback &callback) const
Wraps a ros::TimerCallback with additional functionality.
float frequency_
Frequency in Hz of the timer.
IsolatedAsyncTimer(const ros::NodeHandle &node_handle, const ros::TimerCallback &callback, const float &frequency, bool stoppable=true, bool autostart=true, bool oneshot=false)
Constructor.
bool isValid()
Returns true if timer is valid.
boost::function< void(const TimerEvent &)> TimerCallback
std::function< void(void)> LambdaCallback
IsolatedAsyncTimer()=delete
Default destructor is deleted.
CallbackQueueInterface * callback_queue
std::shared_ptr< ros::AsyncSpinner > spinner_
Shared pointer to the actual ros::AsyncSpiner that serves the callback queue in the background...
IsolatedAsyncTimer(const ros::NodeHandle &node_handle, const IsolatedAsyncTimer::LambdaCallback &callback, const float &frequency, bool stoppable=true, bool autostart=true, bool oneshot=false)
Constructor.
Wrapper around ROS Timer.
ros::NodeHandle node_handle_
Node handle used to create the actual ros::Timer.
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
~IsolatedAsyncTimer()
Default destructor.
ros::TimerCallback callback_
Actual ros::TimerCallback used in the timer.
#define ROS_WARN_STREAM_THROTTLE(rate, args)
void resume()
Resumes the timer.
std::atomic< bool > stoppable_
Atomic bool that determines whether timer is stoppable or not.
ros::Duration period_
Duration between consecutive callback executions.
void start()
Starts the timer.
std::shared_ptr< ros::Timer > timer_
Shared pointer to the actual ros::Timer object.
ros::CallbackQueue callback_queue_
Seperate callback queue for the timer.
void pause()
Pauses the timer.
void stop()
Stops the timer if set to stoppable.
void setRate(const float &frequency, bool reset=true)
Sets a new rate to the timer.
static ros::TimerCallback to_timer_callback(const IsolatedAsyncTimer::LambdaCallback &callback)
Converts a Lambda callback to valid ros::TimerCallback.