Global CountersΒΆ
A global counter ends an infinite loop when 5 Port1In events occur. Port1In events acquired in the first state are deliberately not counted.
1from bpod_core.fsm import StateMachine
2
3fsm = StateMachine()
4
5fsm.set_global_counter(
6 index=0,
7 event='Port1High',
8 threshold=5,
9)
10
11fsm.add_state(
12 name='InitialDelay',
13 timer=2,
14 transitions={'Tup': 'ResetGlobalCounter'},
15 actions={'PWM2': 255},
16)
17fsm.add_state(
18 name='ResetGlobalCounter',
19 transitions={'Tup': 'Port1Light'},
20 actions={'GlobalCounterReset': 0},
21)
22fsm.add_state(
23 name='Port1Light',
24 timer=0.25,
25 transitions={
26 'Tup': 'Port3Light',
27 'GlobalCounter0_End': '>exit',
28 },
29 actions={'PWM1': 255},
30)
31fsm.add_state(
32 name='Port3Light',
33 timer=0.25,
34 transitions={
35 'Tup': 'Port1Light',
36 'GlobalCounter0_End': '>exit',
37 },
38 actions={'PWM3': 255},
39)
1{
2 "states": {
3 "InitialDelay": {
4 "timer": 2.0,
5 "transitions": {
6 "Tup": "ResetGlobalCounter"
7 },
8 "actions": {
9 "PWM2": 255
10 }
11 },
12 "ResetGlobalCounter": {
13 "transitions": {
14 "Tup": "Port1Light"
15 },
16 "actions": {
17 "GlobalCounterReset": 0
18 }
19 },
20 "Port1Light": {
21 "timer": 0.25,
22 "transitions": {
23 "Tup": "Port3Light",
24 "GlobalCounter0_End": ">exit"
25 },
26 "actions": {
27 "PWM1": 255
28 }
29 },
30 "Port3Light": {
31 "timer": 0.25,
32 "transitions": {
33 "Tup": "Port1Light",
34 "GlobalCounter0_End": ">exit"
35 },
36 "actions": {
37 "PWM3": 255
38 }
39 }
40 },
41 "global_counters": {
42 "0": {
43 "event": "Port1High",
44 "threshold": 5
45 }
46 }
47}
1states:
2 InitialDelay:
3 timer: 2.0
4 transitions:
5 Tup: ResetGlobalCounter
6 actions:
7 PWM2: 255
8 ResetGlobalCounter:
9 transitions:
10 Tup: Port1Light
11 actions:
12 GlobalCounterReset: 0
13 Port1Light:
14 timer: 0.25
15 transitions:
16 Tup: Port3Light
17 GlobalCounter0_End: '>exit'
18 actions:
19 PWM1: 255
20 Port3Light:
21 timer: 0.25
22 transitions:
23 Tup: Port1Light
24 GlobalCounter0_End: '>exit'
25 actions:
26 PWM3: 255
27global_counters:
28 0:
29 event: Port1High
30 threshold: 5