Getting started with UML state machines#
-
Start by choosing a modeling tool. For your first steps, ⬇️ download the integrated editor and the code generator, then follow the editor tutorials. For larger projects and model-based workflows (from use cases to architecture and detailed design), a full modeling tool is recommended, for example Enterprise Architect or UModel. You can find more options on the supported tools overview. A good tool in between is the Cadifra UML editor.
-
Use a ready-made project available for different modeling tools and programming languages from our GitHub page. Make sure you have a recent Java Runtime Environment (17 or newer), compiler, and make tool. Download the codegen and unpack the zip file. Then build the example by calling
make(don’t forget to export the path variableCODEGEN_PATHto reflect your codegen installation folder). Example:export CODEGEN_PATH=/home/myusername/develop/sinelaboreRT7.1/bin/ -
Run the example and play with it. Inspect the generated API files first. Start with the event definitions (
*_ext.h) and the state handler interface, understand how those calls map into application code. The handler signature and many aspects of the generated code can be adjusted with the help of a configuration file. -
Create your own example. Start with something small. Identify the events and states of your model. Integrate the state machine into your main loop or scheduler. Feed events into the machine, call the generated handler in a run-to-completion style, and avoid blocking actions (see examples using RTOS or a foreground/background architecture).
-
Enable debug output or trace code early and validate transitions with known event sequences. Verify entry/exit order, self-transitions, and history behavior before scaling the model.
-
Grow the model incrementally. Add one feature at a time (choices, junctions, regions), regenerate, and re-test to avoid hard-to-debug regressions.