-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroboarm-simple.py
127 lines (105 loc) · 3.36 KB
/
roboarm-simple.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
# OWI-535 Robotic Arm - Web Interface / Python + Bottle
# imports
from bottle import Bottle, run, template, request
import usb.core, usb.util, time
# attempt to rewrite lizquilty's OWI 535 Robotic Arm Control Web Interface from Apache to Python Bottle
# objectives: learning Bottle / Python
# - having a simple 1 file script for creating the web interface
# - creates a simple <table> element layout with the links that trigger 1 second of movement in the corresponding motor
# constants
Duration = 1
# initialise the Robot Arm from the USB function
RoboArm = usb.core.find(idVendor=0x1267, idProduct=0x000)
# movearm object for controlling the Arm
def MoveArm (ArmCmd, Duration): # After this, all code until the demo commands must be indented
' Function to start the movement '
RoboArm.ctrl_transfer(0x40, 6, 0x100, 0, ArmCmd, 1000)
#Stop the movement after waiting a specified duration
time.sleep(Duration)
ArmCmd = [0, 0, 1]
RoboArm.ctrl_transfer(0x40, 6, 0x100, 0, ArmCmd, 1000)
movemap = {
'base-anti-clockwise': [0, 1, 1],
'base-clockwise': [0, 2, 1],
'shoulder-up': [64, 0, 1],
'shoulder-down': [128, 0, 1],
'elbow-up': [16, 0, 1],
'elbow-down': [32, 0, 1],
'wrist-up': [4, 0, 1],
'wrist-down': [8, 0, 1],
'grip-open': [2, 0, 1],
'grip-close': [1, 0, 1],
'light-on': [0, 0, 1],
'light-off': [0, 0, 1],
'stop': [0, 0, 1]
}
app = Bottle()
@app.route('/')
def MoveArmInterface():
if RoboArm is None: # in case the robotic arm hasn't been found through usb
return '''
The OWI-535 Robotic Arm has not been found.
'''
else:
# map the URL params and the appropriate movemap
if request.params.get('move') in movemap:
moverequest = movemap[request.params.get('move')]
MoveArm(moverequest, Duration)
else:
moverequest = movemap['light-on']
MoveArm(moverequest, Duration)
# return template("Welcome to <br />The OWI-535 Robotic Arm control interface.<br />Moving: {{moveaction}}", moveaction=moverequest)
return '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Robotic Arm</title>
<style>
table {
text-align: center;
width: 100%;
}
td {
border: 1px solid black;
}
a {
font-size: large;
}
</style>
</head>
<body>
<table>
<tr>
<td colspan="2"><a href="/?move=grip-open">Gripper Open</a></td>
<td colspan="2"><a href="/?move=grip-close">Gripper Close</a></td>
</tr>
<tr>
<td rowspan="6"><a href="/?move=base-clockwise">Base CW</a></td>
<td colspan="2"><a href="/?move=wrist-up">Wrist Up</a></td>
<td rowspan="6"><a href="/?move=base-anti-clockwise">Base CCW</a></td>
</tr>
<tr>
<td colspan="2"><a href="/?move=wrist-down">Wrist Down</a></td>
</tr>
<tr>
<td colspan="2"><a href="/?move=elbow-up">Elbow Up</a></td>
</tr>
<tr>
<td colspan="2"><a href="/?move=elbow-down">Elbow Down</a></td>
</tr>
<tr>
<td colspan="2"><a href="/?move=shoulder-up">Shoulder Up</a></td>
</tr>
<tr>
<td colspan="2"><a href="/?move=shoulder-down">Shoulder Down</a></td>
</tr>
<tr>
<td colspan="2"><a href="/?move=light-on">Light On</a></td>
<td colspan="2"><a href="/?move=light-off">Light Off</a></td>
</tr>
</table>
</body>
</html>
'''
run(app, host='0.0.0.0', port=8080)