-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
304 lines (254 loc) · 6.47 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="./roswebconsole/js/ros/three/three.min.js"></script>
<script src="./roswebconsole/js/ros/ColladaLoader/ColladaLoader.min.js"></script>
<script src="./roswebconsole/js/ros/STLLoader/STLLoader.min.js"></script>
<script src="./roswebconsole/js/ros/eventemitter2/eventemitter2.js"></script>
<script src="./roswebconsole/js/ros/roslibjs/roslib.js"></script>
<script src="./roswebconsole/js/ros/ros3djs/ros3d.js"></script>
</head>
<!-- slider style -->
<style>
body {
width: 100%;
height:100%;
font-family: 'Open Sans', sans-serif;
background: #97CAF9;
}
.xslider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #ff7f7f;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.xslider:hover {
opacity: 1;
}
.xslider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #ff0000;
cursor: pointer;
}
.xslider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #ff0000;
cursor: pointer;
}
.yslider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #7fff7f;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.yslider:hover {
opacity: 1;
}
.yslider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #007f00;
cursor: pointer;
}
.yslider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #007f00;
cursor: pointer;
}
.zslider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #add8e6;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.zslider:hover {
opacity: 1;
}
.zslider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #0000ff;
cursor: pointer;
}
.zslider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #0000ff;
cursor: pointer;
}
</style>
<!--HTML -->
<body>
<h1>NTBD - Arm Control and Visualizer</h1>
<p>1) Drag the slider to set the position (x,y,z) you want your manipulator to reach and choose the gripper status<br>
2) Press the "Execute" button to see the manipulator reach the set position.<br>
Press the Home button to let your manipulator go to the home position</p>
<button id="home" onclick="home()">Home</button>
<div id="urdf"> </div>
<div id = "sliders">
<div style='float: left;' id="xslidecontainer">
<input type="range" min="100" max="250" value="150" class="xslider" id="x">
<p>x: <span id="xVal"></span></p>
</div>
<div style='float: left;' id="yslidecontainer">
<input type="range" min="-100" max="100" value="0" class="yslider" id="y">
<p>y: <span id="yVal"></span></p>
</div>
<div style='float: left;' id="zslidecontainer">
<input type="range" min="100" max="250" value="235" class="zslider" id="z">
<p>z: <span id="zVal"></span></p>
</div>
</div>
<button id="gripper" onclick="action()">gripper is open</button>
<button onclick="pubPos()">Execute</button>
<!-- Script of things to do in html body -->
<script>
// SIMULATION
var xslider = document.getElementById("x");
var yslider = document.getElementById("y");
var zslider = document.getElementById("z");
var x = document.getElementById("xVal");
var y = document.getElementById("yVal");
var z = document.getElementById("zVal");
var gripper = document.getElementById("gripper");
x.innerHTML = xslider.value;
y.innerHTML = yslider.value;
z.innerHTML = zslider.value;
xslider.oninput = function() {
x.innerHTML = this.value;
}
yslider.oninput = function() {
y.innerHTML = this.value;
}
zslider.oninput = function() {
z.innerHTML = this.value;
}
/**
* Setup all visualization elements when the page is loaded.
*/
var ros = new ROSLIB.Ros({
//url : 'ws://'+ window.location.hostname + '/ros/'
url : 'ws://'+ window.location.hostname + ':9090'
});
var viewer = new ROS3D.Viewer({
divID : 'urdf',
width : 800,
height : 400, //600
antialias : true
});
// Add a grid.
viewer.addObject(new ROS3D.Grid());
// Setup a client to listen to TFs.
var tfClient = new ROSLIB.TFClient({
ros : ros,
angularThres : 0.01,
transThres : 0.01,
rate : 10.0
});
// Setup the URDF client.
var urdfClient = new ROS3D.UrdfClient({
ros : ros,
tfClient : tfClient,
path : 'http://' + window.location.hostname + '/',
rootObject : viewer.scene,
//loader : ROS3D.STL_LOADER
loader : ROS3D.COLLADA_LOADER
});
// Set position by publishing
var desP = new ROSLIB.Topic({
ros : ros,
name : '/desired_position_nolim',
messageType : 'geometry_msgs/Point'
});
var pos = new ROSLIB.Message({
x : Number(x.innerHTML),
y : Number(y.innerHTML),
z : Number(z.innerHTML)
});
desP.publish(pos);
// Publish update of positions
function pubPos() {
// Publishing a Topic -------
var posUp = new ROSLIB.Message({
x : Number(x.innerHTML),
y : Number(y.innerHTML),
z : Number(z.innerHTML)
});
desP.publish(posUp);
}
// Set gripper status
var gripperTopic = new ROSLIB.Topic({
ros : ros,
name : '/gripper_value',
messageType : 'std_msgs/String'
});
var s = new ROSLIB.Message({
data : 'open'
});
gripperTopic.publish(s);
// Publish update of gripper status
function action() {
if (gripper.innerHTML == "gripper is open")
{
gripper.innerHTML = "gripper is closed";
var s = new ROSLIB.Message({
data : 'closed'
});
gripperTopic.publish(s);
}
// Gripper is open and you want to close it
else {
gripper.innerHTML = "gripper is open";
var s = new ROSLIB.Message({
data : 'open'
});
gripperTopic.publish(s);
}
}
//Set home position
function home() {
// Publishing a Topic -------
var home = new ROSLIB.Message({
x : 150,
y : 0,
z : 235,
});
desP.publish(home);
// Update sliders values
x.innerHTML = 150;
y.innerHTML = 0;
z.innerHTML = 235;
// Update sliders positions
xslider.value = x.innerHTML;
yslider.value = y.innerHTML;
zslider.value = z.innerHTML;
// Update gripper button
//var change = document.getElementById("gripper");
gripper.innerHTML = "gripper is open";
var s = new ROSLIB.Message({
data : 'open'
});
gripperTopic.publish(s);
}
</script>
</body>
</html>