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
| <html>
<head>
<title>KUKA youbot control via rosbridge</title>
<meta charset="utf-8">
</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://localhost:9090");
// отправка команд управления роботом (скорость)
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();
}
}
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);
}
</script>
<h1>KUKA youbot mobile platform controller</h1>
Некая информация. Используйте кнопки для управления мобильной платформой робота
<p>
<img src="http://localhost:8080/stream?topic=/ardrone/image_raw">
<p>
<table border="0">
<tr>
<td>
<input type="button" id="spinleft" value="spin lift" 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>
</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:80" >
</td>
</tr>
</table>
<p>
</body>
</html> |