Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions PathTracking/stanley_controller/stanley_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,19 @@ def calc_target_index(state, cx, cy):
:param cy: [float]
:return: (int, float)
"""
# Calc front axle position
# Calc front axle position
fx = state.x + L * np.cos(state.yaw)
fy = state.y + L * np.sin(state.yaw)

# Search nearest point index
dx = [fx - icx for icx in cx]
dy = [fy - icy for icy in cy]
d = [np.sqrt(idx ** 2 + idy ** 2) for (idx, idy) in zip(dx, dy)]
closest_error = min(d)
target_idx = d.index(closest_error)
d = np.hypot(dx, dy)
target_idx = np.argmin(d)

# Project RMS error onto front axle vector
front_axle_vec = [-np.cos(state.yaw + np.pi / 2),
- np.sin(state.yaw + np.pi / 2)]
-np.sin(state.yaw + np.pi / 2)]
error_front_axle = np.dot([dx[target_idx], dy[target_idx]], front_axle_vec)

return target_idx, error_front_axle
Expand Down