SMACC2
Loading...
Searching...
No Matches
smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType > Struct Template Reference

State Machine. More...

#include <smacc_state_machine_base.hpp>

Inheritance diagram for smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >:
Inheritance graph
Collaboration diagram for smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >:
Collaboration graph

Public Member Functions

 SmaccStateMachineBase (my_context ctx, SignalDetector *signalDetector, const rclcpp::NodeOptions &node_options=rclcpp::NodeOptions())
 
virtual ~SmaccStateMachineBase ()
 
void reset () override
 
void stop () override
 
void eStop () override
 
void unconsumed_event (const sc::event_base &ev)
 
void initiate_impl () override
 
- Public Member Functions inherited from smacc2::ISmaccStateMachine
 ISmaccStateMachine (std::string stateMachineName, SignalDetector *signalDetector, const rclcpp::NodeOptions &nodeOptions=rclcpp::NodeOptions())
 
virtual ~ISmaccStateMachine ()
 
 ISmaccStateMachine (const ISmaccStateMachine &)=delete
 
ISmaccStateMachine & operator= (const ISmaccStateMachine &)=delete
 
 ISmaccStateMachine (ISmaccStateMachine &&)=delete
 
ISmaccStateMachine & operator= (ISmaccStateMachine &&)=delete
 
void joinAsyncClientBehaviorThreads ()
 
template<typename TOrthogonal >
TOrthogonal * getOrthogonal ()
 
template<typename TOrthogonal , typename TClientBehavior >
TClientBehavior * getClientBehavior (int index=0)
 
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & getOrthogonals () const
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType, ISmaccOrthogonal *first=nullptr)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType, ISmaccOrthogonal *first=nullptr)
 
template<typename EventType >
void postEvent (EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
 
template<typename EventType >
void postEvent (const boost::intrusive_ptr< EventType > &evHolder, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
 
template<typename EventType >
void postEvent (EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
 
template<typename T >
bool getGlobalSMData (const std::string &name, T &ret)
 
template<typename T >
void setGlobalSMData (const std::string &name, T value)
 
std::string getStateMachineName ()
 
void state_machine_visualization ()
 
std::shared_ptr< SmaccStateInfo > getCurrentStateInfo ()
 
void publishTransition (const SmaccTransitionInfo &transitionInfo)
 
virtual void onInitialize ()
 this function should be implemented by the user to create the orthogonals
 
virtual void onUnhandledStInitializationFailure (const std::string &stateName, const std::string &what)
 
void getTransitionLogHistory (const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Request > req, std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Response > res)
 
template<typename TSmaccSignal , typename TMemberFunctionPrototype , typename TSmaccObjectType >
smacc2::SmaccSignalConnection createSignalConnection (TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
 
void disconnectSmaccSignalObject (void *object_ptr)
 
template<typename T >
std::enable_if_t< std::is_polymorphic< T >::value > disconnectSmaccSignalObject (T *object)
 
template<typename StateType >
void notifyOnStateEntryStart (StateType *state)
 
template<typename StateType >
void notifyOnStateEntryEnd (StateType *state)
 
template<typename StateType >
void notifyOnRuntimeConfigured (StateType *state)
 
template<typename StateType >
void notifyOnStateExiting (StateType *state)
 
template<typename StateType >
void notifyOnStateExited (StateType *state)
 
template<typename StateType >
void notifyOnRuntimeConfigurationFinished (StateType *state)
 
int64_t getCurrentStateCounter () const
 
ISmaccState * getCurrentState () const
 
const SmaccStateMachineInfo & getStateMachineInfo ()
 
template<typename InitialStateType >
void buildStateMachineInfo ()
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger ()
 
std::recursive_mutex & getMutex ()
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccStateMachine
void checkStateMachineConsistence ()
 
void initializeROS (const std::string &shortname)
 
void onInitialized ()
 
template<typename TOrthogonal >
void createOrthogonal ()
 
- Protected Attributes inherited from smacc2::ISmaccStateMachine
rclcpp::Node::SharedPtr nh_
 
rclcpp::TimerBase::SharedPtr timer_
 
rclcpp::Publisher< smacc2_msgs::msg::SmaccStateMachine >::SharedPtr stateMachinePub_
 
rclcpp::Publisher< smacc2_msgs::msg::SmaccStatus >::SharedPtr stateMachineStatusPub_
 
rclcpp::Publisher< smacc2_msgs::msg::SmaccTransitionLogEntry >::SharedPtr transitionLogPub_
 
rclcpp::Publisher< smacc2_msgs::msg::SmaccEvent >::SharedPtr eventsLogPub_
 
rclcpp::Service< smacc2_msgs::srv::SmaccGetTransitionHistory >::SharedPtr transitionHistoryService_
 
std::vector< ISmaccState * > currentState_
 
std::shared_ptr< SmaccStateInfo > currentStateInfo_
 
smacc2_msgs::msg::SmaccStatus status_msg_
 
std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > orthogonals_
 
std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo_
 

Detailed Description

template<typename DerivedStateMachine, typename InitialStateType>
struct smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >

State Machine.

Definition at line 30 of file smacc_state_machine_base.hpp.

Constructor & Destructor Documentation

◆ SmaccStateMachineBase()

template<typename DerivedStateMachine , typename InitialStateType >
smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::SmaccStateMachineBase ( my_context ctx,
SignalDetector * signalDetector,
const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions() )
inline

Definition at line 36 of file smacc_state_machine_base.hpp.

40 smacc2::utils::cleanShortTypeName<DerivedStateMachine>(), signalDetector, node_options),
42 DerivedStateMachine, InitialStateType, SmaccFifoScheduler, SmaccAllocator>(ctx)
43 {
44 }
ISmaccStateMachine(std::string stateMachineName, SignalDetector *signalDetector, const rclcpp::NodeOptions &nodeOptions=rclcpp::NodeOptions())
std::string cleanShortTypeName()
Definition common.hpp:69
boost::statechart::fifo_scheduler< SmaccFifoWorker, SmaccAllocator > SmaccFifoScheduler
std::allocator< boost::statechart::none > SmaccAllocator

◆ ~SmaccStateMachineBase()

template<typename DerivedStateMachine , typename InitialStateType >
virtual smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::~SmaccStateMachineBase ( )
inlinevirtual

Definition at line 46 of file smacc_state_machine_base.hpp.

46{}

Member Function Documentation

◆ eStop()

template<typename DerivedStateMachine , typename InitialStateType >
void smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::eStop ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccStateMachine.

Definition at line 61 of file smacc_state_machine_base.hpp.

62 {
64 this->terminate();
65 }

References smacc2::ISmaccStateMachine::eStop().

Here is the call graph for this function:

◆ initiate_impl()

template<typename DerivedStateMachine , typename InitialStateType >
void smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::initiate_impl ( )
inlineoverride

Definition at line 83 of file smacc_state_machine_base.hpp.

84 {
85 globalNh_ = this->getNode();
86
87 // this is before because this creates orthogonals
88 this->onInitialize();
89
90 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] Introspecting state machine via typeWalker");
92
93 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] initiate_impl");
94 auto shortname = smacc2::utils::cleanShortTypeName(typeid(DerivedStateMachine));
95
96 this->initializeROS(shortname);
97
98 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] Initializing ROS communication mechanisms");
99 this->onInitialized();
100
101 // publish startup state machine transition info
102 auto transitionInfo = std::make_shared<SmaccTransitionInfo>();
103 transitionInfo->destinyState = this->stateMachineInfo_->template getState<InitialStateType>();
104 this->publishTransition(*transitionInfo);
105
106 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] Initializing state machine");
107 sc::state_machine<DerivedStateMachine, InitialStateType, SmaccAllocator>::initiate();
108 }
void publishTransition(const SmaccTransitionInfo &transitionInfo)
rclcpp::Node::SharedPtr getNode()
virtual void onInitialize()
this function should be implemented by the user to create the orthogonals
void initializeROS(const std::string &shortname)
std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo_
rclcpp::Node::SharedPtr globalNh_

References smacc2::ISmaccStateMachine::buildStateMachineInfo(), smacc2::utils::cleanShortTypeName(), smacc2::ISmaccStateMachine::getLogger(), smacc2::ISmaccStateMachine::getNode(), smacc2::introspection::globalNh_, smacc2::ISmaccStateMachine::initializeROS(), smacc2::ISmaccStateMachine::onInitialize(), smacc2::ISmaccStateMachine::onInitialized(), smacc2::ISmaccStateMachine::publishTransition(), and smacc2::ISmaccStateMachine::stateMachineInfo_.

Here is the call graph for this function:

◆ reset()

template<typename DerivedStateMachine , typename InitialStateType >
void smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::reset ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccStateMachine.

Definition at line 48 of file smacc_state_machine_base.hpp.

49 {
51 this->terminate();
53 }
void run(ExecutionModel executionModel=ExecutionModel::SINGLE_THREAD_SPINNER)

References smacc2::ISmaccStateMachine::reset(), and smacc2::run().

Here is the call graph for this function:

◆ stop()

template<typename DerivedStateMachine , typename InitialStateType >
void smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::stop ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccStateMachine.

Definition at line 55 of file smacc_state_machine_base.hpp.

56 {
58 this->terminate();
59 }

References smacc2::ISmaccStateMachine::stop().

Here is the call graph for this function:

◆ unconsumed_event()

template<typename DerivedStateMachine , typename InitialStateType >
void smacc2::SmaccStateMachineBase< DerivedStateMachine, InitialStateType >::unconsumed_event ( const sc::event_base & ev)
inline

Definition at line 69 of file smacc_state_machine_base.hpp.

70 {
71 const auto * failure = dynamic_cast<const default_events::EvStInitializationFailureInfo *>(&ev);
72 if (failure == nullptr) return;
73 if (failure->escalate)
74 {
75 failure->escalate();
76 }
77 else
78 {
79 this->onUnhandledStInitializationFailure(failure->stateName, failure->what);
80 }
81 }
virtual void onUnhandledStInitializationFailure(const std::string &stateName, const std::string &what)

References smacc2::ISmaccStateMachine::onUnhandledStInitializationFailure().

Here is the call graph for this function:

The documentation for this struct was generated from the following file: