-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
279 lines (250 loc) · 11.3 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Deadlock Prediction and Recovery for Distributed Collision Avoidance with Buffered Voronoi Cells</title>
<link rel="stylesheet" href="stylesheets/styles.css">
</head>
<style>
</style>
<body>
<svg width="800" height="500"></svg>
<br>
<div class="options">
<div class="ui-section hidden">
<label class="key">Mouse Position:</label>
<label class="input-text" id="mouse-pos"></label>
</div>
<div class="ui-section">
<label class="key">Time: </label>
<label class="input-text" id="time"></label>
</div>
<div class="ui-section">
<label class="key">Robot-Goal Distances: </label>
<label class="input-text" id="distance"></label>
</div>
<div class="ui-section">
<label class="key">Timescale:</label>
<input type="range" min="0.0001" max="30.0" value=".005" step="0.001" class="slider input" id="time-scale-slider">
</div>
<div class="ui-section">
<label class="key">Robots:</label>
<input type="range" min="2" max="150" value="10" step="1" class="slider input" id="robots-slider">
</div>
<div class="ui-section">
<label class="key">Pause and Reset:</label>
<input type="button" value="Pause" class="input-button input half-btn" id="pause-button" onclick="pauseSimulation()">
<input type="button" value="Reset" class="input-button input half-btn" id="reset-button" onclick="resetSimulation()">
</div>
<div class="ui-section">
<label class="key">Show:</label>
<input type="button" value="All" class="input-button input small-btn active" id="redndering-button" onclick="visualizeElementsChanged()">
<input type="button" value="Robot" class="input-button input small-btn active" id="robot-button" onclick="visualizeElementsChanged()">
<input type="button" value="Goal" class="input-button input small-btn active" id="goal-button" onclick="visualizeElementsChanged()">
<input type="button" value="Waypoint" class="input-button input small-btn active" id="tempGoal-button" onclick="visualizeElementsChanged()">
<input type="button" value="Voronoi Cell" class="input-button input small-btn active" id="vc-button" onclick="visualizeElementsChanged()">
<input type="button" value="Buffered VC" class="input-button input small-btn active" id="bvc-button" onclick="visualizeElementsChanged()">
</div>
<div class="ui-section hidden">
<label class="key">Collision Avoidance:</label>
<select class="input-select input" id="algorithm-select" name="algorithms">
<option value="3" selected>Buffered Voronoi Cell</option>
</select>
</div>
<div class="ui-section">
<label class="key">Deadlock Recovery:</label>
<select class="input-select input" id="deadlock-select" name="deadlock" onchange="changeDeadlockAlgorithm()">
<option value="0" selected>None</option>
<option value="1">Right-Hand Heuristic</option>
<option value="2">Proposed Deadlock Prediction and Recovery Algorithm</option>
</select>
</div>
<div class="ui-section">
<label class="key">Positions:</label>
<select class="input-select input" id="starting-positions-select" name="starting-positions" onchange="changeStartingPositions()">
<option value="0" selected>Random</option>
<option value="1">Circle</option>
<option value="2" >Square (Inverted Horizontally)</option>
<option value="3" >Square (Inverted Vertically and Horizontally)</option>
</select>
</div>
<div class="ui-section">
<label class="key">Start Benchmarking:</label>
<input type="button" value="Benchmark" class="input-button input small-btn" id="benchmark-button" onclick="toggleBenchmarking()" style="width: 50%;">
</div>
<div class="ui-section">
<label class="key">Save Benchmark As PNG :</label>
<input type="button" value="Save" class="input-button input small-btn" onclick="bench.downloadImage()" style="width: 50%;">
<input type="button" value="Auto Save" class="hidden input-button input small-btn" onclick="bench.autoDownloadImage()" style="width: 50%;">
</div>
</div>
<div id="graph-container">
<div id="graph" class="aGraph" style="display: block;" width="1400" height="600"></div>
</div>
<div style="width: 1400px; height:600px;">
<div style="margin:auto; width:1000px; padding: 10px; border: solid 1px black;">
<p style="display: inline-block; width: 100px; color: blue;">_______</p>
<p style="display: inline-block;"> Total Robot-Goal Distance (Right-Hand Heuristic) </p>
<br>
<p style="display: inline-block; width: 100px; color: green;">_______</p>
<p style="display: inline-block;"> Total Robot-Goal Distance (Proposed Deadlock Prediction and Recovery Algorithm) </p>
<br>
<p style="display: inline-block; width: 100px; color: blue;">_ _ _ _ _</p>
<p style="display: inline-block;"> Minimum Robot-Robot Distance (Right-Hand Heuristic) </p>
<br>
<p style="display: inline-block; width: 100px; color: green;">_ _ _ _ _</p>
<p style="display: inline-block;"> Minimum Robot-Robot Distance (Proposed Deadlock Prediction and Recovery Algorithm) </p>
<br>
<p style="display: inline-block; width: 100px; color: red;">_ _ _ _ _</p>
<p style="display: inline-block;"> Safety Distance </p>
<br>
</div>
</div>
<script src="https://d3js.org/d3.v4.js"></script>
<script src="libraries/d3-delaunay.js"></script>
<script src="libraries/offset.js"></script>
<script src="libraries/svg-to-image.js"></script>
<script src="scripts/geometry.js"></script>
<script src="scripts/renderer.js"></script>
<script src="scripts/scene.js"></script>
<script src="scripts/benchmark.js"></script>
<script src="scripts/robot.js"></script>
</body>
</html>
<script>
var uiElements = ["time-scale-slider",
"robots-slider",
"reset-button",
"algorithm-select",
"deadlock-select",
"starting-positions-select"];
function selectElement(id, valueToSelect) {
let element = document.getElementById(id);
element.value = valueToSelect;
}
var getStartingPositionsSettings = function(){
const startPositions = parseInt(document.getElementById("starting-positions-select").value);
switch (startPositions) {
case 0:
return Scene.StartingPositions.Random;
case 1:
return Scene.StartingPositions.Circle;
case 2:
return Scene.StartingPositions.InvertedSquare;
case 3:
return Scene.StartingPositions.InvertedSquare2;
default:
return Scene.StartingPositions.Random;
}
}
var getBenchmarkSettings = function(){
return parseInt(document.getElementById("starting-positions-select").value);
}
// Setup
var timeInstance = 0;
var activeElements = {All:1, Robots:1, Goals:1, TempGoals:1, VC:1, BVC:1, Collisions:1};
var paused = false;
var numberOfRobots = 2;
var radiusOfRobots = 10;
var svg = d3.select("svg");
let motionPlanningAlgorithm = parseInt(document.getElementById("algorithm-select").value);
var gScene = new Scene(svg, numberOfRobots, radiusOfRobots, motionPlanningAlgorithm, activeElements.All, getStartingPositionsSettings());
var bench = new Benchmark(getBenchmarkSettings());
var resetSimulation = function(){
timeInstance = 0;
svg.selectAll("*").remove();
motionPlanningAlgorithm = parseInt(document.getElementById("algorithm-select").value);
gScene = new Scene(svg, numberOfRobots, radiusOfRobots, motionPlanningAlgorithm, activeElements.All, getStartingPositionsSettings());
changeDeadlockAlgorithm();
}
var changeStartingPositions = function(){
let startingPositions = parseInt(document.getElementById("starting-positions-select").value);
switch (startingPositions) {
case 0:
radiusOfRobots = 10;
document.getElementById("robots-slider").max = 150;
document.getElementById("robots-slider").value = 100;
break;
case 1:
radiusOfRobots = 3;
document.getElementById("robots-slider").max = 100;
document.getElementById("robots-slider").value = 100;
break;
case 2:
radiusOfRobots = 5;
document.getElementById("robots-slider").max = 100;
document.getElementById("robots-slider").value = 100;
break;
case 3:
radiusOfRobots = 5;
document.getElementById("robots-slider").max = 100;
document.getElementById("robots-slider").value = 100;
break;
default:
radiusOfRobots = 10;
break;
}
document.getElementById("graph-container").innerHTML =
'<div id="graph" class="aGraph" style="display: block;" width="1400" height="600"></div>';
bench = new Benchmark(getBenchmarkSettings());
}
var changeDeadlockAlgorithm = function(){
let deadlockAlgorithm = parseInt(document.getElementById("deadlock-select").value);
gScene.robots.forEach(r => {
r.setDeadlockAlgo(deadlockAlgorithm);
});
}
var toggleBenchmarking = function(){
uiElements.forEach( e => {
let docEl = document.getElementById(e);
docEl.disabled = !docEl.disabled;
});
bench.setSettings(getBenchmarkSettings());
bench.curTotalDistanceSet = [];
bench.curMinDistanceSet = [];
bench.toggleBenchmarking();
}
var pauseSimulation = function(){
paused = !paused;
}
svg.on('mousemove', function() {
document.getElementById("mouse-pos").textContent = d3.mouse(this);
});
var visualizeElementsChanged = function(){
document.getElementById(event.srcElement.id).classList.toggle("active");
activeElements = { All:elementActive("redndering-button"),
Robots:elementActive("robot-button"),
Goals:elementActive("goal-button"),
TempGoals:elementActive("tempGoal-button"),
VC:elementActive("vc-button"),
BVC:elementActive("bvc-button"),
// Collisions:elementActive("collisions-button")
};
gScene.renderingEnabled = activeElements.All;
}
var elementActive = function(id){
return document.getElementById(id).classList.contains("active");
}
var syncSettings = function(){
numberOfRobots = document.getElementById("robots-slider").value;
gScene.setTimeScale(document.getElementById("time-scale-slider").value);
//document.getElementById("collision-count").textContent = gScene.uniqueCollisions.length + " / " + gScene.totalCollisionTimeInst;
document.getElementById("time").textContent = timeInstance.toFixed(2);
document.getElementById("distance").textContent = Math.floor(gScene.distance) ;
}
var renderScene = function(){
if(bench.benchmarking && timeInstance > bench.benchMaxTimesteps){
bench.startBenchmarkInstance();
}
if(!paused){
gScene.update(activeElements);
}
bench.updateBenchSet(timeInstance);
// console.log("TimeInstance: ",timeInstance.toFixed(2), " Distance: ", Math.floor(gScene.distance));
syncSettings();
requestAnimationFrame(renderScene);
}
changeDeadlockAlgorithm();
renderScene();
</script>