Struct StateMachine

Inheritance Relationships

Base Type

  • public boost::statechart::asynchronous_state_machine< StateMachine, Standby, bsc::fifo_scheduler<>, std::allocator< void >, bsc::exception_translator<> >

Struct Documentation

struct mimir::StateMachine : public boost::statechart::asynchronous_state_machine<StateMachine, Standby, bsc::fifo_scheduler<>, std::allocator<void>, bsc::exception_translator<>>

State machine for the algorithm.

The core program logic is implemented an asynchronous state machine. The state diagram below describes it. Its main purpose is to call the functions of an IAlgorithm implementation according to a set pattern.

!include ../static/style.puml
skinparam backgroundColor white
[*] -> Standby : DdsTriad(..)

state Standby
state ShutDown
ShutDown: entry / post(EvKill)
ShutDown: exit / terminate()
state Running {
state Initializing
state Evaluating
state Waiting
[*] -do-> Initializing : AlgorithmCreator(..)


}
Standby -do-> Running : EvStart
Standby -ri-> ShutDown : EvKill
Standby -up-> Standby : EvTimeout
ShutDown --> [*] : EvKill
Running -up-> Standby : EvStop || EvInterrupt
Running -do-> ShutDown : EvKill || EvError || exception_thrown
Initializing : entry / algorithm->initialize(..)
Initializing -do-> Evaluating : EvReady
Evaluating --> Waiting : EvReady
Evaluating : entry / algorithm->solve(..)
Waiting -do-> Evaluating : EvTimeout
Waiting : entry / algorithm->timer(..)

Public Functions

StateMachine(my_context ctx, const YAML::Node &config, std::atomic<bool> &notify_others)

Constructor for state machine.

The constructor creates instances of DDS-related stuff, such as

  • DdsTriad : Initialized domain participant with publisher and subscriber instances.

  • CommandResponder : Class for interacting with other programs via DDS.

  • StateNotifier : Class that notifies subscribers of which state the state machine is in.

Parameters
  • ctx[in] Context construct needed for the asynchronous state machine

  • config[in] YAML config, user provided configuration file

  • notify_others[in] Reference to external boolean for inter-thread notification of living state machine.

~StateMachine()

Destructor.

DdsTriad *Dds()

Pointer to the DdsTriad.

inline control::StateNotifier *Notifier()

Pointer to the StateNotifier.

inline const YAML::Node &Config()

Reference to YAML configuration.

Private Members

std::unique_ptr<DdsTriad> m_dds

Instance of participant, publisher and subscriber.

std::unique_ptr<control::CommandResponder> m_responder
std::unique_ptr<control::StateNotifier> m_notifier
std::atomic<bool> &m_notify_others

External boolean to notify others of terminated state machine.

const YAML::Node m_config

YAML configuration for state machine and algorithm.