-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
448 lines (433 loc) · 18.3 KB
/
app.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_daq as daq
from dash.dependencies import State, Input, Output
from roboarm import Arm
app = dash.Dash(__name__)
server = app.server
arm = Arm()
vendor = 0x1267
bmRequestType = 0x40
bRequest = 6
wValue = 0x100
wIndex = 0
app.layout = html.Div(
[
html.Div(
[
html.Div(
id="dash-daq-remote-banner",
style={"position": "absolute", "top": "70px", "right": "-45px"},
children=[
html.A(
html.Img(
src="https://s3-us-west-1.amazonaws.com/plotly-tutorials/excel/dash-daq/dash-daq-logo-stripe.png",
style={"width": "45%"},
),
href="http://www.dashdaq.io",
)
],
),
html.P(
"Robotic Arm Edge",
style={
"position": "absolute",
"top": "118px",
"left": "307px",
"color": "#506784",
"font-size": "17px",
},
),
html.Div(
[
html.Div(
[
html.H6(
"LED On",
style={
"textAlign": "center",
"font-size": "1.1rem",
"position": "relative",
"right": "19px",
},
),
html.Div(
[
html.H6(
"Base Left",
style={
"textAlign": "center",
"font-size": "1.1rem",
"paddingLeft": "14%",
"top": "30px",
"paddingTop": "8%",
},
className="three columns",
),
daq.Joystick(
id="LED-base-move",
force=0,
className="four columns",
),
html.H6(
"Base Right",
style={
"textAlign": "center",
"font-size": "1.1rem",
"left": "9px",
"top": "24px",
"width": "9%",
"position": "relative",
},
className="three columns",
),
],
className="row",
),
html.H6(
"LED Off",
style={
"textAlign": "center",
"font-size": "1.1rem",
"position": "relative",
"right": "21px",
},
),
],
className="six columns",
style={"paddingTop": "3%"},
),
html.Div(
[
html.H6(
"Wrist Up",
style={
"textAlign": "center",
"font-size": "1.1rem",
"position": "relative",
"right": "20px",
},
),
html.Div(
[
html.H6(
"Open Grip",
style={
"textAlign": "center",
"font-size": "1.1rem",
"paddingLeft": "13%",
"paddingTop": "8.5%",
},
className="three columns",
),
daq.Joystick(
id="wrist-grip-move",
force=0,
className="four columns",
),
html.H6(
"Close Grip",
style={
"textAlign": "center",
"font-size": "1.1rem",
"left": "6px",
"top": "26.5px",
"width": "9%",
"position": "relative",
},
className="three columns",
),
],
className="row",
),
html.H6(
"Wrist Down",
style={
"textAlign": "center",
"font-size": "1.1rem",
"position": "relative",
"right": "19px",
},
),
],
className="six columns",
style={"paddingTop": "3%"},
),
],
className="row",
style={
"width": "86%",
"top": "26%",
"right": "4%",
"position": "absolute",
},
),
html.Div(
[
html.Div(
[
daq.Indicator(
id="LED-state",
label="LED ON/OFF",
value=True,
className="two columns",
color="#EF553B",
style={
"textAlign": "center",
"marginLeft": "12%",
"paddingTop": "13%",
"marginRight": "6%",
},
),
html.Div(
[
html.H6(
"Elbow Up",
style={
"textAlign": "center",
"font-size": "1.1rem",
"position": "relative",
"left": "19px",
},
),
html.Div(
[
html.H6(
"Shoulder Up",
style={
"textAlign": "center",
"font-size": "1.1rem",
"position": "relative",
"top": "21px",
"width": "26%",
"left": "-6px",
},
className="three columns",
),
daq.Joystick(
id="elbow-shoulder-move",
force=0,
className="four columns",
),
html.H6(
"Shoulder Down",
style={
"textAlign": "center",
"font-size": "1.1rem",
"position": "relative",
"top": "22px",
"left": "54px",
"width": "26%",
},
className="three columns",
),
],
className="row",
),
html.H6(
"Elbow Down",
style={
"textAlign": "center",
"font-size": "1.1rem",
"left": "19px",
"position": "relative",
},
),
],
className="six columns",
style={"paddingTop": "3%"},
),
],
className="row",
style={
"marginTop": "3%",
"position": "absolute",
"left": "32.5%",
},
)
]
),
],
style={
"display": "flex",
"justify-content": "center",
"align-items": "center",
"border": "11px solid #A2B1C6",
"border-radius": "150px",
"height": "75%",
"width": "75%",
"marginLeft": "11%",
"marginTop": "8%",
"box-shadow": "16px 10px 8px 0px #506784",
},
),
html.Div(
[
html.A(
href="#open-modal",
children=[
html.Div(
[html.H1(" ")],
style={
"width": "30px",
"height": "7px",
"background-color": "#A2B1C6",
"border": "1px solid #A2B1C6",
"border-radius": "20px",
"position": "absolute",
"top": "232px",
"left": "345px",
},
)
],
),
html.Div(
id="open-modal",
className="modal-window",
style={"background-color": "rgba(162,177,198, 0.75)"},
children=[
html.A(
"Close",
href="#modal-close",
title="Close",
className="modal-close",
style={"font-size": "125%"},
),
html.Div(
style={
"border": "2px solid #2a3f5f",
"border-radius": "10px",
"color": "#2a3f5f",
},
children=[
html.H1(
"Read Me",
style={
"textAlign": "left",
"text-decoration": "underline",
"font-size": "2em",
},
),
html.H6(
"This application was made to \
control the Robotic Arm Edge using \
the USB interface package. This \
application can be controlled \
wirelessly using WI-FI. See it \
in action, by clicking \
on the Dash DAQ logo and reading the \
blog post titled, '\
Robotic Arm Edge'."
),
],
),
],
),
html.H6(
"Read Me",
style={
"position": "absolute",
"top": "238px",
"left": "339px",
"font-size": "1.1rem",
},
),
]
),
html.Div(
[
html.Div(id="wrist-grip-hold"),
html.Div(id="elbow-shoulder-hold"),
html.Div(id="LED-base-hold"),
],
style={"visibility": "hidden"},
),
],
style={
"padding": "0px 10px 0px 10px",
"margin": "auto",
"width": "693px",
"height": "560px",
"position": "absolute",
"top": "0",
"bottom": "0",
"left": "0",
"right": "0",
"border": "5px solid #A2B1C6",
},
)
# Wrist Grip move
@app.callback(
Output("wrist-grip-hold", "children"),
[Input("wrist-grip-move", "angle"),
Input("wrist-grip-move", "force")]
)
def wrist_grip_move(angle, force):
if force < 0.5: # STOP
arm.wrist.stop()
arm.grips.stop()
elif angle < 135 and angle > 45: # UP
arm.wrist.up(None)
elif angle < 315 and angle > 225: # DOWN
arm.wrist.down(None)
elif angle > 135 and angle < 225: # LEFT
arm.grips.open(None)
elif angle < 45 or angle > 345: # RIGHT
arm.grips.close(None)
return
# # Elbow Shoulder move
@app.callback(
Output("elbow-shoulder-hold", "children"),
[Input("elbow-shoulder-move", "angle"),
Input("elbow-shoulder-move", "force")]
)
def elbow_shoulder_move(angle, force):
if force < 0.5: # STOP
arm.elbow.stop()
arm.shoulder.stop()
elif angle < 135 and angle > 45: # UP
arm.elbow.up(None)
elif angle < 315 and angle > 225: # DOWN
arm.elbow.down(None)
elif angle > 135 and angle < 225: # LEFT
arm.shoulder.up(None)
elif angle < 45 or angle > 345: # RIGHT
arm.shoulder.down(None)
return
# # Base Led move
@app.callback(
Output("LED-base-hold", "children"),
[Input("LED-base-move", "angle"),
Input("LED-base-move", "force")]
)
def elbow_shoulder_move(angle, force):
try:
if force < 0.5: # STOP
arm.base.stop()
elif angle < 135 and angle > 45: # UP
arm.led.on(None)
led_color = "#00cc96"
return led_color
elif angle < 315 and angle > 225: # DOWN
arm.led.off(None)
led_color = "#EF553B"
return led_color
elif angle > 135 and angle < 225: # LEFT
arm.base.rotate_counter(None)
elif angle < 45 or angle > 345: # RIGHT
arm.base.rotate_clock(None)
return
except ValueError:
pass
@app.callback(
Output("LED-state", "color"),
[Input("LED-base-hold", "children")]
)
def LED_ON_OFF(LED_color):
if LED_color is None:
return None
return LED_color
if __name__ == "__main__":
app.run_server(debug=True)
# Insert this line in beside "app.run_server", to run through WI-FI: host="0.0.0.0"