mc_control::fsm::State Class Referenceabstract

#include <mc_control/fsm/State.h>

Inheritance diagram for mc_control::fsm::State:
Collaboration diagram for mc_control::fsm::State:

Public Member Functions

virtual ~State ()
 
void configure_ (const mc_rtc::Configuration &config)
 
void start_ (Controller &ctl)
 
void teardown_ (Controller &ctl)
 
virtual bool run (Controller &ctl)=0
 
virtual void stop (Controller &)
 
virtual bool read_msg (std::string &)
 
virtual bool read_write_msg (std::string &, std::string &)
 
const std::string & output () const noexcept
 
const std::string & name ()
 
void name (const std::string &n)
 

Protected Member Functions

void output (const std::string &o)
 
virtual void configure (const mc_rtc::Configuration &config)
 
virtual void start (Controller &ctl)=0
 
virtual void teardown (Controller &ctl)=0
 

Protected Attributes

mc_rtc::Configuration add_contacts_config_
 
mc_rtc::Configuration remove_contacts_config_
 
mc_rtc::Configuration add_contacts_after_config_
 
mc_rtc::Configuration remove_contacts_after_config_
 
mc_rtc::Configuration add_collisions_config_
 
mc_rtc::Configuration remove_collisions_config_
 
mc_rtc::Configuration add_collisions_after_config_
 
mc_rtc::Configuration remove_collisions_after_config_
 
mc_rtc::Configuration constraints_config_
 
mc_rtc::Configuration tasks_config_
 
mc_rtc::Configuration remove_posture_task_
 
mc_rtc::Configuration config_
 
std::vector< mc_solver::ConstraintSetPtrconstraints_
 
std::vector< std::pair< mc_tasks::MetaTaskPtr, mc_rtc::Configuration > > tasks_
 
std::vector< mc_tasks::PostureTaskPtrpostures_
 

Detailed Description

A state of an FSM.

A state implementation should create, add and remove the tasks/constraints it needs, with the following exceptions:

  • Contacts are handled at the global level, the state should go through the addContact/removeContact methods of FSMController
  • Collision constraints are handled at the global level, the state should go through the addCollisons/removeCollisions methods of Controller
  • Kinematics/Dynamics constraints are handled at the global level
  • Posture tasks are handled at the global level, if a state removes a posture task from the solver, it should put it back afterwards

Notably, a state should not keep constraints or tasks it created active after the state finished its execution.

Every methods can be called in a real-time context. You should be aware of that, especially if you plan to have threads in your state (e.g. monitoring a ROS topic, waiting for data on the network...) then you should be especially careful when your state is destroyed.

The life-span of a state is:

  • the state is constructed and init is called (iteration 0)
  • run(...) is called until it returns true (iteration 1 to N)
  • teardown(...) is called and the state is destructed (iteration N, after run last call)

The state might be interrupted (e.g. emergency behaviour triggered) in which case, stopped(...) will be called. The default implementation does nothing as teardown(...) is called anyway.

Constructor & Destructor Documentation

◆ ~State()

virtual mc_control::fsm::State::~State ( )
inlinevirtual

Member Function Documentation

◆ configure()

virtual void mc_control::fsm::State::configure ( const mc_rtc::Configuration config)
protectedvirtual

Called to configure the state.

This is called multiple times:

  • once for every level of state inheritance
  • once with the executor configuration, this is the FSM global executor, the Meta state executor, the Parallel state or any state that handle other states

The default implementation simply loads the provided configuration into the config_ protected members. You can override this behavior to implement a more complex loading logic.

You can access this configuration either via the config_ variable

Reimplemented in mc_control::fsm::MetaTasksState, mc_control::fsm::StabilizerStandingState, mc_control::fsm::PauseState, mc_control::fsm::MessageState, mc_control::fsm::PostureState, and mc_control::fsm::PythonState.

◆ configure_()

void mc_control::fsm::State::configure_ ( const mc_rtc::Configuration config)

Common implementation, handles the following options:

  • AddContacts/RemoveContacts: add and remove contacts during the state's start
  • AddContactsAfter/RemoveContactsAfter: add and remove contacts during the state's teardown
  • AddCollisions/RemoveCollisions: add and remove collisions during the state's start
  • AddCollisionsAfter/RemoveCollisionsAfter: add and remove collisions during the state's teardown
  • RemovePostureTask: if true, remove the robot posture task at the state's start

◆ name() [1/2]

const std::string& mc_control::fsm::State::name ( )
inline

Returns the name of the state

◆ name() [2/2]

void mc_control::fsm::State::name ( const std::string &  n)
inline

◆ output() [1/2]

const std::string& mc_control::fsm::State::output ( ) const
inlinenoexcept

Returns the output of the state, should only be consulted once run has returned true

◆ output() [2/2]

void mc_control::fsm::State::output ( const std::string &  o)
inlineprotected

Output setter for derived classes

◆ read_msg()

virtual bool mc_control::fsm::State::read_msg ( std::string &  )
inlinevirtual

Handle read service call

Reimplemented in mc_control::fsm::ParallelState, and mc_control::fsm::MetaState.

◆ read_write_msg()

virtual bool mc_control::fsm::State::read_write_msg ( std::string &  ,
std::string &   
)
inlinevirtual

Handle read/write service call

Reimplemented in mc_control::fsm::ParallelState.

◆ run()

◆ start()

◆ start_()

void mc_control::fsm::State::start_ ( Controller ctl)

Common implementation, takes care of common options

◆ stop()

virtual void mc_control::fsm::State::stop ( Controller )
inlinevirtual

Called if the state is interrupted

Reimplemented in mc_control::fsm::PythonState, mc_control::fsm::ParallelState, and mc_control::fsm::MetaState.

◆ teardown()

◆ teardown_()

void mc_control::fsm::State::teardown_ ( Controller ctl)

Common implementation, takes care of common options

Member Data Documentation

◆ add_collisions_after_config_

mc_rtc::Configuration mc_control::fsm::State::add_collisions_after_config_
protected

AddCollisionsAfter in the configuration

◆ add_collisions_config_

mc_rtc::Configuration mc_control::fsm::State::add_collisions_config_
protected

AddCollisions in the configuration

◆ add_contacts_after_config_

mc_rtc::Configuration mc_control::fsm::State::add_contacts_after_config_
protected

AddContactsAfter in the configuration

◆ add_contacts_config_

mc_rtc::Configuration mc_control::fsm::State::add_contacts_config_
protected

AddContacts in the configuration

◆ config_

mc_rtc::Configuration mc_control::fsm::State::config_
protected

Configuration obtained through several calls

◆ constraints_

std::vector<mc_solver::ConstraintSetPtr> mc_control::fsm::State::constraints_
protected

Constraints managed by the state if any

◆ constraints_config_

mc_rtc::Configuration mc_control::fsm::State::constraints_config_
protected

constraints in the configuration

◆ postures_

std::vector<mc_tasks::PostureTaskPtr> mc_control::fsm::State::postures_
protected

Posture tasks that were removed by this state

◆ remove_collisions_after_config_

mc_rtc::Configuration mc_control::fsm::State::remove_collisions_after_config_
protected

RemoveCollisionsAfter in the configuration

◆ remove_collisions_config_

mc_rtc::Configuration mc_control::fsm::State::remove_collisions_config_
protected

RemoveCollisions in the configuration

◆ remove_contacts_after_config_

mc_rtc::Configuration mc_control::fsm::State::remove_contacts_after_config_
protected

RemoveContactsAfter in the configuration

◆ remove_contacts_config_

mc_rtc::Configuration mc_control::fsm::State::remove_contacts_config_
protected

RemoveContacts in the configuration

◆ remove_posture_task_

mc_rtc::Configuration mc_control::fsm::State::remove_posture_task_
protected

RemovePostureTask in the configuration

◆ tasks_

std::vector<std::pair<mc_tasks::MetaTaskPtr, mc_rtc::Configuration> > mc_control::fsm::State::tasks_
protected

Tasks managed by the state if any

◆ tasks_config_

mc_rtc::Configuration mc_control::fsm::State::tasks_config_
protected

tasks in the configuration


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