-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathhardware_test.py
More file actions
98 lines (75 loc) · 2.28 KB
/
Copy pathhardware_test.py
File metadata and controls
98 lines (75 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# A script for testing the hardware, optionally run by the cli.run_experiment() before running the experiment
# so the user can check the hardware is all working as expected.
from pyControl.utility import *
import hardware_definition as hw
# States and events.
states = [
"init_state",
"left_active",
"right_active",
"left_release",
"right_release",
]
events = [
"left_poke",
"right_poke",
"center_poke",
"center_poke_out",
]
initial_state = "init_state"
# Run start and stop behaviour.
def run_start():
hw.houselight.on()
def run_end():
hw.off()
# State behaviour functions.
def init_state(event):
# Select left or right poke.
if event == "entry":
hw.center_poke.LED.on()
elif event == "exit":
hw.center_poke.LED.off()
elif event == "left_poke":
goto_state("left_active")
elif event == "right_poke":
goto_state("right_active")
def left_active(event):
# Poke center to trigger solenoid or right to go to state right_active.
if event == "entry":
hw.left_poke.LED.on()
elif event == "exit":
hw.left_poke.LED.off()
elif event == "center_poke":
goto_state("left_release")
elif event == "right_poke":
goto_state("right_active")
def right_active(event):
# Poke center to trigger solenoid or left to go to state left_active.
if event == "entry":
hw.right_poke.LED.on()
elif event == "exit":
hw.right_poke.LED.off()
elif event == "left_poke":
goto_state("left_active")
elif event == "center_poke":
goto_state("right_release")
def left_release(event):
# Trigger left solenoid while center poke IR beam remains broken.
if event == "entry":
hw.left_poke.SOL.on()
elif event == "exit":
hw.left_poke.SOL.off()
elif event == "center_poke_out":
goto_state("left_active")
elif event == "right_poke":
goto_state("right_active")
def right_release(event):
# Trigger right solenoid while center poke IR beam remains broken.
if event == "entry":
hw.right_poke.SOL.on()
elif event == "exit":
hw.right_poke.SOL.off()
elif event == "left_poke":
goto_state("left_active")
elif event == "center_poke_out":
goto_state("right_active")