87da1eaf2281a5f03543f67c4ef218d8af046f82
[ros_wild_thumper.git] / www / index.html
1 <!doctype html>
2 <html>
3         <head>
4                 <meta charset="utf-8" />
5
6                 <link rel="stylesheet" href="assets/stylesheets/bootstrap.min.css">
7                 <link rel="stylesheet" href="assets/stylesheets/jquery-ui.css">
8                 <link rel="stylesheet" href="assets/stylesheets/jquery.minicolors.css">
9
10                 <style>
11                 .minicolors-theme-default.minicolors { margin: 5px; }
12                 .bottom-leds > .minicolors-theme-default.minicolors { margin: 5px 0; }
13                 .top-leds > .minicolors-theme-default.minicolors { margin-top: 70px; }
14                 .wt-icon {background: url('assets/images/wt_top.png'); background-size: cover; background-size: 100%; background-repeat: no-repeat; background-position: center; height: 260px;}
15                 </style>
16
17                 <script type="text/javascript">
18                 function init() {
19                         var ros = new ROSLIB.Ros();
20                         ros.connect('ws://wildthumper:9090');
21                         var isDragging = false;
22
23                         ros.on('connection', function() {
24                                 $("#information").append(`
25                                 <div class="alert alert-dismissible alert-success">
26                                         <span data-dismiss="alert">Connected to websocket server.</span>
27                                 </div>
28                                 `);
29                         });
30
31                         ros.on('error', function(error) {
32                                 $("#information").append(`
33                                 <div class="alert alert-dismissible alert-danger">
34                                         <span data-dismiss="alert">Error connecting to websocket server.</span>
35                                 </div>
36                                 `);
37                         });
38
39                         ros.on('close', function() {
40                                 $("#information").append(`
41                                 <div class="alert alert-dismissible alert-info">
42                                         <span data-dismiss="alert">Connection to websocket server closed.</span>
43                                 </div>
44                                 `);
45                         });
46
47                         //tfClient.subscribe('base_link', function(tf) {
48                         //      var now = new Date();
49                         //      $("#pose").text(now.toLocaleTimeString() + ": (" + tf.translation.x + ", " + tf.translation.y + ")");
50
51                         //      robotMarker.x = tf.translation.x;
52                         //      robotMarker.y = -tf.translation.y;
53                         //      robotMarker.rotation = viewer2D.scene.rosQuaternionToGlobalTheta(tf.rotation);
54                         //});
55                         var poseTopic = new ROSLIB.Topic({ros: ros, name: '/robot_pose', messageType: 'geometry_msgs/Pose'});
56                         var sensorTopic = new ROSLIB.Topic({ros: ros, name: '/sensors', messageType: 'wild_thumper/Sensor'});
57                         var batteryTopic = new ROSLIB.Topic({ros: ros, name: '/battery', messageType: 'sensor_msgs/BatteryState'});
58                         var ledStripeTopic = new ROSLIB.Topic({ros: ros, name: '/led_stripe', messageType: 'wild_thumper/LedStripe'});
59
60                         poseTopic.subscribe(function(message) {
61                                 var now = new Date();
62                                 $("#pose").text(now.toLocaleTimeString() + ": (" + message.position.x + ", " + message.position.y + ")");
63                         });
64
65                         sensorTopic.subscribe(function(message) {
66                                 sensordiv = $("#sensors")
67                                 sensordiv.find("input[name=light]").val(message.light);
68                                 sensordiv.find("input[name=temp]").val(message.temp.toFixed(1));
69                                 sensordiv.find("input[name=humidity]").val(message.humidity);
70                                 sensordiv.find("input[name=pressure]").val(message.pressure.toFixed(1));
71                                 sensordiv.find("input[name=co]").val(message.co);
72                         });
73
74                         batteryTopic.subscribe(function(message) {
75                                 powerdiv = $("#power");
76                                 powerdiv.find("input[name=voltage]").val(message.voltage.toFixed(1));
77                                 powerdiv.find("input[name=current]").val(message.current.toFixed(1));
78                         });
79
80                         viewer2D = new ROS2D.Viewer({
81                                 divID: 'map',
82                                 width: 640,
83                                 height: 480,
84                                 background: "#efefef"
85                         });
86                         $('#map')
87                         .bind('mousewheel', function(e) {
88                                 if (e.originalEvent.wheelDelta/120 > 0) {
89                                         viewer2D.scaleToDimensions(10, 10)
90                                 } else {
91                                         viewer2D.scaleToDimensions(5, 5)
92                                 }
93                         })
94                         .mousedown(function() {
95                                 isDragging = true;
96                                 mousePreX = undefined;
97                                 mousePreY = undefined;
98                         })
99                         .mouseup(function() {
100                                 isDragging = false;
101                         })
102                         .mousemove(function(event) {
103                                 if (isDragging) {
104                                         if (mousePreX != undefined && mousePreY != undefined) {
105                                                 var diffX = event.pageX - mousePreX;
106                                                 var diffY = event.pageY - mousePreY;
107                                                 console.log("Moving viewer2D by " + diffX + ", " + diffY);
108                                                 viewer2D.shift(diffX, diffY);
109                                         }
110                                         mousePreX = event.pageX;
111                                         mousePreY = event.pageY;
112                                 }
113                         });
114
115                         // Setup the nav client.
116                         NAV2D.OccupancyGridClientNav({
117                                 ros : ros,
118                                 rootObject : viewer2D.scene,
119                                 viewer : viewer2D,
120                                 serverName : '/move_base'
121                         });
122
123                         // Initialize the teleop.
124                         var teleop = new KEYBOARDTELEOP.Teleop({
125                                 ros : ros,
126                                 topic : '/cmd_vel'
127                         });
128
129                         // Create a UI slider using JQuery UI.
130                         $('#speed-slider').slider({
131                                 range : 'min',
132                                 min : 0,
133                                 max : 100,
134                                 value : 50,
135                                 slide : function(event, ui) {
136                                         // Change the speed label.
137                                         $('#speed-label').html('Speed: ' + ui.value + '%');
138                                         // Scale the speed.
139                                         teleop.scale = (ui.value / 100.0);
140                                 }
141                         });
142
143                         // Set the initial speed.
144                         $('#speed-label').html('Speed: ' + ($('#speed-slider').slider('value')) + '%');
145                         teleop.scale = ($('#speed-slider').slider('value') / 100.0);
146
147                         $('.led_color').minicolors({
148                                 control: 'wheel',
149                                 format: 'rgb',
150                                 defaultValue: '#000000',
151                                 change: function(value) {
152                                         var rgb = $(this).minicolors('rgbObject');
153                                         var nums = jQuery.parseJSON($(this).prop("name"));
154                                         var msg = new ROSLIB.Message({
155                                                 leds: []
156                                         });
157                                         jQuery.each(nums, function(i, num) {
158                                                 msg["leds"].push({
159                                                         num: num,
160                                                         red: parseInt(rgb.r*127/255),
161                                                         green: parseInt(rgb.g*127/255),
162                                                         blue: parseInt(rgb.b*127/255)
163                                                 })
164                                         });
165                                         ledStripeTopic.publish(msg);
166                                 }
167                         });
168                 }
169                 </script>
170                 <title>Wild Thumper control</title>
171         </head>
172         <body onload="init()">
173                 <div class="container-fluid">
174                         <div id="information">
175                         </div>
176
177                         <nav class="navbar navbar-expand-lg navbar-light bg-light">
178                                 <a class="navbar-brand" href="#">Wild Thumper</a>
179                                 <ul class="nav nav-tabs" role="tablist">
180                                         <li class="nav-item">
181                                                 <a class="nav-link active" href="#data" data-toggle="tab" role="tab">Data</a>
182                                         </li>
183                                         <li class="nav-item">
184                                                 <a class="nav-link" href="#navigation" data-toggle="tab" role="tab">Navigation</a>
185                                         </li>
186                                         <li class="nav-item">
187                                                 <a class="nav-link" href="#lights" data-toggle="tab" role="tab">Lights</a>
188                                         </li>
189                                 </ul>
190                         </nav>
191                         <div class="tab-content">
192                                 <div id="data" class="tab-pane active" role="tabpanel">
193                                         <div class="row">
194                                                 <div id="power" class="col-auto">
195                                                         <h4>Power</h4>
196                                                         <label>Voltage:</label>
197                                                         <div class="input-group">
198                                                                 <input type=text name="voltage" class="form-control" readonly>
199                                                                 <div class="input-group-append">
200                                                                         <span class="input-group-text">V</span>
201                                                                 </div>
202                                                         </div>
203                                                         <label>Current:</label>
204                                                         <div class="input-group">
205                                                                 <input type=text name="current" class="form-control" readonly>
206                                                                 <div class="input-group-append">
207                                                                         <span class="input-group-text">A</span>
208                                                                 </div>
209                                                         </div>
210                                                 </div>
211                                                 <div id="sensors" class="col-auto">
212                                                         <h4>Sensors</h4>
213                                                         <label>Light:</label>
214                                                         <div class="input-group">
215                                                                 <input type=text name="light" class="form-control" readonly>
216                                                                 <div class="input-group-append">
217                                                                         <span class="input-group-text">lx</span>
218                                                                 </div>
219                                                         </div>
220                                                         <label>Temperature:</label>
221                                                         <div class="input-group">
222                                                                 <input type=text name="temp" class="form-control" readonly>
223                                                                 <div class="input-group-append">
224                                                                         <span class="input-group-text">&#x2103</span>
225                                                                 </div>
226                                                         </div>
227                                                         <label>Humidity:</label>
228                                                         <div class="input-group">
229                                                                 <input type=text name="humidity" class="form-control" readonly>
230                                                                 <div class="input-group-append">
231                                                                         <span class="input-group-text">%</span>
232                                                                 </div>
233                                                         </div>
234                                                         <label>Pressure:</label>
235                                                         <div class="input-group">
236                                                                 <input type=text name="pressure" class="form-control" readonly>
237                                                                 <div class="input-group-append">
238                                                                         <span class="input-group-text">kPa</span>
239                                                                 </div>
240                                                         </div>
241                                                         <label>CO:</label>
242                                                         <input type=text name="co" class="form-control" readonly>
243                                                 </div>
244                                         </div>
245                                 </div>
246                                 <div id="navigation" class="tab-pane" role="tabpanel">
247                                         <div id="pose"></div>
248                                         <div id="map"></div>
249                                         <div id="speed-label"></div>
250                                         <div id="speed-slider"></div>
251                                 </div>
252                                 <div id="lights" class="tab-pane" role="tabpanel">
253                                         <div class="row">
254                                                 <div class="col-md-2 offset-md-1" >
255                                                         <div class="d-flex justify-content-center">
256                                                                 <input class="led_color" type="hidden" name="[0]"/>
257                                                                 <input class="led_color" type="hidden" name="[1]"/>
258                                                                 <input class="led_color" type="hidden" name="[2]"/>
259                                                                 <input class="led_color" type="hidden" name="[3]"/>
260                                                         </div>
261                                                         <div>
262                                                                 <div class="row wt-icon">
263                                                                         <div class="col-md-2 align-self-center bottom-leds">
264                                                                                 <input class="led_color" type="hidden" name="[14]"/>
265                                                                                 <input class="led_color" type="hidden" name="[15]"/>
266                                                                         </div>
267                                                                         <div class="col-md-8">
268                                                                                 <div class="d-flex justify-content-center top-leds">
269                                                                                         <input class="led_color" type="hidden" name="[7]"/>
270                                                                                         <input class="led_color" type="hidden" name="[6]"/>
271                                                                                         <input class="led_color" type="hidden" name="[5]"/>
272                                                                                         <input class="led_color" type="hidden" name="[4]"/>
273                                                                                 </div>
274                                                                         </div>
275                                                                         <div class="col-md-2 align-self-center bottom-leds">
276                                                                                 <input class="led_color" type="hidden" name="[13]"/>
277                                                                                 <input class="led_color" type="hidden" name="[12]"/>
278                                                                         </div>
279                                                                 </div>
280                                                         </div>
281                                                         <div class="d-flex justify-content-center">
282                                                                 <input class="led_color" type="hidden" name="[8]"/>
283                                                                 <input class="led_color" type="hidden" name="[9]"/>
284                                                                 <input class="led_color" type="hidden" name="[10]"/>
285                                                                 <input class="led_color" type="hidden" name="[11]"/>
286                                                         </div>
287                                                 </div>
288                                                 <div class="col-md-3 offset-md-1">
289                                                         <div class="form-group row">
290                                                                 <label class="col-sm-2 col-form-label">Alle</label>
291                                                                 <div class="col-sm-10">
292                                                                         <input class="led_color" type="text" name="[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]" class="form-control"/>
293                                                                 </div>
294                                                         </div>
295                                                         <div class="form-group row">
296                                                                 <label class="col-sm-2 col-form-label">Front</label>
297                                                                 <div class="col-sm-10">
298                                                                         <input class="led_color" type="text" name="[0, 1, 2, 3]" class="form-control"/>
299                                                                 </div>
300                                                         </div>
301                                                         <div class="form-group row">
302                                                                 <label class="col-sm-2 col-form-label">Aft</label>
303                                                                 <div class="col-sm-10">
304                                                                         <input class="led_color" type="text" name="[8, 9, 10, 11]" class="form-control"/>
305                                                                 </div>
306                                                         </div>
307                                                         <div class="form-group row">
308                                                                 <label class="col-sm-2 col-form-label">Top</label>
309                                                                 <div class="col-sm-10">
310                                                                         <input class="led_color" type="text" name="[4, 5, 6, 7]" class="form-control"/>
311                                                                 </div>
312                                                         </div>
313                                                         <div class="form-group row">
314                                                                 <label class="col-sm-2 col-form-label">Bottom</label>
315                                                                 <div class="col-sm-10">
316                                                                         <input class="led_color" type="text" name="[12, 13, 14, 15]" class="form-control"/>
317                                                                 </div>
318                                                         </div>
319                                                 </div>
320                                         </div>
321                                 </div>
322                         </div>
323                 </div>
324                 <script src="assets/javascripts/jquery-3.3.1.min.js"></script>
325                 <script src="assets/javascripts/popper.min.js"></script>
326                 <script src="assets/javascripts/bootstrap.min.js"></script>
327                 <script src="assets/javascripts/jquery-ui.min.js"></script>
328                 <script src="assets/javascripts/easeljs.min.js"></script>
329                 <script src="assets/javascripts/eventemitter2.js"></script>
330                 <script src="assets/javascripts/roslib.js"></script>
331                 <script src="assets/javascripts/ros2d.js"></script>
332                 <script src="assets/javascripts/nav2d.js"></script>
333                 <script src="assets/javascripts/keyboardteleop.js"></script>
334                 <script src="assets/javascripts/jquery.minicolors.js"></script>
335         </body>
336 </html>