-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.py
196 lines (173 loc) · 4.34 KB
/
control.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import time
import random
from ProController import *
brightness = 15
j = ProController(0)
def PlayGeneric(pressed):
if pressed:
if j.R:
r2.Sound.Play("Chatty")
elif j.ZR:
r2.Sound.Play("Scream")
elif j.L:
pass
elif j.ZL:
pass
else:
r2.Sound.Play("Generic")
j.Register('A', PlayGeneric)
def B(pressed):
if pressed:
if j.R:
r2.Sound.Play("Laugh")
elif j.ZR:
r2.Sound.Play("Whistle")
elif j.L:
pass
elif j.ZL:
pass
else:
r2.Sound.Play("Happy")
j.Register('B', B)
def Y(pressed):
if pressed:
if j.R:
r2.Sound.Play("Alarmed")
elif j.ZR:
r2.Sound.Play("Annoyed")
elif j.L:
pass
elif j.ZL:
pass
else:
r2.Sound.Play("Sad")
j.Register('Y', Y)
def X(pressed):
if pressed:
if j.R:
r2.Sound.Play("ShortCircuit")
elif j.ZR:
r2.Sound.Play("Music")
elif j.L:
pass
elif j.ZL:
pass
else:
r2.Sound.Play("Leia")
j.Register('X', X)
def Plus(pressed):
if pressed:
if j.R:
global brightness
brightness = min(255, brightness + 15)
r2.SetBrightness(brightness)
else:
r2.Sound.Volume = min(100, r2.Sound.Volume + 5)
j.Register('Plus', Plus)
def Minus(pressed):
if pressed:
if j.R:
global brightness
brightness = max(0, brightness - 15)
r2.SetBrightness(brightness)
else:
r2.Sound.Volume = max(0, r2.Sound.Volume - 5)
j.Register('Minus', Minus)
def RightY(value):
if j.R:
r2.FrontHoloProjector.SetPositionY(value)
if j.ZR:
r2.RearHoloProjector.SetPositionY(value)
if j.L:
r2.TopHoloProjector.SetPositionY(value)
if not (j.R or j.ZR or j.L or j.ZL):
pass
j.Register('RightY', RightY)
def RightStick(pressed):
if pressed:
if j.R:
r2.FrontHoloProjector.ToggleLight()
if j.ZR:
r2.RearHoloProjector.ToggleLight()
if j.L:
r2.TopHoloProjector.ToggleLight()
if j.ZL:
pass
if not (j.R or j.ZR or j.L or j.ZL):
r2.Head.SetPosition(0)
j.Register('RightStick', RightStick)
def RightX(value):
if j.R:
r2.FrontHoloProjector.SetPositionX(value)
if j.ZR:
r2.RearHoloProjector.SetPositionX(value)
if j.L:
r2.TopHoloProjector.SetPositionX(value)
if j.ZL:
pass
if not (j.R or j.ZR or j.L or j.ZL):
r2.Head.SetSpeed(value)
j.Register('RightX', RightX)
def DX(value):
if j.R:
if value == 1:
print "Open Front Body Panels"
elif value == -1:
print "Close Front Body Panels"
if j.ZR:
if value == 1:
print "Open Rear Body Panels"
elif value == -1:
print "Close Rear Body Panels"
if j.L:
pass
if j.ZL:
pass
if not(j.R or j.ZR or j.L or j.ZL):
if value == 1:
r2.LeftUtilityArm.Open()
r2.RightUtilityArm.Open()
elif value == -1:
r2.LeftUtilityArm.Close()
r2.RightUtilityArm.Close()
j.Register('DX', DX)
def DY(value):
if j.R:
if value == -1:
print "Open Periscope"
elif value == 1:
print "Close Periscope"
if j.ZR:
if value == -1:
r2.LifeFormScanner.SetOn()
elif value == 1:
r2.LifeFormScanner.SetOff()
if j.L:
pass
if j.ZL:
pass
if not (j.R or j.ZR or j.L or j.ZL):
if value == -1:
print "Open Dome Panels"
elif value == 1:
print "Close Dome Panels"
j.Register('DY', DY)
r2.DomeLightsRelay.Enable()
r2.DomeServosRelay.Enable()
r2.DomeMotorRelay.Enable()
r2.SoundRelay.Enable()
r2.BodyServosRelay.Enable()
time.sleep(1)
r2.SetBrightness(brightness)
r2.Head.Enable()
r2.LeftUtilityArm.SetTarget(0)
r2.RightUtilityArm.SetTarget(0)
while running():
t = time.time()
j.Update()
if r2.Network.Changed("BB8"):
if r2.Network.IsConnected("BB8"):
r2.Sound.Play("Happy")
else:
r2.Sound.Play("Sad")
r2.DomeMotorRelay.Disable()