-
Notifications
You must be signed in to change notification settings - Fork 0
/
icreate_vid.html
252 lines (229 loc) · 9.28 KB
/
icreate_vid.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
<html>
<head>
<title>Drone control via rosbridge</title>
</head>
<body>
<script type="text/javascript" src="ros.js"></script>
<script type="text/javascript">
// Changed origin to middle bottom 11.14.13 -- JRaiti
// This is the turtle to connect to
//var con = new Bridge("ws://localhost:9090");
var con = new Bridge("ws://138.16.161.234:9090");
// send velocity command to the robot
function takeoff() {
con.publish('/ardrone/takeoff', { });
}
function land() {
con.publish('/ardrone/land', { });
}
function togglecam() {
con.callService({ }, '/ardrone/togglecam');
}
function start_moving(keycode) {
console.log("Starting to move, keycode: " + keycode);
if (keycode == 38) {
// Forward
con.publish('/cmd_vel', {"linear":{"x":1.0,"y":0,"z":0},"angular":{"x":0,"y":0,"z":0}});
} else if (keycode == 40) {
// Backward
con.publish('/cmd_vel', {"linear":{"x":-1.0,"y":0,"z":0},"angular":{"x":0,"y":0,"z":0}});
} else if (keycode == 39) {
// Spin Left
con.publish('/cmd_vel', {"linear":{"x":0,"y":0,"z":0},"angular":{"x":0,"y":0,"z":-1.0}});
} else if (keycode == 37) {
// Spin Right
con.publish('/cmd_vel', {"linear":{"x":0,"y":0,"z":0},"angular":{"x":0,"y":0,"z":1.0}});
} else if (keycode == 65) {
// Strafe Left
con.publish('/cmd_vel', {"linear":{"x":0,"y":1.0,"z":0},"angular":{"x":0,"y":0,"z":0}});
} else if (keycode == 68) {
// Strafe Right
con.publish('/cmd_vel', {"linear":{"x":0,"y":-1.0,"z":0},"angular":{"x":0,"y":0,"z":0}});
} else if (keycode == 83) {
// Descend
con.publish('/cmd_vel', {"linear":{"x":0,"y":0,"z":-1.0},"angular":{"x":0,"y":0,"z":0}});
} else if (keycode == 87) {
// Ascend
con.publish('/cmd_vel', {"linear":{"x":0,"y":0,"z":1.0},"angular":{"x":0,"y":0,"z":0}});
} else if (keycode == 13) {
takeoff();
} else if (keycode == 32) {
land();
} else if (keycode == 33) {
togglecam();
}
}
function stop_moving(keycode) {
console.log("ELECTRIC Done moving, keycode: " + keycode);
//if (keycode >= 37 && keycode <= 40) {
con.publish('/cmd_vel', {"linear":{"x":0,"y":0,"z":0},"angular":{"x":0,"y":0,"z":0}});
//}
}
function OnButtonDown (button,keycode) {
button.style.color = "#ff0000";
document.getElementById("countme").innerHTML = button.value+" "+keycode;
start_moving(keycode);
}
function OnButtonUp (button,keycode) {
button.style.color = "#000000";
document.getElementById("countme").innerHTML = "stop"+" "+keycode;
stop_moving(keycode);
}
function addlisteners(button,keycode) {
if (button.addEventListener) { // all browsers except IE before version 9
button.addEventListener ("mousedown", function () {OnButtonDown (button,keycode)}, false);
button.addEventListener ("mouseup", function () {OnButtonUp (button,0)}, false);
}
}
/*function point_it(event){
pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("pointer_div").offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("pointer_div").offsetTop;
document.getElementById("cross").style.left = (pos_x-1) ;
document.getElementById("cross").style.top = (pos_y-15) ;
document.getElementById("cross").style.visibility = "visible" ;
document.pointform.form_x.value = pos_x;
document.pointform.form_y.value = pos_y;
}*/
function start_moving_mouse(event) {
// origin at center of image
x2 = 640/2;
y2 = 480;//480/2;
pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("pointer_div").offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("pointer_div").offsetTop;
//find horizontal distance (x)
var x = x2 - pos_x;
//find vertical distance (y)
var y = y2 - pos_y;
//compute distance
dist = Math.sqrt(x*x + y*y);
theta =Math.atan2(x,y);// + 3.14159/2;
if (theta > 0){
small_d = dist/100;
} else if (theta < 0){
small_d = -dist/100;
} small_d = dist/100;
//theta_X = small_d*Math.cos(theta);
//theta_Y = small_d*Math.sin(theta);
document.pointform.dist.value = dist;
document.pointform.theta.value = theta;
document.getElementById("cross").style.left = (pos_x-1) ;
document.getElementById("cross").style.top = (pos_y-15) ;
document.getElementById("cross").style.visibility = "visible" ;
document.pointform.form_x.value = pos_x;
document.pointform.form_y.value = pos_y;
tmr = 0;
while (tmr < small_d){
con.publish('/cmd_vel', {"linear":{"x":small_d,"y":0,"z":0},"angular":{"x":0,"y":0,"z":theta}});
tmr = tmr + 0.005;
}
setTimeout(function(){con.publish('/cmd_vel', {"linear":{"x":0,"y":0,"z":0},"angular":{"x":0,"y":0,"z":0}});
},500);
/*setTimeout(function(){con.publish('/cmd_vel', {"linear":{"x":small_d,"y":0,"z":0},"angular":{"x":0,"y":0,"z":theta}});
setTimeout(function(){con.publish('/cmd_vel', {"linear":{"x":0,"y":0,"z":0},"angular":{"x":0,"y":0,"z":0}});
},0);
},0);*/
}
function main() {
document.addEventListener('keydown', function(e) {start_moving(e.keyCode); }, true);
document.addEventListener('keyup', function(e) {stop_moving(e.keyCode); }, true);
document.addEventListener('click', function(e) {start_moving_mouse(e.event); }, true);
document.addEventListener('mousedown', function() {start_moving_mouse(e.event); }, true);
document.addEventListener('mouseup', function() {con.publish('/cmd_vel', {'linear':{'x':0.0,'y':0,'z':0},'angular':{'x':0,'y':0,'z':0}}); }, false);
}
main();
window.onload = function() {
var button_ascend = document.getElementById ("ascend");
addlisteners(button_ascend,87);
var button_descend = document.getElementById ("descend");
addlisteners(button_descend,83);
var button_forward = document.getElementById ("forward");
addlisteners(button_forward,38);
var button_backward = document.getElementById ("backward");
addlisteners(button_backward,40);
var button_right = document.getElementById ("right");
addlisteners(button_right,68);
var button_left = document.getElementById ("left");
addlisteners(button_left,65);
var button_spinright = document.getElementById ("spinright");
addlisteners(button_spinright,39);
var button_spinleft = document.getElementById ("spinleft");
addlisteners(button_spinleft,37);
var button_takeoff = document.getElementById ("takeoff");
addlisteners(button_takeoff,13);
var button_land = document.getElementById ("land");
addlisteners(button_land,32);
var button_togglecam = document.getElementById ("togglecam");
addlisteners(button_togglecam,33);
}
</script>
<h1>Drone controller</h1>
Click in the image to control the iCreate:
John Raiti [email protected]
<!--Drive your drone by pressing the arrow keys. Take off with the enter key. Land with the space key. -->
<p>
<form name="pointform" method="post">
<div id="pointer_div" onclick="start_moving_mouse(event)">
<!--<img src="http://localhost:8080/stream?topic=/ardrone/image_raw?width=640?height=480" width=640 height=480 id="cross"></div>-->
<!--<img src="http://localhost:8080/stream?topic=/ardrone/image_raw?quality=0?width=200?height=150" width=640 height=480 id="cross"></div> -->
<img src="http://138.16.161.234:8080/stream?topic=/gscam/image_raw?quality=70?width=200?height=150" width=640 height=480 id="cross"></div>
You pointed on x = <input type="text" name="form_x" size="4" /> y = <input type="text" name="form_y" size="4" />
Dist from origin @ center bottom = <input type="text" name="dist" size="4" />
Angle = <input type="text" name="theta" size="4" />
</form>
<table border="0">
<tr>
<td>
<input type="button" id="takeoff" value="take off" style="width:200px;height:100px;font-size:30" >
</td>
<td>
<input type="button" id="land" value="land" style="width:200px;height:100px;font-size:30" >
</td>
<!--<div id="slider">
1% <input id="slide" type="range"
min="1.0" max="5.0" step="1.0" value="2.0"
onchange="forward_slider(this.value)"/>
5%
</div><br/>
<div id="chosen">5</div>
<td> -->
<input type="button" id="togglecam" value="togglecam" style="width:200px;height:100px;font-size:30" >
</td>
<th colspan="2">
<div id="countme" style="font-size:30;text-align:center"> update 11_14_13</div>
</th>
</tr>
</table>
<p>
<table border="0">
<tr>
<td>
<input type="button" id="spinleft" value="spin left" style="width:200px;height:100px;font-size:30" >
</td>
<td>
<input type="button" id="forward" value="forward" style="width:200px;height:100px;font-size:30" >
</td>
<td>
<input type="button" id="spinright" value="spin right" style="width:200px;height:100px;font-size:30" >...............
</td>
<td>
<input type="button" id="ascend" value="ascend" style="width:200px;height:100px;font-size:30" >
</td>
</tr>
<tr>
<td>
<input type="button" id="left" value="left" style="width:200px;height:100px;font-size:30" >
</td>
<td>
<input type="button" id="backward" value="backward" style="width:200px;height:100px;font-size:30" >
</td>
<td>
<input type="button" id="right" value="right" style="width:200px;height:100px;font-size:30" >
</td>
<td>
<input type="button" id="descend" value="descend" style="width:200px;height:100px;font-size:30" >
</td>
</tr>
</table>
<p>
</body>
</html>