SMACC
Loading...
Searching...
No Matches
cl_ros_timer.h
Go to the documentation of this file.
1#pragma once
2
3#include <smacc/smacc.h>
4#include <boost/signals2.hpp>
5#include <boost/optional/optional_io.hpp>
6
7namespace cl_ros_timer
8{
9template <typename TSource, typename TOrthogonal>
10struct EvTimer : sc::event<EvTimer<TSource, TOrthogonal>>
11{
12 /*
13 ClRosTimer *sender;
14 ros::TimerEvent timedata;
15
16 EvTimer(ClRosTimer *sender, const ros::TimerEvent &timedata)
17 {
18 this->sender = sender;
19 this->timedata = timedata;
20 }
21 */
22};
23
25{
26public:
27 ClRosTimer(ros::Duration duration, bool oneshot = false);
28
29 virtual ~ClRosTimer();
30
31 virtual void initialize();
32
33 template <typename T>
34 boost::signals2::connection onTimerTick(void (T::*callback)(), T *object)
35 {
36 return this->getStateMachine()->createSignalConnection(onTimerTick_, callback, object);
37 }
38
39 template <typename TOrthogonal, typename TSourceObject>
41 {
42 this->postTimerEvent_ = [=]() {
43 this->postEvent<EvTimer<TSourceObject, TOrthogonal>>();
44 };
45 }
46
47protected:
48 ros::NodeHandle nh_;
49
50 ros::Timer timer;
51 ros::Duration duration;
52 bool oneshot;
53
54 void timerCallback(const ros::TimerEvent &timedata);
55 std::function<void()> postTimerEvent_;
57};
58} // namespace cl_ros_timer
void timerCallback(const ros::TimerEvent &timedata)
smacc::SmaccSignal< void()> onTimerTick_
Definition: cl_ros_timer.h:56
ros::NodeHandle nh_
Definition: cl_ros_timer.h:48
ros::Duration duration
Definition: cl_ros_timer.h:51
boost::signals2::connection onTimerTick(void(T::*callback)(), T *object)
Definition: cl_ros_timer.h:34
virtual void initialize()
std::function< void()> postTimerEvent_
Definition: cl_ros_timer.h:55
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)