SMACC2
Loading...
Searching...
No Matches
cl_ros_timer.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <boost/signals2.hpp>
18#include <chrono>
19#include <optional>
20#include <smacc2/smacc.hpp>
21
22namespace cl_ros_timer
23{
24template <typename TSource, typename TOrthogonal>
25struct EvTimer : sc::event<EvTimer<TSource, TOrthogonal>>
26{
27 /*
28 ClRosTimer *sender;
29 rclcpp::TimerEvent timedata;
30
31 EvTimer(ClRosTimer *sender, const rclcpp::TimerEvent &timedata)
32 {
33 this->sender = sender;
34 this->timedata = timedata;
35 }
36 */
37};
38
40{
41public:
42 ClRosTimer(rclcpp::Duration duration, bool oneshot = false);
43
44 virtual ~ClRosTimer();
45
46 virtual void initialize();
47
48 template <typename T>
49 boost::signals2::connection onTimerTick(void (T::*callback)(), T * object)
50 {
51 return this->getStateMachine()->createSignalConnection(onTimerTick_, callback, object);
52 }
53
54 template <typename TOrthogonal, typename TSourceObject>
56 {
57 this->postTimerEvent_ = [=]() { this->postEvent<EvTimer<TSourceObject, TOrthogonal>>(); };
58 }
59
60protected:
61 rclcpp::TimerBase::SharedPtr timer_;
62 rclcpp::Duration duration_;
64
65 void timerCallback();
66 std::function<void()> postTimerEvent_;
68};
69} // namespace cl_ros_timer
rclcpp::Duration duration_
virtual void initialize()
boost::signals2::connection onTimerTick(void(T::*callback)(), T *object)
smacc2::SmaccSignal< void()> onTimerTick_
rclcpp::TimerBase::SharedPtr timer_
std::function< void()> postTimerEvent_
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)