13#include <condition_variable>
29template<
template<
class>
class Wrapper,
typename Tuple>
32template<
template<
class>
class Wrapper,
typename... Ts>
34 using type = std::tuple<typename Wrapper<Ts>::type...>;
37template<
template<
class>
class Wrapper,
typename Tuple>
41template<
typename T,
typename Tuple>
46 using type = std::tuple<T>;
49template<
typename T,
typename... Ts>
53 using type = std::conditional_t<!(std::is_same_v<T, Ts> || ...),
58template<
typename T,
typename Tuple>
63template<
typename Ts,
typename Us>
68template<
typename... Us>
70 using type = std::tuple<Us...>;
75template<
typename T,
typename... Ts,
typename... Us>
83template<
typename Ts,
typename Us = std::tuple<>>
92template<
typename Tuple>
95template<
typename... Ts>
97 using type = std::variant<Ts...>;
101template<
typename Tuple>
115template<
typename From,
typename Event,
typename To>
122template<
typename From,
125 auto Action = []() {},
126 auto Guard = []() {
return true; }>
140template<
typename From,
142 auto Action = []() {},
143 auto Guard = []() {
return true; }>
145 :
Transition<From, ClockTickEvent, To, Action, Guard> {};
148template<
typename Tuple,
typename... Ts>
153template<
typename Tuple>
159template<
typename Tuple,
typename First,
typename... Rest>
170template<
typename... Ts>
173template<
typename... Ts>
178template<
typename... Ts>
185template<
typename From,
187 typename TransitionsTuple,
193template<
typename Transition,
typename From,
typename Event>
196template<
typename From,
203 Event> : std::true_type {};
206template<
typename From,
typename Event,
typename... Transitions,
size_t Index>
210 std::tuple<Transitions...>,
212 std::enable_if_t<(Index < sizeof...(Transitions))>> {
214 std::tuple_element_t<Index, std::tuple<Transitions...>>;
215 static constexpr bool match =
218 using type =
typename std::conditional_t<
223 std::tuple<Transitions...>,
228template<
typename From,
typename Event,
typename... Transitions,
size_t Index>
232 std::tuple<Transitions...>,
234 std::enable_if_t<!(Index < sizeof...(Transitions))>> {
239template<
typename From,
typename Event,
typename Transitions>
245template<
typename From,
typename Event,
typename Transitions>
250template<
typename State,
typename Event,
typename Transitions>
252 !std::is_same_v<typename TransitionMap<State, Event, Transitions>::type,
256template<
typename T,
typename Event,
typename =
void>
259template<
typename T,
typename Event>
262 std::void_t<std::disjunction<
263 std::is_invocable<decltype(&T::exit), T>,
264 std::is_invocable<decltype(&T::exit), T, T&>,
265 std::is_invocable<decltype(&T::exit), T, Event>>>>
268template<
typename T,
typename Event>
272template<
typename T,
typename Event,
typename =
void>
275template<
typename T,
typename Event>
278 std::void_t<std::disjunction<
279 std::is_invocable<decltype(&T::entry), T>,
280 std::is_invocable<decltype(&T::entry), T&>,
281 std::is_invocable<decltype(&T::entry), T, Event>>>>
284template<
typename T,
typename Event>
288template<
typename T,
typename Event,
typename =
void>
291template<
typename T,
typename Event>
294 std::void_t<std::disjunction<
295 std::is_invocable<decltype(&T::guard), T>,
296 std::is_invocable<decltype(&T::guard), T&>,
297 std::is_invocable<decltype(&T::guard), T, Event>>>>
300template<
typename T,
typename Event>
304template<
typename T,
typename Event,
typename =
void>
307template<
typename T,
typename Event>
310 std::void_t<std::disjunction<
311 std::is_invocable<decltype(&T::action), T>,
312 std::is_invocable<decltype(&T::action), T&>,
313 std::is_invocable<decltype(&T::action), T, Event>>>>
316template<
typename T,
typename Event>
320template<
typename,
typename = std::
void_t<>>
335template<
typename State,
338 typename = std::void_t<>>
341template<
typename State,
typename Event,
typename Context>
346 std::void_t<decltype(std::declval<State>().handle(std::declval<Context&>(),
347 std::declval<Event>()))>>
351template<
typename State,
typename Event,
typename Context>
356template<
typename,
typename = std::
void_t<>>
360struct is_hsm_trait<T, std::void_t<decltype(T::is_hsm)>> : std::true_type {};
371 std::conjunction_v<has_transitions<T>, std::negation<is_hsm_trait<T>>>;
373template<
typename T,
typename =
void>
384template<
typename T,
typename transitions =
typename T::transitions>
396 template<
typename Event>
401 [
this, &e](
auto* state) {
402 using State = std::decay_t<
decltype(*state)>;
404 bool handled =
false;
407 handled = state->handle(std::forward<Event>(e));
418 state,
static_cast<Event&&
>(
e));
427 template<
typename Event,
typename State>
430 if constexpr (std::is_invocable_v<
decltype(&State::entry),
434 state->entry(
static_cast<T&
>(*
this), std::forward<Event>(
e));
435 }
else if constexpr (std::is_invocable_v<
decltype(&State::entry),
438 state->entry(
static_cast<T&
>(*
this));
439 }
else if constexpr (std::is_invocable_v<
decltype(&State::entry),
446 template<
typename Event,
typename State>
449 if constexpr (std::is_invocable_v<
decltype(&State::exit),
453 state->exit(
static_cast<T&
>(*
this), std::forward<Event>(
e));
454 }
else if constexpr (std::is_invocable_v<
decltype(&State::exit),
457 state->exit(
static_cast<T&
>(*
this));
458 }
else if constexpr (std::is_invocable_v<
decltype(&State::exit),
465 template<
typename Tn,
466 typename Event =
typename Tn::event,
467 typename State =
typename Tn::from>
470 if constexpr (std::is_invocable_v<
decltype(&State::guard),
474 return state->guard(
static_cast<T&
>(*
this),
475 std::forward<Event>(
e));
476 }
else if constexpr (std::is_invocable_v<
decltype(&State::guard),
479 return state->guard(
static_cast<T&
>(*
this));
480 }
else if constexpr (std::is_invocable_v<
decltype(&State::guard),
482 return state->guard();
484 }
else if constexpr (std::is_member_function_pointer_v<
decltype(Tn::guard)>) {
485 auto&
ctx =
static_cast<T&
>(*this);
486 return std::invoke(Tn::guard,
ctx);
492 template<
typename Tn,
493 typename Event =
typename Tn::event,
494 typename State =
typename Tn::from>
497 if constexpr (std::is_invocable_v<
decltype(&State::action),
501 state->action(
static_cast<T&
>(*
this), std::forward<Event>(
e));
502 }
else if constexpr (std::is_invocable_v<
decltype(&State::action),
505 state->action(
static_cast<T&
>(*
this));
506 }
else if constexpr (std::is_invocable_v<
decltype(&State::action),
511 else if constexpr (std::is_member_function_pointer_v<
decltype(Tn::action)>) {
512 auto&
ctx =
static_cast<T&
>(*this);
513 std::invoke(Tn::action,
ctx);
518 typename State =
typename transition::from,
519 typename Event =
typename transition::event>
520 std::enable_if_t<!has_handle_method_v<State, Event, T>,
void>
532 using to =
typename transition::to;
542 typename State =
typename transition::from,
543 typename Event =
typename transition::event>
544 std::enable_if_t<has_handle_method_v<State, Event, T>,
void>
548 if (!
state->handle(
static_cast<T&
>(*
this), std::forward<Event>(
e))) {
552 using to =
typename transition::to;
561 template<
typename State>
571template<
typename T,
typename =
void>
575struct make_hsm<T, std::enable_if_t<!is_state_trait_v<T>>> {
587 using to =
typename T::to;
600template<
typename... Ts>
603template<
typename... Ts>
605 using type = std::tuple<wrap_transition_t<Ts>...>;
608template<
typename... Ts>
613template<
typename T,
template<
typename>
class Policy =
make_hsm_t>
622 template<
typename Event>
624 return HsmType::handle(e);
629 return HsmType::handle(e);
637struct make_hsm<T, std::enable_if_t<is_state_trait_v<T>>> {
645template<
typename... Hsms>
650 template<
typename Event>
652 std::apply([e](
auto&... hsm) { (hsm.entry(e), ...); },
hsms_);
655 template<
typename Event>
657 std::apply([e](
auto&... hsm) { (hsm.exit(e), ...); },
hsms_);
660 template<
typename Event>
662 return std::apply([e](
auto&... hsm) {
return (hsm.handle(e) && ...); },
671template<
typename Event,
typename LockType,
typename ConditionVarType>
680 std::unique_lock<LockType> lock(eventQueueMutex_);
681 cvEventAvailable_.wait(
682 lock, [
this] {
return (!this->
empty() || this->interrupt_); });
695 std::lock_guard<LockType> lock(eventQueueMutex_);
697 cvEventAvailable_.notify_all();
702 cvEventAvailable_.notify_all();
710 bool empty() {
return push_index_ == pop_index_; }
716 pop_index_ = (pop_index_ + 1) % data_.size();
721 if ((push_index_ + 1) % data_.size() != pop_index_) {
722 data_[push_index_] = e;
723 push_index_ = (push_index_ + 1) % data_.size();
730 LockType eventQueueMutex_;
731 ConditionVarType cvEventAvailable_;
733 size_t push_index_{ 0 };
734 size_t pop_index_{ 0 };
735 std::array<Event, 50> data_;
745 this->mutex = xSemaphoreCreateMutex();
750 vSemaphoreDelete(this->mutex);
755 xSemaphoreTake(this->mutex, portMAX_DELAY);
760 return xSemaphoreTake(this->mutex, 0) == pdTRUE;
765 xSemaphoreGive(this->mutex);
772 SemaphoreHandle_t mutex;
778 : semaphore_(xSemaphoreCreateBinary())
781 xSemaphoreTake(semaphore_, 0);
786 template<
typename Lock>
789 UBaseType_t oldISRState = taskENTER_CRITICAL_FROM_ISR();
791 taskEXIT_CRITICAL_FROM_ISR(oldISRState);
795 xSemaphoreTake(semaphore_, portMAX_DELAY);
798 oldISRState = taskENTER_CRITICAL_FROM_ISR();
800 taskEXIT_CRITICAL_FROM_ISR(oldISRState);
807 if (waitersCount_ > 0) {
808 xSemaphoreGive(semaphore_);
813 while (waitersCount_ > 0) {
814 xSemaphoreGive(semaphore_);
816 vTaskDelay(pdMS_TO_TICKS(10));
821 SemaphoreHandle_t semaphore_;
822 volatile UBaseType_t waitersCount_;
829 using rep = duration::rep;
835 TickType_t ticks = xTaskGetTickCount();
838 auto durationSinceEpoch =
839 std::chrono::milliseconds(ticks * (1000 / configTICK_RATE_HZ));
844template<
typename Event>
847template<
typename HsmType,
typename Events>
857 xTaskCreate(
reinterpret_cast<TaskFunction_t
>(
taskCallback),
858 "ThreadedPolicyTask",
859 configMINIMAL_STACK_SIZE,
896 std::visit([
this](
auto const& e) {
return this->handle(e); },
904template<
typename Event>
905using EventQueue = EventQueueT<Event, std::mutex, std::condition_variable_any>;
909struct AccurateClock {
910 using duration = std::chrono::nanoseconds;
911 using period = duration::period;
912 using rep = duration::rep;
913 using time_point = std::chrono::time_point<AccurateClock>;
915 static constexpr bool is_steady =
true;
917 static time_point now() noexcept {
919 clock_gettime(CLOCK_MONOTONIC, &ts);
920 auto durationSinceEpoch = std::chrono::seconds(ts.tv_sec) +
921 std::chrono::nanoseconds(ts.tv_nsec);
922 return time_point(duration(durationSinceEpoch));
929template<
typename HsmType,
typename =
void>
932template<
typename Transition>
935template<
typename TransitionsTuple>
939template<
typename... Transitions>
941 using type =
decltype(std::tuple_cat(
952template<
typename Transition>
954 using Event = std::tuple<typename Transition::event>;
963template<
typename HsmType>
965 std::enable_if_t<has_transitions_v<HsmType>>> {
971template<
typename HsmType>
973 std::enable_if_t<!has_transitions_v<HsmType>>> {
978template<
typename HsmType>
983template<
typename Context,
template<
typename>
class Policy =
make_hsm_t>
986 using HsmType =
typename Policy<Context>::type;
991 Event const& nextEvent = eventQueue_.next_event();
995 [
this](
auto&& e) ->
bool {
return HsmType::handle(e); }, nextEvent);
999 eventQueue_.add_event(std::forward<Event>(event));
1008template<
typename Context,
template<
typename>
class Policy =
make_hsm_t>
1009struct ThreadedExecutionPolicy : Policy<Context> {
1033 eventQueue_.add_event(std::forward<Event>(event));
1045 std::visit([
this](
auto const& e) {
return this->handle(e); },
1057template<
typename LockType,
typename ConditionVarType>
1060 std::unique_lock<std::mutex> lock(smBusyMutex_);
1066 std::unique_lock<std::mutex> lock(smBusyMutex_);
1067 cv_.wait(lock, [
this] {
return this->notified_ ==
true; });
1072 LockType smBusyMutex_;
1073 ConditionVarType cv_;
1080 if (cb !=
nullptr) {
1086 for (
auto const& cb : cbs_) {
1092 std::vector<std::function<void()>> cbs_;
1108template<
typename Observer,
1112 :
public Policy<Context>
1116 using HsmType::interrupt_;
1117 using HsmType::process_event;
1118 using HsmType::smThread_;
1121 smThread_ = std::thread([
this] {
1122 while (!interrupt_) {
1135template<
typename Context>
1140template<
typename Clock = std::chrono::steady_clock,
1141 typename Duration =
typename Clock::duration>
1154 auto now = Clock::now();
1156 return std::chrono::duration_cast<Duration>(interval);
1159 template<
typename ToDuration = Duration>
1161 auto now = Clock::now();
1162 if constexpr (std::is_same<ToDuration, Duration>::value) {
1163 return std::chrono::duration_cast<Duration>(now - since);
1165 return std::chrono::duration_cast<ToDuration>(now - since);
1169 template<
typename ToDuration>
1171 return std::chrono::duration_cast<ToDuration>(
elapsed());
1184template<
typename Clock = std::chrono::steady_clock,
1185 typename Duration =
typename Clock::duration>
1194 auto now = Clock::now();
1196 this->start_time_ = now;
1197 return std::chrono::duration_cast<Duration>(
interval);
1205template<
typename Clock = AccurateClock,
1206 typename Duration =
typename Clock::duration>
1219 std::chrono::duration_cast<std::chrono::seconds>(remaining).count();
1221 std::chrono::duration_cast<std::chrono::nanoseconds>(remaining)
1224 struct timespec remaining_ts;
1225 while (nanosleep(&ts, &remaining_ts) == EINTR) {
1247 struct sched_param param;
1249 if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m) != 0) {
1250 perror(
"pthread_setschedparam");
1257 CPU_SET(cpu, &cpuset);
1260 if (pthread_setaffinity_np(
1261 pthread_self(),
sizeof(cpu_set_t), &cpuset) != 0) {
1262 perror(
"sched_setaffinity");
1266 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
1267 perror(
"mlockall failed");
1271 template<
typename Fn>
1273 return std::thread([
this, fn] {
1281 return std::move(t);
1290template<
typename Context,
1291 template<
typename>
class Policy = ThreadedExecutionPolicy>
1297 using HsmType::interrupt_;
1298 using HsmType::process_event;
1299 using HsmType::smThread_;
1303 while (!interrupt_) {
1313template<
typename Context,
1316 std::chrono::milliseconds>>
1323 using HsmType::interrupt_;
1324 using HsmType::send_event;
1327 PeriodicTimer::start();
1331 while (!interrupt_) {
1332 PeriodicTimer::wait();
1355template<
typename Context,
1358 std::chrono::milliseconds>>
1367 using HsmType::interrupt_;
1368 using HsmType::process_event;
1369 using HsmType::send_event;
1370 using HsmType::smThread_;
1373 PeriodicTimer::start();
1375 while (!interrupt_) {
1376 this->process_event();
1381 while (!interrupt_) {
1382 PeriodicTimer::wait();
1405template<
typename... Hsms>
1410 template<
typename Event>
1412 std::apply([e](
auto&... hsm) { (hsm.entry(e), ...); },
hsms_);
1415 template<
typename Event>
1417 std::apply([e](
auto&... hsm) { (hsm.exit(e), ...); },
hsms_);
1420 template<
typename Event>
1424 [e](
auto&... hsm) { (hsm.send_event(e), ...); },
1431 std::apply([](
auto&... hsm) { (hsm.tick(), ...); },
hsms_);
1477template<
typename Context,
1491template<
typename Context,
1510template<
typename Context,
1525template<
typename Context,
1530template<
typename Context,
1536 typename... Contexts>
tsm::EventQueueT< tsm::Event, std::mutex > EventQueue
Definition EventQueue.cpp:8
FreeRTOSConditionVariable()
Definition tsm.h:777
~FreeRTOSConditionVariable()
Definition tsm.h:784
void notify_all()
Definition tsm.h:812
void wait(Lock &lock)
Definition tsm.h:787
void notify_one()
Definition tsm.h:806
bool try_lock()
Definition tsm.h:758
SemaphoreHandle_t native_handle()
Definition tsm.h:769
void lock()
Definition tsm.h:753
FreeRTOSMutex()
Definition tsm.h:743
void unlock()
Definition tsm.h:763
~FreeRTOSMutex()
Definition tsm.h:748
typename Policy< Context >::type HsmType
Definition tsm.h:1011
static void StepTask(void *pvParameters)
Definition tsm.h:882
void stop()
Definition tsm.h:1022
tuple_to_variant_t< Events > Event
Definition tsm.h:850
ThreadedExecutionPolicy()
Definition tsm.h:854
BaseType_t interrupt_
Definition tsm.h:880
void process_event()
Definition tsm.h:893
TaskHandle_t smTaskHandle
Definition tsm.h:878
EventQueue eventQueue
Definition tsm.h:879
std::thread smThread_
Definition tsm.h:1037
virtual ~ThreadedExecutionPolicy()
Definition tsm.h:865
void(*)(ThreadedExecutionPolicy *) TaskCallback
Definition tsm.h:852
void start()
Definition tsm.h:1014
TaskCallback taskCallback
Definition tsm.h:877
void send_event(const Event &event)
Definition tsm.h:874
void step()
Definition tsm.h:887
EventQueue< Event > eventQueue_
Definition tsm.h:1038
void send_event(Event &&event)
Definition tsm.h:1032
constexpr bool has_entry_v
Definition tsm.h:285
constexpr bool has_guard_v
Definition tsm.h:301
typename get_states< Ts... >::type get_states_t
Definition tsm.h:179
constexpr bool is_clocked_hsm_v
Definition tsm.h:381
unique_tuple_t< typename get_events_from_hsm< HsmType >::type > get_events_t
Definition tsm.h:980
constexpr bool is_hsm_trait_v
Definition tsm.h:366
constexpr bool has_exit_v
Definition tsm.h:269
typename wrap_type_impl< Wrapper, Tuple >::type wrap_type
Definition tsm.h:38
constexpr bool is_state_trait_v
Definition tsm.h:370
constexpr bool has_transitions_v
Definition tsm.h:331
typename make_hsm< T >::type make_hsm_t
Definition tsm.h:580
constexpr bool has_action_v
Definition tsm.h:317
typename is_hsm_trait< T >::type is_hsm_trait_t
Definition tsm.h:363
typename wrap_transitions< Ts... >::type wrap_transitions_t
Definition tsm.h:609
constexpr int MaxEvents
Definition tsm.h:739
constexpr bool has_valid_transition_v
Definition tsm.h:251
typename wrap_transition< T >::type wrap_transition_t
Definition tsm.h:598
constexpr bool has_handle_method_v
Definition tsm.h:352
typename make_concurrent_hsm< Policy, Ts... >::type make_concurrent_hsm_t
Definition tsm.h:1446
typename unique_tuple< Ts >::type unique_tuple_t
Definition tsm.h:89
typename tuple_to_variant_impl< Tuple >::type tuple_to_variant_t
Definition tsm.h:102
typename has_transitions< T >::type has_transitions_t
Definition tsm.h:328
typename TransitionMap< From, Event, Transitions >::type find_transition_t
Definition tsm.h:247
typename append_unique_impl< T, Tuple >::type append_unique
Definition tsm.h:59
detail::make_concurrent_hsm_t< Policy, Contexts... > ConcurrentHsm
Definition tsm.h:1537
Policy< Context > SingleThreadedHsm
Definition tsm.h:1479
Policy< Context > ThreadedHsm
Definition tsm.h:1493
Policy< Context > RealtimeHsm
Definition tsm.h:1532
Policy< Context > RealtimePeriodicHsm
Definition tsm.h:1527
Policy< Context > PeriodicHsm
Definition tsm.h:1512
From from
Definition tsm.h:117
To to
Definition tsm.h:119
void wait()
Definition tsm.h:1065
void notify()
Definition tsm.h:1059
void add_callback(std::function< void()> &&cb)
Definition tsm.h:1079
void notify()
Definition tsm.h:1085
int ticks_
Definition tsm.h:137
ClockTickEvent tick_event_
Definition tsm.h:631
bool handle(Event e=Event())
Definition tsm.h:623
bool tick()
Definition tsm.h:620
bool handle(ClockTickEvent &e)
Definition tsm.h:627
typename Policy< T >::type HsmType
Definition tsm.h:616
void exit(Event &&e)
Definition tsm.h:1416
std::tuple< Hsms... > hsms_
Definition tsm.h:1434
void send_event(Event &&e)
Definition tsm.h:1421
void entry(Event e=Event())
Definition tsm.h:1411
void tick()
Definition tsm.h:1430
static constexpr bool is_hsm
Definition tsm.h:1407
bool interrupted()
Definition tsm.h:707
void add_event(Event &&e)
Definition tsm.h:691
bool empty()
Definition tsm.h:710
void stop()
Definition tsm.h:700
bool push_back(Event const &e)
Definition tsm.h:720
void pop_front()
Definition tsm.h:714
Event next_event()
Definition tsm.h:679
Event const & front()
Definition tsm.h:712
virtual ~EventQueueT()
Definition tsm.h:675
std::chrono::milliseconds duration
Definition tsm.h:827
static constexpr bool is_steady
Definition tsm.h:832
duration::rep rep
Definition tsm.h:829
static time_point now() noexcept
Definition tsm.h:834
duration::period period
Definition tsm.h:828
std::chrono::time_point< FreeRTOSClock > time_point
Definition tsm.h:830
transitions transitions_
Definition tsm.h:567
std::enable_if_t< has_handle_method_v< State, Event, T >, void > handle_transition(State *state, Event &&e)
Definition tsm.h:545
bool check_guard(Event &&e, State *state)
Definition tsm.h:468
void perform_action(Event &&e, State *state)
Definition tsm.h:495
void current_state()
Definition tsm.h:562
typename std::tuple_element_t< 0, transitions >::from initial_state
Definition tsm.h:389
Hsm()
Definition tsm.h:392
std::enable_if_t<!has_handle_method_v< State, Event, T >, void > handle_transition(typename transition::from *state, Event &&e)
Definition tsm.h:521
get_states_t< transitions > States
Definition tsm.h:390
Hsm< T, transitions > type
Definition tsm.h:387
static constexpr bool is_hsm
Definition tsm.h:386
tuple_to_variant_t< wrap_type< std::add_pointer, States > > current_state_
Definition tsm.h:568
void entry(Event &&e, State *state) noexcept
Definition tsm.h:428
bool handle(Event &&e)
Definition tsm.h:397
States states_
Definition tsm.h:566
void exit(Event &&e, State *state) noexcept
Definition tsm.h:447
Duration interval()
Definition tsm.h:1189
void exit(Event e=Event())
Definition tsm.h:656
static constexpr bool is_hsm
Definition tsm.h:647
bool handle(Event e=Event())
Definition tsm.h:661
void entry(Event e=Event())
Definition tsm.h:651
std::tuple< Hsms... > hsms_
Definition tsm.h:666
PeriodicTimer TimerType
Definition tsm.h:1322
std::thread eventThread_
Definition tsm.h:1350
ClockTickEvent tick_event_
Definition tsm.h:1351
virtual ~PeriodicExecutionPolicy()
Definition tsm.h:1345
int get_ticks()
Definition tsm.h:1347
void start()
Definition tsm.h:1326
typename Policy< Context >::type HsmType
Definition tsm.h:1321
void stop()
Definition tsm.h:1339
void start()
Definition tsm.h:1210
PeriodicSleepTimer(Duration period=Duration(1))
Definition tsm.h:1208
Duration get_period() const
Definition tsm.h:1232
Duration period_
Definition tsm.h:1235
void wait()
Definition tsm.h:1212
std::array< int, 4 > CPU_AFFINITY
Definition tsm.h:1286
RealtimeConfigurator()=default
RealtimeConfigurator(int priority, std::array< int, 4 > affinity)
Definition tsm.h:1241
std::thread make_real_time(std::thread &&t)
Definition tsm.h:1279
std::thread real_time_thread(Fn fn)
Definition tsm.h:1272
int PROCESS_PRIORITY
Definition tsm.h:1285
void config_realtime_thread()
Definition tsm.h:1245
void start()
Definition tsm.h:1301
typename Policy< Context >::type HsmType
Definition tsm.h:1296
virtual ~RealtimeExecutionPolicy()=default
PeriodicTimer TimerType
Definition tsm.h:1365
virtual ~RealtimePeriodicExecutionPolicy()
Definition tsm.h:1395
int get_ticks()
Definition tsm.h:1397
typename Policy< Context >::type HsmType
Definition tsm.h:1366
ClockTickEvent tick_event_
Definition tsm.h:1401
void start()
Definition tsm.h:1372
void stop()
Definition tsm.h:1389
std::thread eventThread_
Definition tsm.h:1400
void send_event(Event &&event)
Definition tsm.h:998
bool step()
Definition tsm.h:989
tuple_to_variant_t< get_events_t< HsmType > > Event
Definition tsm.h:987
typename Policy< Context >::type HsmType
Definition tsm.h:986
typename Policy< Context >::type HsmType
Definition tsm.h:1115
void start()
Definition tsm.h:1120
virtual ~ThreadedExecWithObserver()=default
Helper to implement a Timed Execution Policy.
Definition tsm.h:1142
Clock ClockType
Definition tsm.h:1143
void start()
Definition tsm.h:1145
Duration DurationType
Definition tsm.h:1144
ToDuration elapsed() const
Definition tsm.h:1170
Clock::time_point start_time_
Definition tsm.h:1179
bool started_
Definition tsm.h:1180
bool started() const
Definition tsm.h:1174
Duration elapsed(ToDuration since) const
Definition tsm.h:1160
void reset()
Definition tsm.h:1175
Duration elapsed() const
Definition tsm.h:1150
void stop()
Definition tsm.h:1176
typename transition_map_helper< From, Event, Transitions >::type type
Definition tsm.h:241
decltype(Guard) guard_t
Definition tsm.h:131
decltype(Action) action_t
Definition tsm.h:130
static constexpr action_t action
Definition tsm.h:132
static constexpr guard_t guard
Definition tsm.h:133
decltype(std::tuple_cat(typename get_events_from_transition< Transitions >::type{}...)) type
Definition tsm.h:942
std::tuple<> type
Definition tsm.h:948
std::conditional_t<!(std::is_same_v< T, Ts >||...), std::tuple< Ts..., T >, std::tuple< Ts... > > type
Definition tsm.h:55
std::tuple< T > type
Definition tsm.h:46
typename aggregate_events< Transitions >::type type
Definition tsm.h:967
typename HsmType::transitions Transitions
Definition tsm.h:966
std::tuple<> type
Definition tsm.h:974
typename get_events_from_hsm< typename Transition::from >::type FromEvents
Definition tsm.h:956
std::tuple< typename Transition::event > Event
Definition tsm.h:954
decltype(std::tuple_cat(Event{}, FromEvents{}, ToEvents{})) type
Definition tsm.h:959
typename get_events_from_hsm< typename Transition::to >::type ToEvents
Definition tsm.h:958
typename get_states_impl< std::tuple<>, Ts... >::type type
Definition tsm.h:175
append_unique< typename First::from, Tuple > from_states
Definition tsm.h:162
append_unique< typename First::to, from_states > to_states
Definition tsm.h:164
typename get_states_impl< to_states, Rest... >::type type
Definition tsm.h:167
Tuple type
Definition tsm.h:155
wrap_transitions_t< typename T::transitions > transitions
Definition tsm.h:639
T type
Definition tsm.h:576
void type
Definition tsm.h:235
typename std::conditional_t< match, CurrentTransition, typename transition_map_helper< From, Event, std::tuple< Transitions... >, Index+1 >::type > type
Definition tsm.h:224
std::tuple_element_t< Index, std::tuple< Transitions... > > CurrentTransition
Definition tsm.h:214
std::variant< Ts... > type
Definition tsm.h:97
typename unique_tuple_impl< std::tuple< Ts... >, append_unique< T, std::tuple< Us... > > >::type type
Definition tsm.h:79
std::tuple< Us... > type
Definition tsm.h:70
typename unique_tuple_impl< Ts, Us >::type type
Definition tsm.h:85
typename T::to to
Definition tsm.h:587
std::conditional_t< is_state_trait_v< from >, make_hsm_t< from >, from > wrap_from
Definition tsm.h:590
std::conditional_t< is_state_trait_v< to >, make_hsm_t< to >, to > wrap_to
Definition tsm.h:592
typename T::from from
Definition tsm.h:585
typename T::event event
Definition tsm.h:586
std::tuple< wrap_transition_t< Ts >... > type
Definition tsm.h:605
std::tuple< typename Wrapper< Ts >::type... > type
Definition tsm.h:34
T type
Definition tsm.h:109