SMACC
Loading...
Searching...
No Matches
smacc_state_machine_base.h
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6#pragma once
7#include <smacc/common.h>
8
11
12namespace smacc
13{
14
16template <typename DerivedStateMachine, typename InitialStateType>
17struct SmaccStateMachineBase : public ISmaccStateMachine, public sc::asynchronous_state_machine<DerivedStateMachine, InitialStateType, SmaccFifoScheduler, SmaccAllocator>
18{
19public:
21 : ISmaccStateMachine(signalDetector),
22 sc::asynchronous_state_machine<DerivedStateMachine, InitialStateType, SmaccFifoScheduler, SmaccAllocator>(ctx)
23 {
24 }
25
27 {
28 //updateCurrentState<InitialStateType>(false);
29 }
30
31 virtual void reset() override
32 {
34 this->terminate();
35 smacc::run<DerivedStateMachine>();
36 }
37
38 virtual void stop() override
39 {
41 this->terminate();
42 }
43
44 virtual void eStop() override
45 {
47 this->terminate();
48 }
49
50 virtual void initiate_impl() override
51 {
52 // this is before because this creates orthogonals
53 this->onInitialize();
54
55 ROS_INFO("[SmaccStateMachine] Introspecting state machine via typeWalker");
56 this->buildStateMachineInfo<InitialStateType>();
57
58 ROS_INFO("[SmaccStateMachine] initiate_impl");
59 auto shortname = smacc::utils::cleanShortTypeName(typeid(DerivedStateMachine));
60
61 this->initializeROS(shortname);
62
63 ROS_INFO("[SmaccStateMachine] Initializing ROS communication mechanisms");
64 this->onInitialized();
65
66 ROS_INFO("[SmaccStateMachine] Initializing state machine");
67 sc::state_machine<DerivedStateMachine, InitialStateType, SmaccAllocator>::initiate();
68 }
69};
70} // namespace smacc
void initializeROS(std::string smshortname)
virtual void onInitialize()
this function should be implemented by the user to create the orthogonals
boost::statechart::processor_container< boost::statechart::fifo_scheduler<>, boost::function0< void >, std::allocator< void > >::processor_context my_context
Definition: common.h:33
std::allocator< void > SmaccAllocator
Definition: introspection.h:36
std::string cleanShortTypeName(const std::type_info &tinfo)
Definition: common.cpp:14
boost::statechart::fifo_scheduler< SmaccFifoWorker, SmaccAllocator > SmaccFifoScheduler
virtual void initiate_impl() override
SmaccStateMachineBase(my_context ctx, SignalDetector *signalDetector)