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

Commit a85864c

Browse files
committed
draw the curvature in debug
1 parent 7625560 commit a85864c

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

scripts/render.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,25 @@ function renderDebug() {
189189
}
190190

191191
// draw the robot at the current time stamp
192+
// get robot position
192193
const robotPos = new Point();
193194
let robotPosPx = new Point();
194195
const heading = Math.PI/2 - degToRad(debugDataList[debugDataTime].heading);
195196
robotPos.x = debugDataList[debugDataTime].x;
196197
robotPos.y = debugDataList[debugDataTime].y;
197198
robotPosPx = coordToPx(robotPos);
199+
// draw the robot center
198200
ctx.beginPath();
199201
ctx.fillStyle = hslToHex(0, 0, 0);
200202
ctx.strokeStyle = hslToHex(0, 0, 0);
201203
ctx.arc(robotPosPx.x, robotPosPx.y, 2*imgPixelsPerInch, 0, 2 * Math.PI);
202204
ctx.fill();
203205
ctx.closePath();
206+
// draw the robot track width
204207
ctx.beginPath();
205208
ctx.arc(robotPosPx.x, robotPosPx.y, 9*imgPixelsPerInch, 0, 2 * Math.PI);
206209
ctx.stroke();
207210
ctx.closePath();
208-
209211
// draw the robot's heading
210212
const headingVec = new Point();
211213
headingVec.x = robotPos.x + 5*Math.cos(heading);
@@ -219,6 +221,35 @@ function renderDebug() {
219221
ctx.stroke();
220222
ctx.closePath();
221223

224+
// draw the lookahead point
225+
ctx.beginPath();
226+
ctx.fillStyle = hslToHex(0, 0, 0);
227+
ctx.strokeStyle = hslToHex(0, 0, 0);
228+
const lookaheadRaw = new Point(debugDataList[debugDataTime].lookaheadX,
229+
debugDataList[debugDataTime].lookaheadY);
230+
const lookaheadPx = coordToPx(lookaheadRaw);
231+
ctx.arc(lookaheadPx.x, lookaheadPx.y, 2*imgPixelsPerInch, 0, 2*Math.PI);
232+
ctx.fill();
233+
ctx.closePath();
234+
235+
// draw the curvature arc
236+
ctx.beginPath();
237+
ctx.strokeStyle = 'red';
238+
// calculate the circle
239+
const radius = 1/(debugDataList[debugDataTime].curvature);
240+
const theta = degToRad(debugDataList[debugDataTime].heading);
241+
const midX = debugDataList[debugDataTime].x +
242+
radius*Math.cos(theta);
243+
const midY = -(debugDataList[debugDataTime].y) -
244+
radius*Math.sin(theta);
245+
const trueRadius = Math.abs(radius);
246+
const mid = new Point(midX, midY);
247+
const midPx = coordToPx(mid);
248+
// draw the arc
249+
ctx.arc(midPx.x, midPx.y, trueRadius*imgPixelsPerInch, 0, 2*Math.PI);
250+
ctx.stroke();
251+
ctx.closePath();
252+
222253
// update the time
223254
if (debugDataTime < debugDataList.length - 1) {
224255
debugDataTime++;

0 commit comments

Comments
 (0)