I am using PyTransitions to generate a simple FSM, configuring it using a yml file. An example could be something like this:
initial: A
states:
- A
- B
- C
transitions:
- {trigger: "AtoC", source: "A", dest: "C"}
- {trigger: "CtoB", source: "C", dest: "B"}
My question is, using the yml file, how do I write in state outputs? For example, at state A turn on LED 1, state B turn on LED2, state C turn on LED1 and 2. I can't find any documentation for it in the PyTransitions page.
There is no dedicated output slot for states but you can use
transitionsto trigger certain actions when a state is entered or left. Actions can be done in callbacks. Those actions need to be implemented in the model. If you want to do most things via configurations you can customizeMachineand the usedStateclass. For instance, you could create a customLEDStateand assign a value array calledled_statesto it where each value represents a LED state. The array is applied to the LEDs in theafter_state_changecallback of the Model that is calledupdate_leds:This is just one way how this could be done. You could also just pass an array with indexes representing all LEDs that should be
ON. We'd switch off all LEDs when exiting a state withbefore_state_change