Python YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin.state.State Class Reference
Inheritance diagram for yasmin.state.State:
Collaboration diagram for yasmin.state.State:

Public Member Functions

None __init__ (self, Set[str] outcomes)
 
str __call__ (self, Blackboard blackboard=None)
 
str execute (self, Blackboard blackboard)
 
str __str__ (self)
 
None cancel_state (self)
 
bool is_canceled (self)
 
bool is_running (self)
 
Set[str] get_outcomes (self)
 

Protected Attributes

Set _outcomes = set()
 A set of valid outcomes for this state.
 
bool _running = False
 A flag indicating whether the state is currently running.
 
bool _canceled = False
 A flag indicating whether the state has been canceled.
 

Detailed Description

Abstract base class representing a state in a state machine.

This class provides a framework for creating specific states with defined outcomes.
Subclasses must implement the `execute` method to define the state-specific behavior.

Attributes:
    _outcomes (Set[str]): A set of valid outcomes for this state.
    _running (bool): A flag indicating whether the state is currently running.
    _canceled (bool): A flag indicating whether the state has been canceled.

Constructor & Destructor Documentation

◆ __init__()

None yasmin.state.State.__init__ ( self,
Set[str] outcomes )

Member Function Documentation

◆ __call__()

str yasmin.state.State.__call__ ( self,
Blackboard blackboard = None )
Executes the state and returns the outcome.

This method sets the state as running, executes the state's behavior,
and validates the outcome against the allowed outcomes.

:param blackboard: An optional Blackboard instance that can be used during execution.
                   If None, a new Blackboard instance will be created.
:return: The outcome of the state execution.
:raises ValueError: If the outcome is not one of the valid outcomes for this state.

◆ __str__()

str yasmin.state.State.__str__ ( self)
Returns the string representation of the state.

:return: The name of the class representing the state.

Reimplemented in yasmin.state_machine.StateMachine.

◆ cancel_state()

None yasmin.state.State.cancel_state ( self)
Cancels the execution of the state.

Sets the _canceled flag to True and logs the cancellation.

Reimplemented in yasmin.state_machine.StateMachine, and yasmin_ros.action_state.ActionState.

◆ execute()

str yasmin.state.State.execute ( self,
Blackboard blackboard )
Executes the specific behavior of the state.

This method must be implemented by subclasses to define what happens
when the state is executed.

:param blackboard: An instance of Blackboard that provides the context for execution.
:return: The outcome of the execution as a string.
:raises NotImplementedError: If not implemented in a subclass.

Reimplemented in yasmin.cb_state.CbState, yasmin.state_machine.StateMachine, yasmin_demos.yasmin_demo.BarState, yasmin_demos.yasmin_demo.FooState, yasmin_ros.action_state.ActionState, yasmin_ros.monitor_state.MonitorState, and yasmin_ros.service_state.ServiceState.

◆ get_outcomes()

Set[str] yasmin.state.State.get_outcomes ( self)
Gets the valid outcomes for this state.

:return: A set of valid outcomes as strings.

◆ is_canceled()

bool yasmin.state.State.is_canceled ( self)
Checks if the state has been canceled.

:return: True if the state is canceled, False otherwise.

◆ is_running()

bool yasmin.state.State.is_running ( self)
Checks if the state is currently running.

:return: True if the state is running, False otherwise.

Member Data Documentation

◆ _canceled

bool yasmin.state.State._canceled = False
protected

A flag indicating whether the state has been canceled.

◆ _outcomes

Set yasmin.state.State._outcomes = set()
protected

A set of valid outcomes for this state.

◆ _running

bool yasmin.state.State._running = False
protected

A flag indicating whether the state is currently running.


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