Back OperatorΒΆ
In this example, when the >back operator is triggered by Port3In in the
state WaitForExit, the state machine returns to the state that previously
transitioned into WaitForExit - either FlashPort1 or FlashPort2.
1from bpod_core.fsm import StateMachine
2
3fsm = StateMachine()
4
5fsm.add_state(
6 name='WaitForChoice',
7 transitions={'Port1_High': 'FlashPort1', 'Port2_High': 'FlashPort2'},
8)
9fsm.add_state(
10 name='FlashPort1',
11 timer=0.5,
12 transitions={'Tup': 'WaitForExit'},
13 actions={'PWM1': 255},
14)
15fsm.add_state(
16 name='FlashPort2',
17 timer=0.5,
18 transitions={'Tup': 'WaitForExit'},
19 actions={'PWM2': 255},
20)
21fsm.add_state(
22 name='WaitForExit',
23 transitions={
24 'Port1_High': '>exit',
25 'Port2_High': '>exit',
26 'Port3_High': '>back',
27 },
28)
1{
2 "states": {
3 "WaitForChoice": {
4 "transitions": {
5 "Port1_High": "FlashPort1",
6 "Port2_High": "FlashPort2"
7 }
8 },
9 "FlashPort1": {
10 "timer": 0.5,
11 "transitions": {
12 "Tup": "WaitForExit"
13 },
14 "actions": {
15 "PWM1": 255
16 }
17 },
18 "FlashPort2": {
19 "timer": 0.5,
20 "transitions": {
21 "Tup": "WaitForExit"
22 },
23 "actions": {
24 "PWM2": 255
25 }
26 },
27 "WaitForExit": {
28 "transitions": {
29 "Port1_High": ">exit",
30 "Port2_High": ">exit",
31 "Port3_High": ">back"
32 }
33 }
34 }
35}
1states:
2 WaitForChoice:
3 transitions:
4 Port1_High: FlashPort1
5 Port2_High: FlashPort2
6 FlashPort1:
7 timer: 0.5
8 transitions:
9 Tup: WaitForExit
10 actions:
11 PWM1: 255
12 FlashPort2:
13 timer: 0.5
14 transitions:
15 Tup: WaitForExit
16 actions:
17 PWM2: 255
18 WaitForExit:
19 transitions:
20 Port1_High: '>exit'
21 Port2_High: '>exit'
22 Port3_High: '>back'