Skip to content

Commit 4a78dea

Browse files
velocity_profile.py cleanup
1 parent 503945e commit 4a78dea

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

GEMstack/onboard/planning/velocity_profile.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313

1414
def parse_route_csv(filename):
1515
"""
16-
Parses the pure pursuit tracker log file and extracts the following data:
17-
- vehicle time (from column index 19)
18-
- X position actual (from column index 2)
19-
- Y position actual (from column index 5)
20-
- X position desired (from column index 11)
21-
- Y position desired (from column index 14)
16+
Parses the route file and extracts:
17+
- X position desired (from column index 0)
18+
- Y position desired (from column index 1)
2219
"""
2320

2421
data = np.genfromtxt(filename, delimiter=',', skip_header=1)
@@ -31,23 +28,19 @@ def compute_spline_curvature(x, y, s=0.0, num=1000):
3128
Computes curvature from 2D path (x, y) using parametric splines.
3229
3330
Parameters:
34-
x, y : list or np.array
35-
Input path coordinates
36-
s : float
37-
Smoothing factor for spline (0 = interpolating spline)
38-
num : int
39-
Number of points to evaluate spline and curvature at
31+
x, y (np.array): path coordinates
32+
s (float): Smoothing factor for spline (0 = interpolating spline)
33+
num (int): Number of points to evaluate spline and curvature at
4034
4135
Returns:
42-
x_smooth, y_smooth, curvature : np.ndarrays
36+
kappa (float): curvature profile along the trajectory
4337
"""
4438
# Fit parametric spline
4539
num = len(x)
46-
tck, u = splprep([x, y], s=s)
40+
tck, _ = splprep([x, y], s=s)
4741
u_fine = np.linspace(0, 1, num)
4842

4943
# Evaluate spline and its first and second derivatives
50-
x_smooth, y_smooth = splev(u_fine, tck)
5144
dx, dy = splev(u_fine, tck, der=1)
5245
ddx, ddy = splev(u_fine, tck, der=2)
5346

@@ -58,10 +51,33 @@ def compute_spline_curvature(x, y, s=0.0, num=1000):
5851
return kappa
5952

6053
def lateral_speed_limit(kappa, ay_max, v_max):
54+
"""
55+
Limits the velocity based on curvature and lateral acceleration limits.
56+
57+
Parameters:
58+
kappa (np.ndarray): curvature profile along the trajectory
59+
ay_max (float): maximum lateral acceleration
60+
v_max (float): maximum velocity
61+
62+
Returns:
63+
np.minimum(v_lat, v_max): velocity profile limited by lateral acceleration
64+
"""
6165
v_lat = np.sqrt(np.maximum(ay_max / (np.abs(kappa) + 1e-8), 0))
6266
return np.minimum(v_lat, v_max)
6367

6468
def limit_ax_for_friction_ellipse(v, kappa, ax_limit, ay_max):
69+
"""
70+
Longitudinal acceleration limit based on current lateral acceleration.
71+
72+
Parameters:
73+
v (float): velocity
74+
kappa (float): curvature
75+
ax_limit (float): maximum longitudinal acceleration
76+
ay_limit (float): maximum lateral acceleration
77+
78+
Returns:
79+
ax_limit * ax_ratio: maximum allowed longitudinal acceleration
80+
"""
6581
# Compute a_y at current v
6682
ay = v**2 * kappa
6783
ay_ratio = ay / ay_max

0 commit comments

Comments
 (0)