ROS 状态机 SMACH 概述与基本概念

1.About SMACH

Smach, which stands for “State Machine”, is a powerful and scalable Python-based library for hierarchical state machines.


When should I use SMACH?
SMACH is useful when you want a robot to execute some complex plan, and all possible states and state transitions can be described explicitly.
When should I NOT use SMACH?

Unstructured tasks: SMACH will fall short as the scheduling of your
task becomes less structured.
Low-level systems: SMACH is not meant to be used as a state machine for low-level systems that require high efficiency, SMACH is a task-level architecture.
Smash: Do not use SMACH when you want to smash something.

2.Concepts

2.1 Outcome Semantics

Outcomes simply acts as a common interface between states and containers.
A state’s potential outcomes are a property of the state instance, and must be declared before it is executed.

2.2 User Data

SMACH containers each have a flat database used to coordinate and pass data between different states. This allows such data to be held at the execution level, and made available to other tasks or procedures.
Similarly to outcomes, the userdata keys that are set and retrieved in each state are described by the state’s input keys and output keys. These are also a property of the state instance, and must be declared prior to execution.
For information on the user data API see Manipulating Userdata in SMACH.

2.3 Preemption

This allows the system to both cleanly respond to termination signals from an end user and be able to be canceled programmatically by a higher-level executive.

2.4 Introspection

SMACH containers can provide a debugging interface which allows a developer to (over ROS) set the full initial state of a SMACH tree. You can visualize it with the SMACH Viewer.

3.States

In SMACH, a “state” is a local state of execution, or equivalently a “state” corresponds to the system performing some task.

3.1 Provided State Classes

Class Description Outcomes
State State base interface. None
SPAState A state which has three commonly used pre-defined outcomes. succeeded, preempted, aborted
MonitorState A state that subscribes to a ROS topic and blocks while a condition holds. valid, invalid, preempted
ConditionState A state that executes a condition callback. true, false
SimpleActionState A state which acts as a proxy to a simple actionlib action. succeeded, preempted, aborted

4.Containers

All SMACH containers have the following properties:

1.They contain a dictionary of states where objects implementing the smach.State interface are keyed by string labels.
2.They contain a userdata structure that all of their children can access.
3. In order to modify the structure of a container, it must be opened (see below).

猜你喜欢

转载自blog.csdn.net/qq_36764147/article/details/80202718