Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit bf916fa

Browse files
committed
started work on time scrolling
1 parent 9fa7fb1 commit bf916fa

File tree

6 files changed

+82
-16
lines changed

6 files changed

+82
-16
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pros.showInstallOnStartup": false
3+
}

index.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ body {
4747
* This css is used to style the sliders when in debug mode
4848
*/
4949
.debugContainer {
50-
display: flex;
50+
display: none;
5151
flex-wrap: wrap;
5252
padding-left: 0;
5353
padding-top: 49px;
5454
}
5555

5656
.debugContainer input {
5757
list-style: none;
58-
flex-basis: 40%;
58+
flex-basis: 100%;
5959
color: white;
6060
}
6161

@@ -73,7 +73,10 @@ body {
7373

7474
.debugContainer button {
7575
list-style: none;
76-
flex-basis: 100%;
76+
flex-basis: 10%;
77+
width:50px;
78+
height:50px;
79+
font-size:30px;
7780
color: black;
7881
}
7982

index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<html>
44
<head>
5+
<meta charset="utf-8"/>
56
<title>Path Generator</title>
67
<link rel="icon" type="image/x-icon" href="/images/icon.png">
78
<link rel="stylesheet" href="index.css">
@@ -105,13 +106,19 @@
105106
<div class="debugContainer">
106107
<input type="file" id="uploadDebugBtn"></input>
107108
<label for="uploadDebugBtn" id="uploadDebugLabel">Upload Robot Debug Data</label>
109+
<button type="button" id="debugBackBtn">&#x23EE;</button>
110+
<button type="button" id="debugPauseBtn">&#x23EF;</button>
111+
<button type="button" id="debugForwardBtn">&#x23ED;</button>
112+
<input type="range" value ="0" min="0" max="100" step="0.1" oninput="this.nextElementSibling.value = this.value" id="timeSlider">
113+
<output class="text" id="timeSliderVal">0</output>
114+
108115
</div>
109116

110117
<script src="scripts/point.js"></script>
111118
<script src="scripts/userInput.js"></script>
112119
<script src="scripts/spline.js"></script>
113120
<script src="scripts/robot.js"></script>
114-
<script src="scripts/index.js"></script>
121+
<script src="scripts/render.js"></script>
115122
<script src="scripts/events.js"></script>
116123
</body>
117124
</html>

scripts/events.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ window.onload = function() {
1818
path.genPoints(precision, 10);
1919

2020
// draw path every x seconds
21-
setInterval(render, 1000/60);
21+
intervalId = setInterval(render, 1000/fps);
2222
};
2323

2424

@@ -495,6 +495,10 @@ modeBtn.onclick = function() {
495495
const cols2 = document.getElementsByClassName('debugContainer');
496496
if (cols[0].style.display === 'none') {
497497
mode = 0;
498+
// set the interval on the render function
499+
debugRun = false;
500+
clearInterval(intervalId);
501+
intervalId = setInterval(render, 1000/fps);
498502
// show create mode sliders
499503
for (i = 0; i < cols.length; i++) {
500504
cols[i].style.display = 'flex';
@@ -505,6 +509,10 @@ modeBtn.onclick = function() {
505509
}
506510
} else {
507511
mode = 1;
512+
// clear the interval on render
513+
clearInterval(intervalId);
514+
// run the render function once
515+
render();
508516
// hide create mode sliders
509517
for (i = 0; i < cols.length; i++) {
510518
cols[i].style.display = 'none';
@@ -515,3 +523,37 @@ modeBtn.onclick = function() {
515523
}
516524
}
517525
};
526+
527+
528+
/**
529+
* @brief rewind button pressed
530+
*/
531+
rewindBtn.onclick = function() {
532+
if (debugDataTime > 0) {
533+
debugDataTime--;
534+
}
535+
};
536+
537+
538+
/**
539+
* @brief pause/play button pressed
540+
*/
541+
pauseBtn.onclick = function() {
542+
debugRun = !debugRun;
543+
if (debugRun == true) {
544+
clearInterval(intervalId);
545+
intervalId = setInterval(render, 10);
546+
} else {
547+
clearInterval(intervalId);
548+
}
549+
};
550+
551+
552+
/**
553+
* @brief fast forward button pressed
554+
*/
555+
forwardBtn.onclick = function() {
556+
if (debugDataTime < debugDataList.length-1) {
557+
debugDataTime++;
558+
}
559+
};

scripts/index.js renamed to scripts/render.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
let path = new Path(); // robot path
2+
let intervalId;
23
let debugPath = [];
34
let debugDataList = [];
45
let debugDataTime = 0;
56
let debugSet = false;
7+
let debugRun = false;
8+
const fps = 60;
69

710

811
// program mode
@@ -70,6 +73,20 @@ function getInput() {
7073
};
7174

7275

76+
/**
77+
* @brief render the field
78+
*/
79+
function renderField() {
80+
// draw field
81+
ctx.clearRect(0, 0, canvas.width, canvas.height);
82+
// draw the field
83+
ctx.drawImage(img, 0, 0, img.width, img.height, // source rectangle
84+
0, 0, canvas.width, canvas.height); // destination rectangle
85+
// reset line width
86+
ctx.lineWidth = 1.0;
87+
}
88+
89+
7390
/**
7491
* @brief function to create a field
7592
*/
@@ -204,13 +221,8 @@ function renderDebug() {
204221
* @brief draw the spline
205222
*/
206223
function render() {
207-
// clear the canvas
208-
ctx.clearRect(0, 0, canvas.width, canvas.height);
209-
// draw the field
210-
ctx.drawImage(img, 0, 0, img.width, img.height, // source rectangle
211-
0, 0, canvas.width, canvas.height); // destination rectangle
212-
// reset line width
213-
ctx.lineWidth = 1.0;
224+
// render the field
225+
renderField();
214226

215227
// create mode render
216228
if (mode == 0) {

scripts/userInput.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/* eslint-disable no-unused-vars */
2-
/* eslint-disable prefer-const */
3-
4-
51
// sliders
62
const lookaheadSlider = document.getElementById('lookahead');
73
const decelSlider = document.getElementById('decel');
@@ -65,6 +61,9 @@ const downloadPathBtn = document.getElementById('downloadPathBtn');
6561
const uploadDebugBtn = document.getElementById('uploadDebugBtn');
6662
const uploadPathBtn = document.getElementById('uploadPathBtn');
6763
const modeBtn = document.getElementById('modeBtn');
64+
const rewindBtn = document.getElementById('debugBackBtn');
65+
const pauseBtn = document.getElementById('debugPauseBtn');
66+
const forwardBtn = document.getElementById('debugForwardBtn');
6867

6968
// user settings
7069
let lookahead = 0.5; // lookahead

0 commit comments

Comments
 (0)