hsm.action_state.ActionState
- class ActionState(action, spec=None, goal=None, name=None, server_wait_timeout=10.0)
Bases:
Container
Simple action client state.
Use this class to represent an actionlib as a state in a state machine.
Constructor for ActionState action client wrapper.
@type action: actionlib.SimpleActionClient | string @param action: SimpleActionClient instance to use or name of ROS action to create a client for
@type spec: actionlib action msg @param spec: The type of action to which this client will connect.
@type goal: actionlib goal msg @param goal: If the goal for this action does not need to be generated at runtime, it can be passed to this state on construction.
@type server_wait_timeout: C{rospy.Duration} @param server_wait_timeout: This is the timeout used for aborting while waiting for an action server to become active.
The reported status (‘PENDING’,’ACTIVE’,’PREEMPTED’,’SUCCEEDED’,’ABORTED’,’REJECTED’,’LOST’) is dispatched as an HSM event. If the connection to the action server could not be established within the given timeout, a ‘TIMEOUT’ event is dispatched.
Methods
Add a new event callback.
Add a state to a state the container.
Add multiple states to the Container.
Add a transition from self to target_state
feedback_cb
get_active_states
get_initial_states
is_active
Check whether the state is a substate of self.
ros_subscribe
Set an initial state in a state machine.
Attributes
ACTIVE
EXITING
INACTIVE
PENDING
WAITING_FOR_SERVER
Get the history state of this
Container
.Get the initial state in a state machine.
Get the current leaf state.
Get the root state in a states hierarchy.
- add_handler(events, func, prepend=False)
Add a new event callback.
- Parameters:
trigger (str) – name of triggering event
func (callable) – callback function
- add_state(state, initial=False)
Add a state to a state the container.
If states are added, one (and only one) of them has to be declared as initial.
- add_states(*states)
Add multiple states to the Container.
- Parameters:
states – A list of states to be added
- add_transition(events, target_state, *args, **kwargs)
Add a transition from self to target_state
All callbacks take two arguments - state and event. See parameters description for details.
It is possible to create conditional if/elif/else-like logic for transitions. To do so, add many same transition rules with different condition callbacks. First met condition will trigger a transition, if no condition is met, no transition is performed.
- Parameters:
target_state (
State
, None) – Target state. If None, then it’s an internal transitionevents (
Iterable
ofHashable
) – List of events that trigger the transitioncondition (
Callable
) –Condition callback - if returns True transition may be initiated.
condition callback takes two arguments:
state: Leaf state before transition
event: Event that triggered the transition
action (
Callable
) –Action callback that is called during the transition after all states have been left but before the new one is entered.
action callback takes two arguments:
state: Leaf state before transition
event: Event that triggered the transition
before (
Callable
) –Action callback that is called right before the transition.
before callback takes two arguments:
state: Leaf state before transition
event: Event that triggered the transition
after (
Callable
) –Action callback that is called just after the transition
after callback takes two arguments:
state: Leaf state after transition
event: Event that triggered the transition
- property history_state
Get the history state of this
Container
.- Returns:
Leaf state in a hierarchical state machine
- Return type:
- property initial_state
Get the initial state in a state machine.
- Returns:
Initial state in a state machine
- Return type:
- is_substate(state)
Check whether the state is a substate of self.
Also self is considered a substate of self.
- property leaf_state
Get the current leaf state.
The
state
property gives the current, local state in a state machine. The leaf_state goes to the bottom in a hierarchy of states. In most cases, this is the property that should be used to get the current state in a state machine, even in a flat FSM, to keep the consistency in the code and to avoid confusion.- Returns:
Leaf state in a hierarchical state machine
- Return type:
- property root
Get the root state in a states hierarchy.
- Returns:
Root state in the states hierarchy
- Return type: