This python library provides an easy-to-learn and easy-to-use API for using Hierarchical State Machines in your project. The state machine is defined using a basic JSON string, and includes convenience timers.
Project description
Crystal Clear Design's Hierarchical State Machine for Python
hierarchical_state_machine
This python library provides an easy-to-learn and easy-to-use API for using Hierarchical State Machines in your project. The state machine is defined using a basic JSON string, and includes convenience timers.
Simplest Example
The Blinky Light
Countdown Example
Fireworks
A More Involved Example
A Hierarchical State Machine Implementing a Simple Crosswalk Controller
- Get the location of the examples:
python -m pip show hierarchical_state_machine
- Go to the example folder:
cd <site-packages>/hierarchical_state_machine/example/pedestrian_crosswalk/
- Look at the state machine diagram:
hierarchical_example_pedestrian_crosswalk_signaler.pdf
- Execute and follow along:
python crosswalk_light_simulator.py
- Press the
b
button to request a crossing. - Press the
Esc
button to exit the simulation.
A Tutorial
Here are details about creating a hierarchical state machine in python.
Components of a State Machine
--Events - Are user inputs, timeouts, code-generated, or an output of another state machine. --States - A state machine waits in a state until an event or condition causes a transition to another state. --Transitions - Are paths gated by events and/or conditions, to go to another state. --Actions - Are behaviors (i.e. callbacks) evoked as a side-effect of a transition.
Creating a State
Each state contains the following optional elements: entry A list of callback functions that will be invoked each time the state is entered. exit A list of callback functions that will be invoked each time the state is exited. tran A list of transitions which will be followed when conditions are met.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for hierarchical_state_machine-1.0.16.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc3fa0f4c32bf4de3ba9a1df9c8102d92e1192409efdc91f375584b75050dd8b |
|
MD5 | ac20ac38c6ee33a38c20de0088cd646e |
|
BLAKE2b-256 | 27abd2d11aa5513211ea0e5d04df6e58264edbc65f37e0fe1e682afe0720fb4f |
Hashes for hierarchical_state_machine-1.0.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9afff9eafc8730d2b2bec6ff6a28f0f972ad7ba3fb5e3c2223e10fc8115e521 |
|
MD5 | 65a87d17046e5941b17171b32aed3c41 |
|
BLAKE2b-256 | cb07c423886bec152eb2f2a4c14f46ab3a8aa05100c1c0276a3681fddb4f9633 |