-
Notifications
You must be signed in to change notification settings - Fork 0
/
drone_browser_teleop_toggle.html~
182 lines (159 loc) · 5.92 KB
/
drone_browser_teleop_toggle.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
<html>
<head>
<title>Drone control via rosbridge</title>
</head>
<body>
<script type="text/javascript" src="ros.js"></script>
<script type="text/javascript">
// This is the turtle to connect to
var con = new Bridge("ws://138.16.160.10: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 main() {
document.addEventListener('keydown', function(e) {start_moving(e.keyCode); }, true);
document.addEventListener('keyup', function(e) {stop_moving(e.keyCode); }, true);
}
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>
Drive your drone by pressing the arrow keys. Take off with the enter key. Land with the space key.
<p>
<img src="http://138.16.160.10:8080/stream?topic=/ardrone/image_raw?quality=50?width=200?height=150" width=640 height=480>
<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>
<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 9_28_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>