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
30{
31public:
32 ClRosTimer(rclcpp::Duration duration, bool oneshot = false);
33
34 virtual ~ClRosTimer();
35
36 virtual void initialize();
37
38 template <typename T>
39 boost::signals2::connection onTimerTick(void (T::*callback)(), T * object)
40 {
41 return this->getStateMachine()->createSignalConnection(onTimerTick_, callback, object);
42 }
43
44 template <typename TOrthogonal, typename TSourceObject>
49
50protected:
51 rclcpp::TimerBase::SharedPtr timer_;
52 rclcpp::Duration duration_;
54
55 void timerCallback();
56 std::function<void()> postTimerEvent_;
58};
59} // 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_
ClRosTimer(rclcpp::Duration duration, bool oneshot=false)
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)