Skip to content

Commit 640fcbe

Browse files
authored
Merge pull request AtsushiSakai#166 from amirx96/master
Fixes to lateral error calculation
2 parents 2dfa2ae + 2ba3a43 commit 640fcbe

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

PathTracking/stanley_controller/stanley_controller.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,20 @@ def calc_target_index(state, cx, cy):
123123
:param cy: [float]
124124
:return: (int, float)
125125
"""
126-
# Calc front axle position
126+
# Calc front axle position
127127
fx = state.x + L * np.cos(state.yaw)
128128
fy = state.y + L * np.sin(state.yaw)
129129

130130
# Search nearest point index
131131
dx = [fx - icx for icx in cx]
132132
dy = [fy - icy for icy in cy]
133133
d = [np.sqrt(idx ** 2 + idy ** 2) for (idx, idy) in zip(dx, dy)]
134-
error_front_axle = min(d)
135-
target_idx = d.index(error_front_axle)
136-
137-
target_yaw = normalize_angle(np.arctan2(
138-
fy - cy[target_idx], fx - cx[target_idx]) - state.yaw)
139-
if target_yaw > 0.0:
140-
error_front_axle = - error_front_axle
134+
front_axle_vec = [-np.cos(state.yaw + np.pi/2), -np.sin(state.yaw + np.pi/2)]
135+
closest_error = min(d)
136+
target_idx = d.index(closest_error)
137+
138+
#Project RMS error onto front axle vector
139+
error_front_axle = np.dot( [ dx[target_idx], dy[target_idx] ], front_axle_vec)
141140

142141
return target_idx, error_front_axle
143142

0 commit comments

Comments
 (0)