@@ -256,22 +256,7 @@ def from_refline(x: np.ndarray, y: np.ndarray, velx: np.ndarray):
256
256
margin_perc = 0.1
257
257
258
258
spline = CubicSpline2D (x = x , y = y )
259
- ss , xs , ys , yaws , ks , vxs = [], [], [], [], [], []
260
- for i_s in np .arange (0 , spline .s [- 1 ], ds ):
261
- xi , yi = spline .calc_position (i_s )
262
- yaw = spline .calc_yaw (i_s )
263
- k = spline .calc_curvature (i_s )
264
-
265
- # find closest waypoint
266
- closest = np .argmin (np .hypot (x - xi , y - yi ))
267
- v = velx [closest ]
268
-
269
- xs .append (xi )
270
- ys .append (yi )
271
- yaws .append (yaw )
272
- ks .append (k )
273
- ss .append (i_s )
274
- vxs .append (v )
259
+ ss , xs , ys , yaws , ks , vxs = spline .ss , spline .xs , spline .ys , spline .psis , spline .ks , velx
275
260
276
261
refline = Raceline (
277
262
ss = np .array (ss ).astype (np .float32 ),
@@ -316,6 +301,67 @@ def from_refline(x: np.ndarray, y: np.ndarray, velx: np.ndarray):
316
301
raceline = refline ,
317
302
centerline = refline ,
318
303
)
304
+
305
+ def from_raceline_file (filepath : pathlib .Path , delimiter : str = ";" , skip_rows : int = 3 , track_scale : float = 1.0 ) -> Track :
306
+ """
307
+ Creates a Track object from a raceline file of the format [s, x, y, psi, k, vx, ax].
308
+
309
+ Args:
310
+ filepath (pathlib.Path): path to the raceline file
311
+ delimiter (str, optional): delimiter used in the file. Defaults to ";".
312
+ skip_rows (int, optional): number of rows to skip. Defaults to 3.
313
+ track_scale (float, optional): scale of the track. Defaults to 1.0.
314
+
315
+ Returns:
316
+ Track: track object
317
+ """
318
+ raceline = Raceline .from_raceline_file (filepath , delimiter , skip_rows , track_scale )
319
+ xs = raceline .xs
320
+ ys = raceline .ys
321
+ resolution = 0.05
322
+ margin_perc = 0.1
323
+
324
+ min_x , max_x = np .min (xs ), np .max (xs )
325
+ min_y , max_y = np .min (ys ), np .max (ys )
326
+ x_range = max_x - min_x
327
+ y_range = max_y - min_y
328
+ occupancy_map = 255.0 * np .ones (
329
+ (
330
+ int ((1 + 2 * margin_perc ) * x_range / resolution ),
331
+ int ((1 + 2 * margin_perc ) * y_range / resolution ),
332
+ ),
333
+ dtype = np .float32 ,
334
+ )
335
+ # origin is the bottom left corner
336
+ origin = (min_x - margin_perc * x_range , min_y - margin_perc * y_range , 0.0 )
337
+
338
+ track_spec = TrackSpec (
339
+ name = None ,
340
+ image = None ,
341
+ resolution = resolution ,
342
+ origin = origin ,
343
+ negate = False ,
344
+ occupied_thresh = 0.65 ,
345
+ free_thresh = 0.196 ,
346
+ )
347
+
348
+ track_spec = TrackSpec (
349
+ name = None ,
350
+ image = None ,
351
+ resolution = 0.05 ,
352
+ origin = (0.0 , 0.0 , 0.0 ),
353
+ negate = False ,
354
+ occupied_thresh = 0.65 ,
355
+ free_thresh = 0.196 ,
356
+ )
357
+ return Track (
358
+ spec = track_spec ,
359
+ filepath = None ,
360
+ ext = None ,
361
+ occupancy_map = occupancy_map ,
362
+ raceline = raceline ,
363
+ centerline = raceline ,
364
+ )
319
365
320
366
def save_raceline (self , outdir : pathlib .Path ):
321
367
"""
0 commit comments