@@ -189,23 +189,25 @@ function renderDebug() {
189
189
}
190
190
191
191
// draw the robot at the current time stamp
192
+ // get robot position
192
193
const robotPos = new Point ( ) ;
193
194
let robotPosPx = new Point ( ) ;
194
195
const heading = Math . PI / 2 - degToRad ( debugDataList [ debugDataTime ] . heading ) ;
195
196
robotPos . x = debugDataList [ debugDataTime ] . x ;
196
197
robotPos . y = debugDataList [ debugDataTime ] . y ;
197
198
robotPosPx = coordToPx ( robotPos ) ;
199
+ // draw the robot center
198
200
ctx . beginPath ( ) ;
199
201
ctx . fillStyle = hslToHex ( 0 , 0 , 0 ) ;
200
202
ctx . strokeStyle = hslToHex ( 0 , 0 , 0 ) ;
201
203
ctx . arc ( robotPosPx . x , robotPosPx . y , 2 * imgPixelsPerInch , 0 , 2 * Math . PI ) ;
202
204
ctx . fill ( ) ;
203
205
ctx . closePath ( ) ;
206
+ // draw the robot track width
204
207
ctx . beginPath ( ) ;
205
208
ctx . arc ( robotPosPx . x , robotPosPx . y , 9 * imgPixelsPerInch , 0 , 2 * Math . PI ) ;
206
209
ctx . stroke ( ) ;
207
210
ctx . closePath ( ) ;
208
-
209
211
// draw the robot's heading
210
212
const headingVec = new Point ( ) ;
211
213
headingVec . x = robotPos . x + 5 * Math . cos ( heading ) ;
@@ -219,6 +221,35 @@ function renderDebug() {
219
221
ctx . stroke ( ) ;
220
222
ctx . closePath ( ) ;
221
223
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
+
222
253
// update the time
223
254
if ( debugDataTime < debugDataList . length - 1 ) {
224
255
debugDataTime ++ ;
0 commit comments