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

Commit 95ad31f

Browse files
committed
added debug velocity graphs
1 parent a85864c commit 95ad31f

File tree

6 files changed

+269
-17
lines changed

6 files changed

+269
-17
lines changed

index.css

+14
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,17 @@ body {
8080
color: black;
8181
}
8282

83+
84+
.graph {
85+
display: none;
86+
flex-wrap: wrap;
87+
justify-content: center;
88+
padding-top: 25px;
89+
gap: 25px 25px;
90+
}
91+
92+
.graph canvas {
93+
width: 60%;
94+
height: 35%;
95+
border: 1px solid hwb(0 0% 100%);
96+
}

index.html

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
<button type="button" id="debugForwardBtn">&#x23ED;</button>
112112
<input type="range" value ="0" min="0" max="100" step="1" oninput="this.nextElementSibling.value = this.value" id="timeSlider">
113113
</div>
114+
115+
<div class="graph" id="graphContainer">
116+
<canvas id="leftMotorCanvas"></canvas>
117+
<canvas id="rightMotorCanvas"></canvas>
118+
</div>
114119

115120
<script src="scripts/point.js"></script>
116121
<script src="scripts/userInput.js"></script>

scripts/events.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,14 @@ uploadDebugBtn.onchange = function() {
441441
// split the data into lines
442442
const lines = data.split('\n');
443443

444+
// get constants from the first line
445+
const firstLine = lines[0].split(', ');
446+
const maxVel = parseFloat(firstLine[0]);
447+
const trackWidth = parseFloat(firstLine[1]);
448+
debugData = new DebugDataParams(maxVel, trackWidth);
449+
444450
// loop to get path points
445-
let i = 0;
451+
let i = 1;
446452
while (lines[i].substr(0, 5) != 'debug') {
447453
const line = lines[i].split(', ');
448454
const x = parseFloat(line[0]);
@@ -486,9 +492,9 @@ uploadDebugBtn.onchange = function() {
486492
// render the debug data
487493
debugDataTime = 0;
488494
debugTimeSlider.value = 0;
495+
renderGraphs();
489496
renderField();
490497
renderDebug();
491-
debugDataTime--;
492498
debugTimeSlider.value = debugDataTime;
493499
};
494500
reader.readAsText(this.files[this.files.length-1]);
@@ -501,6 +507,7 @@ uploadDebugBtn.onchange = function() {
501507
modeBtn.onclick = function() {
502508
const cols = document.getElementsByClassName('sliderContainer');
503509
const cols2 = document.getElementsByClassName('debugContainer');
510+
const cols3 = document.getElementsByClassName('graph');
504511
if (cols[0].style.display === 'none') {
505512
mode = 0;
506513
// set the interval on the render function
@@ -515,6 +522,10 @@ modeBtn.onclick = function() {
515522
for (i = 0; i < cols2.length; i++) {
516523
cols2[i].style.display = 'none';
517524
}
525+
// hide graphs
526+
for (i = 0; i < cols3.length; i++) {
527+
cols3[i].style.display = 'none';
528+
}
518529
} else {
519530
mode = 1;
520531
// clear the interval on render
@@ -529,6 +540,10 @@ modeBtn.onclick = function() {
529540
for (i = 0; i < cols2.length; i++) {
530541
cols2[i].style.display = 'flex';
531542
}
543+
// show graphs
544+
for (i = 0; i < cols3.length; i++) {
545+
cols3[i].style.display = 'flex';
546+
}
532547
}
533548
};
534549

@@ -539,11 +554,13 @@ modeBtn.onclick = function() {
539554
rewindBtn.onclick = function() {
540555
if (debugDataTime > 0) {
541556
debugDataTime--;
557+
if (debugDataTime == 19) {
558+
debugDataTime--;
559+
}
542560
debugTimeSlider.value = debugDataTime;
561+
renderGraphs();
543562
renderField();
544563
renderDebug();
545-
debugDataTime--;
546-
debugTimeSlider.value--;
547564
}
548565
};
549566

@@ -554,7 +571,7 @@ rewindBtn.onclick = function() {
554571
pauseBtn.onclick = function() {
555572
debugRun = !debugRun;
556573
if (debugRun == true) {
557-
if (debugDataTime == debugDataList.length-1) {
574+
if (debugDataTime == debugDataList.length) {
558575
debugDataTime = 0;
559576
}
560577
clearInterval(intervalId);
@@ -569,13 +586,12 @@ pauseBtn.onclick = function() {
569586
* @brief fast forward button pressed
570587
*/
571588
forwardBtn.onclick = function() {
572-
if (debugDataTime < debugDataList.length-1) {
589+
if (debugDataTime < debugDataList.length - 1) {
573590
debugDataTime++;
574591
debugTimeSlider.value = debugDataTime;
592+
renderGraphs();
575593
renderField();
576594
renderDebug();
577-
debugDataTime--;
578-
debugTimeSlider.value--;
579595
}
580596
};
581597

@@ -586,9 +602,8 @@ forwardBtn.onclick = function() {
586602
debugTimeSlider.oninput = function() {
587603
debugDataTime = this.value;
588604
if (debugSet == true) {
605+
renderGraphs();
589606
renderField();
590607
renderDebug();
591-
debugDataTime--;
592-
debugTimeSlider.value = debugDataTime;
593608
}
594609
};

scripts/point.js

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const canvas = document.getElementById('fieldCanvas');
55
const canvasQuery = document.querySelector('canvas');
66
const ctx = canvas.getContext('2d');
77
const img = new Image();
8+
const leftMotorGraph = document.getElementById('leftMotorCanvas');
9+
const rightMotorGraph = document.getElementById('rightMotorCanvas');
10+
const leftMotorCtx = leftMotorGraph.getContext('2d');
11+
const rightMotorCtx = rightMotorGraph.getContext('2d');
12+
const graphContainer = document.getElementById('graphContainer');
813
img.src = 'images/Top View Render.png';
914

1015
/**

0 commit comments

Comments
 (0)