This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleop.html
116 lines (105 loc) · 2.94 KB
/
teleop.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
<html>
<head>
<script type="text/javascript" src="http://brown-ros-pkg.googlecode.com/svn/tags/brown-ros-pkg/rosbridge/ros.js"></script>
<script type="text/javascript">
function nop() {} /* console for logging */
var console = null;
var connection = null;
function pub() {
connection.publish('/cmd_vel', 'geometry_msgs/Twist', '{"linear":{"x":' + x + ',"y":0,"z":0}, "angular":{"x":0,"y":0,"z":' + z + '}}');
}
function log(msg) {
if (console == null) return;
console.innerHTML = console.innerHTML + msg + "<br/>";
}
function init() {
function waitForDOM() {
var cnsl = document.getElementById('console');
if (cnsl == null) {
setTimeout(waitForDOM, 100);
} else {
console = cnsl;
setTimeout(main, 0);
}
}
setTimeout(waitForDOM, 100);
}
function handleKey(code, down) {
var scale = 0;
if (down == true) {
scale = 1;
}
//log('Code: ' + code);
switch (code) {
case 65:
//left
z = 1 * scale;
x = 100 * scale;
break;
case 87:
//up
x = 100 * scale;
z = 32768 * scale;
break;
case 68:
//right
z = -1 * scale;
x = 100 * scale;
break;
case 83:
//down
x = -100 * scale;
z = 32768 * scale;
break;
case 81:
//stop
x = 0;
z = 0;
break;
}
pub();
}
function main() {
var x = 0;
var z = 0;
log('console initialized');
var connectInfo = document.location.toString();
log('creating ROSProxy connection object...');
try {
connection = new ros.Connection("ws://192.168.1.106:9090");
} catch (err) {
log('Problem creating proxy connection object!');
return;
}
log('connection created');
connection.setOnClose(function (e) {
log('connection closed');
});
connection.setOnError(function (e) {
log('network error!');
});
connection.setOnOpen(function (e) {
log('connected');
document.addEventListener('keydown', function (e) {
handleKey(e.keyCode, true);
}, true);
document.addEventListener('keyup', function (e) {
handleKey(e.keyCode, false);
}, true);
});
}
</script>
</head>
<body onload="init()">
<div>
Keyboard controls: Up (w), Down (s), Left (a), Right (d)
</div>
<button type="button" onclick="handleKey(87, true)">Up</button>
<button type="button" onclick="handleKey(83, true)">Down</button>
<button type="button" onclick="handleKey(65, true)">Left</button>
<button type="button" onclick="handleKey(68, true)">Right</button>
<button type="button" onclick="handleKey(81, true)">Stop</button><br /><br />
Log:<br />
<div id="console" style="margin-left: 1em;"></div>
</body>
</html>