|
C++ YASMIN (Yet Another State MachINe)
|
Represents a state in a state machine. More...
#include <state.hpp>


Public Member Functions | |
| State (const Outcomes &outcomes) | |
| Shared pointer type for State. | |
| virtual | ~State () |
| Virtual destructor. | |
| Blackboard::SharedPtr | get_parameters_blackboard () const |
| Gets the private parameter blackboard of this state. | |
| bool | is_idle () const noexcept |
| Checks if the state is idle. | |
| bool | is_running () const noexcept |
| Checks if the state is currently running. | |
| bool | is_canceled () const noexcept |
| Checks if the state has been canceled. | |
| bool | is_completed () const noexcept |
| Checks if the state has completed execution. | |
| std::string | operator() (Blackboard::SharedPtr blackboard) |
| Executes the state and returns the outcome. | |
| virtual std::string | execute (Blackboard::SharedPtr blackboard) |
| Executes the state's specific logic. | |
| virtual void | configure () |
| Configures the state before execution. | |
| virtual void | cancel_state () |
| Cancels the current state execution. | |
| Outcomes const & | get_outcomes () const noexcept |
| Gets the set of possible outcomes for this state. | |
| void | set_description (const std::string &description) |
| Sets the description for this state. | |
| const std::string & | get_description () const |
| Gets the description of this state. | |
| void | set_outcome_description (const std::string &outcome, const std::string &description) |
| Sets a human-readable description for an outcome. | |
| const std::string & | get_outcome_description (const std::string &outcome) const |
| Gets the human-readable description for an outcome. | |
| const std::unordered_map< std::string, std::string > & | get_outcome_descriptions () const |
| Gets all outcome descriptions. | |
| void | add_input_key (const BlackboardKeyInfo &key_info) |
| Adds an input key to the state's metadata. | |
| void | add_input_key (const std::string &key_name) |
| Adds an input key with a name only. | |
| void | add_input_key (const std::string &key_name, const std::string &description) |
| Adds an input key with a name and description. | |
| template<typename T> | |
| void | add_input_key (const std::string &key_name, const std::string &description, T default_value) |
| Adds an input key with a name, default value and description. | |
| void | add_output_key (const BlackboardKeyInfo &key_info) |
| Adds an output key to the state's metadata. | |
| void | add_output_key (const std::string &key_name) |
| Adds an output key with a name only. | |
| void | add_output_key (const std::string &key_name, const std::string &description) |
| Adds an output key with a name and description. | |
| const std::vector< BlackboardKeyInfo > & | get_input_keys () const |
| Gets the input keys metadata. | |
| const std::vector< BlackboardKeyInfo > & | get_output_keys () const |
| Gets the output keys metadata. | |
| void | declare_parameter (const BlackboardKeyInfo ¶meter_info) |
| Declares a parameter in the state metadata. | |
| void | declare_parameter (const std::string ¶meter_name) |
| Declares a parameter with a name only. | |
| void | declare_parameter (const std::string ¶meter_name, const std::string &description) |
| Declares a parameter with a name and description. | |
| template<typename T> | |
| void | declare_parameter (const std::string ¶meter_name, const std::string &description, T default_value) |
| Declares a parameter with a name, description, and default value. | |
| bool | has_parameter (const std::string ¶meter_name) const |
| Checks if a parameter exists in the state-local parameter storage. | |
| template<typename T> | |
| T | get_parameter (const std::string ¶meter_name) const |
| Gets a parameter from the state-local parameter storage. | |
| template<typename T> | |
| void | set_parameter (const std::string ¶meter_name, T value) |
| Sets a parameter in the state-local parameter storage. | |
| bool | is_parameter_declared (const std::string ¶meter_name) const |
| Checks whether a parameter was declared in the state metadata. | |
| void | copy_parameter_from (const State &source_state, const std::string &source_parameter_name, const std::string &target_parameter_name) |
| Copies a parameter value from another state. | |
| const std::vector< BlackboardKeyInfo > & | get_parameters () const |
| Gets the declared parameter metadata. | |
| const StateMetadata & | get_metadata () const |
| Gets the complete state metadata. | |
| virtual std::string | to_string () const |
| Converts the state to a string representation. | |
Protected Attributes | |
| Outcomes | outcomes |
| The possible outcomes of this state. | |
Private Member Functions | |
| StateMetadata & | get_metadata_ref () const |
| Gets a mutable reference to this state's metadata. | |
| void | set_status (StateStatus new_status) |
| Sets the current status of the state. | |
| StateStatus | get_status () const |
| Gets the current status of the state. | |
Private Attributes | |
| std::atomic< StateStatus > | status {StateStatus::IDLE} |
| Current status of the state. | |
Represents a state in a state machine.
The State class defines a state that can execute actions and manage outcomes. It maintains information about its execution status and the possible outcomes of its execution.
| State::State | ( | const Outcomes & | outcomes | ) |
|
virtual |
Virtual destructor.
Cleans up externally-stored metadata for this instance.
| void State::add_input_key | ( | const BlackboardKeyInfo & | key_info | ) |
Adds an input key to the state's metadata.
| key_info | Information about the input key. |
| void State::add_input_key | ( | const std::string & | key_name | ) |
Adds an input key with a name only.
| key_name | The name of the input key. |
| void State::add_input_key | ( | const std::string & | key_name, |
| const std::string & | description ) |
Adds an input key with a name and description.
| key_name | The name of the input key. |
| description | Human-readable description of the input key. |
|
inline |
Adds an input key with a name, default value and description.
| T | The type of the default value. |
| key_name | The name of the input key. |
| description | Human-readable description of the input key. |
| default_value | The default value for the key. |
| void State::add_output_key | ( | const BlackboardKeyInfo & | key_info | ) |
Adds an output key to the state's metadata.
| key_info | Information about the output key. |
| void State::add_output_key | ( | const std::string & | key_name | ) |
Adds an output key with a name only.
| key_name | The name of the output key. |
| void State::add_output_key | ( | const std::string & | key_name, |
| const std::string & | description ) |
Adds an output key with a name and description.
| key_name | The name of the output key. |
| description | Human-readable description of the output key. |
|
inlinevirtual |
Cancels the current state execution.
This method sets the status to CANCELED and logs the action.
Reimplemented in yasmin::Concurrence, yasmin::PyState, yasmin::StateMachine, yasmin_ros::ActionState< ActionT >, yasmin_ros::ActionState< Fibonacci >, yasmin_ros::MonitorState< MsgT >, and yasmin_ros::MonitorState< nav_msgs::msg::Odometry >.
|
inlinevirtual |
Configures the state before execution.
This method can be overridden by derived classes to allocate resources, validate configuration, or initialize internal state. The default implementation does nothing.
Reimplemented in ConfigurableConcurrentState, ConfigurableLeafState, yasmin::Concurrence, yasmin::PyState, yasmin::StateMachine, yasmin_ros::RosDeserializeCppState, yasmin_ros::RosSerializeCppState, and yasmin_ros::TfBufferState.
| void State::copy_parameter_from | ( | const State & | source_state, |
| const std::string & | source_parameter_name, | ||
| const std::string & | target_parameter_name ) |
Copies a parameter value from another state.
| source_state | The source state. |
| source_parameter_name | The parameter name in the source state. |
| target_parameter_name | The parameter name in this state. |
| void State::declare_parameter | ( | const BlackboardKeyInfo & | parameter_info | ) |
Declares a parameter in the state metadata.
| parameter_info | Information about the parameter. |
| void State::declare_parameter | ( | const std::string & | parameter_name | ) |
Declares a parameter with a name only.
| parameter_name | The name of the parameter. |
| void State::declare_parameter | ( | const std::string & | parameter_name, |
| const std::string & | description ) |
Declares a parameter with a name and description.
| parameter_name | The name of the parameter. |
| description | Human-readable description of the parameter. |
|
inline |
Declares a parameter with a name, description, and default value.
| T | The type of the default value. |
| parameter_name | The name of the parameter. |
| description | Human-readable description of the parameter. |
| default_value | The default value for the parameter. |
|
inlinevirtual |
Executes the state's specific logic.
| blackboard | A shared pointer to the Blackboard to use during execution. |
This method is intended to be overridden by derived classes to provide specific execution logic.
Reimplemented in BarState, BarState, BarState, BarState, BarState, BarState, BarState, BlockingWriteState, ConfigurableConcurrentState, ConfigurableLeafState, DelayedStartStateMachine, FooState, FooState, FooState, FooState, FooState, FooState, FooState, StateWithAllTypes, StateWithDefaults, yasmin::CbState, yasmin::Concurrence, yasmin::PyState, yasmin::StateMachine, yasmin_ros::ActionState< ActionT >, yasmin_ros::ActionState< Fibonacci >, yasmin_ros::GetParametersState, yasmin_ros::MonitorState< MsgT >, yasmin_ros::MonitorState< nav_msgs::msg::Odometry >, yasmin_ros::PublisherState< MsgT >, yasmin_ros::PublisherState< std_msgs::msg::Int32 >, yasmin_ros::RosDeserializeCppState, yasmin_ros::RosSerializeCppState, yasmin_ros::ServiceState< ServiceT >, yasmin_ros::ServiceState< example_interfaces::srv::AddTwoInts >, and yasmin_ros::TfBufferState.
| const std::string & State::get_description | ( | ) | const |
Gets the description of this state.
| const std::vector< BlackboardKeyInfo > & State::get_input_keys | ( | ) | const |
Gets the input keys metadata.
| const StateMetadata & State::get_metadata | ( | ) | const |
Gets the complete state metadata.
|
private |
Gets a mutable reference to this state's metadata.
Metadata is stored externally (not as a direct member) to preserve ABI compatibility with plugins compiled against earlier versions of the State class.
| const std::string & State::get_outcome_description | ( | const std::string & | outcome | ) | const |
Gets the human-readable description for an outcome.
| outcome | The outcome name. |
| std::invalid_argument | If the outcome is not part of this state. |
| const std::unordered_map< std::string, std::string > & State::get_outcome_descriptions | ( | ) | const |
Gets all outcome descriptions.
|
noexcept |
Gets the set of possible outcomes for this state.
| const std::vector< BlackboardKeyInfo > & State::get_output_keys | ( | ) | const |
Gets the output keys metadata.
|
inline |
Gets a parameter from the state-local parameter storage.
| T | The parameter type. |
| parameter_name | The parameter name. |
| const std::vector< BlackboardKeyInfo > & State::get_parameters | ( | ) | const |
Gets the declared parameter metadata.
| Blackboard::SharedPtr State::get_parameters_blackboard | ( | ) | const |
Gets the private parameter blackboard of this state.
This is primarily exposed for internal framework use and Python bindings.
|
private |
Gets the current status of the state.
| bool State::has_parameter | ( | const std::string & | parameter_name | ) | const |
Checks if a parameter exists in the state-local parameter storage.
| parameter_name | The parameter name. |
|
noexcept |
Checks if the state has been canceled.
|
noexcept |
Checks if the state has completed execution.
|
noexcept |
Checks if the state is idle.
| bool State::is_parameter_declared | ( | const std::string & | parameter_name | ) | const |
Checks whether a parameter was declared in the state metadata.
| parameter_name | The parameter name. |
|
noexcept |
Checks if the state is currently running.
| std::string State::operator() | ( | Blackboard::SharedPtr | blackboard | ) |
Executes the state and returns the outcome.
| blackboard | A shared pointer to the Blackboard to use during execution. |
This function stores the state as running, invokes the execute method, and checks if the returned outcome is valid. If the outcome is not valid, a std::logic_error is thrown.
| std::logic_error | If the outcome is not in the set of outcomes. |
| void State::set_description | ( | const std::string & | description | ) |
Sets the description for this state.
| description | The description of the state. |
| void State::set_outcome_description | ( | const std::string & | outcome, |
| const std::string & | description ) |
Sets a human-readable description for an outcome.
| outcome | The outcome name. |
| description | The description of the outcome. |
| std::invalid_argument | If the outcome is not part of this state. |
|
inline |
Sets a parameter in the state-local parameter storage.
| T | The parameter type. |
| parameter_name | The parameter name. |
| value | The parameter value. |
|
private |
Sets the current status of the state.
| new_status | The new status to set. |
|
virtual |
Converts the state to a string representation.
This method retrieves the demangled name of the class for a readable string representation.
Reimplemented in yasmin::Concurrence, yasmin::PyState, and yasmin::StateMachine.
|
protected |
The possible outcomes of this state.
|
private |
Current status of the state.