Skip to main content

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

  1. Get the location of the examples: python -m pip show hierarchical_state_machine
  2. Go to the example folder: cd <site-packages>/hierarchical_state_machine/example/pedestrian_crosswalk/
  3. Look at the state machine diagram: hierarchical_example_pedestrian_crosswalk_signaler.pdf
  4. Execute and follow along: python crosswalk_light_simulator.py
  5. Press the b button to request a crossing.
  6. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hierarchical_state_machine-1.0.16.tar.gz (76.7 kB view hashes)

Uploaded Source

Built Distribution

hierarchical_state_machine-1.0.16-py3-none-any.whl (75.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page