-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
253 lines (228 loc) · 7.54 KB
/
index.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
252
253
<!DOCTYPE html>
<!--
The MIT License (MIT)
This file is part of the jetbot_ros_webconsole package (https://github.com/bobboteck/jetbot_ros_webconsole).
Copyright (c) 2020 Roberto D'Amico (Bobboteck).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<html>
<head>
<title>JetBot Web Console ROS based</title>
<meta charset="utf-8" />
<meta name="description" content="NVIDIA JetBot ROS Web Console">
<meta name="author" content="Roberto D'Amico">
<link rel="shortcut icon" type="image/png" href="favicon.ico">
<link rel="stylesheet" href="assets/css/style.css" />
<script type="text/javascript" src="http://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script type="text/javascript" src="http://static.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
<script type="text/javascript" src="assets/js/RosWeb.js"></script>
<script type="text/javascript" src="https://github.com/bobboteck/ros-jetson-stats-webcomponent/releases/download/v1.0.0/index.js"></script>
<script type="text/javascript" src="https://github.com/bobboteck/JoyStick/releases/download/v1.1.5/joy.min.js"></script>
</head>
<body>
<div class="row">
<div class="columnLateral">
<div class="boxContainer">
<div class="titleAlign">
<h3 class="boxTitle">Jetson Nano Stats</h3>
</div>
<div class="boxDataTop">
<jetson-stats showOffCpu="false"></jetson-stats>
</div>
</div>
</div>
<div class="columnCetral">
<div class="boxContainer">
<div class="titleAlign">
<h2 class="boxTitle">NVIDIA JetBot Web Console ROS based</h2>
</div>
<div class="boxDataTop">
<label>Connenction to:</label>
<input type="text" id="WebSocketAddress" value="" />
<input type="button" id="ConnectWebSocket" value="Connect" onclick="StartConnection()" />
</div>
<div class="boxData">
<label>Current status:</label>
<label id="labelConnectionStatus" style="font-weight: bold;">Not connected.</label>
</div>
</div>
</div>
<div class="columnLateral">
<div class="boxContainer">
<div class="titleAlign">
<h3 class="boxTitle">Move control</h3>
</div>
<div class="boxDataTop">
<div id="joyDiv" style="width:200px;height:200px;margin:auto;"></div>
Posizione X:<input id="joy1PosizioneX" type="text" size="10" /><br />
Posizione Y:<input id="joy1PosizioneY" type="text" size="10" /><br />
Direzione:<input id="joy1Direzione" type="text" size="10" /><br />
X :<input id="joy1X" type="text" size="10" /></br>
Y :<input id="joy1Y" type="text" size="10" />
</div>
</div>
<div class="boxContainer boxContainerTopMargin">
<div class="titleAlign">
<h3 class="boxTitle">Message on display</h3>
</div>
<div class="boxDataTop">
<input type="text" id="forDisplayMessage" value="" />
<input type="button" id="sendMessage" value="Send" onclick="sendDisplayMessage()" />
</div>
</div>
</div>
</div>
<script type="text/javascript">
// Define possible WebSocket url
let url = "ws://" + window.location.hostname + ":9090";
document.getElementById("WebSocketAddress").value = url;
// Instance of RosWeb oject
var rosWeb = new RosWeb();
// Show the current Status of connection
document.getElementById("labelConnectionStatus").innerText = rosWeb.ConnectionStatus.Status;
let currentDirection = "C";
// Subscribing to Diagnostics Topic
let listenerDiagnostics = new ROSLIB.Topic(
{
ros : rosWeb.Ros,
name : '/diagnostics',
messageType : 'diagnostic_msgs/DiagnosticArray'
});
// Add a callback to be called every time a message is published on this topic.
listenerDiagnostics.subscribe(function(message)
{
const element = document.querySelector("jetson-stats");
element.data = message;
});
// Publishing a Topic
let cmdVel = new ROSLIB.Topic(
{
ros : rosWeb.Ros,
name : "/jetbot_motors/cmd_str",
messageType : "std_msgs/String"
});
let displayMessage = new ROSLIB.Topic(
{
ros: rosWeb.Ros,
name: "/jetbot_oled/user_text",
messageType: "std_msgs/String"
}
);
function waitForConnection(rosWeb, callback)
{
if(rosWeb.ConnectionStatus.Code>0)
{
callback();
}
else
{
setTimeout(function() {
waitForConnection(rosWeb, callback);
}, 100);
}
}
function StartConnection()
{
let lblConnectionStatus = document.getElementById("labelConnectionStatus");
lblConnectionStatus.innerText = "Connecting to rosbridge...";
let wsAddress = document.getElementById("WebSocketAddress").value;
rosWeb.Connection(wsAddress);
waitForConnection(rosWeb, function()
{
switch(rosWeb.ConnectionStatus.Code)
{
case 1:
lblConnectionStatus.innerText = "Connected";
lblConnectionStatus.style.color = "#00D600";
break;
case 2:
lblConnectionStatus.innerText = "Connection closed.";
lblConnectionStatus.style.color = "#A0A0A0";
break;
case 3:
lblConnectionStatus.innerText = "Error in the frontend!";
lblConnectionStatus.style.color = "#FF0000";
break;
case 4:
lblConnectionStatus.innerText = "Error in the backend!";
lblConnectionStatus.style.color = "#FF0000";
break;
}
});
}
var Joy = new JoyStick('joyDiv');
var joy1IinputPosX = document.getElementById("joy1PosizioneX");
var joy1InputPosY = document.getElementById("joy1PosizioneY");
var joy1Direzione = document.getElementById("joy1Direzione");
var joy1X = document.getElementById("joy1X");
var joy1Y = document.getElementById("joy1Y");
setInterval(function(){ joy1IinputPosX.value=Joy.GetPosX(); }, 50);
setInterval(function(){ joy1InputPosY.value=Joy.GetPosY(); }, 50);
setInterval(function()
{
let direction = Joy.GetDir();
joy1Direzione.value=direction;
switch(direction)
{
case "N":
if(currentDirection!="N")
{
cmdVel.publish({data: "forward"});
currentDirection="N";
}
break;
case "S":
if(currentDirection!="S")
{
cmdVel.publish({data: "backward"});
currentDirection="S";
}
break;
case "W":
if(currentDirection!="W")
{
cmdVel.publish({data: "left"});
currentDirection="W";
}
break;
case "E":
if(currentDirection!="E")
{
cmdVel.publish({data: "right"});
currentDirection="E";
}
break;
case "C":
default:
if(currentDirection!="C")
{
cmdVel.publish({data: "stop"});
currentDirection="C";
}
break;
}
}, 50);
setInterval(function(){ joy1X.value=Joy.GetX(); }, 50);
setInterval(function(){ joy1Y.value=Joy.GetY(); }, 50);
function sendDisplayMessage()
{
let messageElement = document.getElementById("forDisplayMessage");
displayMessage.publish({data: messageElement.value});
}
</script>
</body>
</html>