Skip to content

Commit 138f478

Browse files
committed
stanley_controller code clean up
1 parent 640fcbe commit 138f478

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

PathPlanning/BezierPath/bezier_path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
author: Atsushi Sakai(@Atsushi_twi)
66
77
"""
8-
from __future__ import division, print_function
98

109
import scipy.special
1110
import numpy as np

PathTracking/stanley_controller/stanley_controller.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
55
author: Atsushi Sakai (@Atsushi_twi)
66
7-
"""
8-
from __future__ import division, print_function
7+
Ref:
8+
- [Stanley: The robot that won the DARPA grand challenge](http://isl.ecst.csuchico.edu/DOCS/darpa2005/DARPA%202005%20Stanley.pdf)
9+
- [Autonomous Automobile Path Tracking](https://www.ri.cmu.edu/pub_files/2009/2/Automatic_Steering_Methods_for_Autonomous_Automobile_Path_Tracking.pdf)
910
11+
"""
12+
import numpy as np
13+
import matplotlib.pyplot as plt
1014
import sys
11-
1215
sys.path.append("../../PathPlanning/CubicSpline/")
1316

14-
import matplotlib.pyplot as plt
15-
import numpy as np
17+
try:
18+
import cubic_spline_planner
19+
except:
20+
raise
1621

17-
import cubic_spline_planner
1822

1923
k = 0.5 # control gain
2024
Kp = 1.0 # speed propotional gain
@@ -131,12 +135,13 @@ def calc_target_index(state, cx, cy):
131135
dx = [fx - icx for icx in cx]
132136
dy = [fy - icy for icy in cy]
133137
d = [np.sqrt(idx ** 2 + idy ** 2) for (idx, idy) in zip(dx, dy)]
134-
front_axle_vec = [-np.cos(state.yaw + np.pi/2), -np.sin(state.yaw + np.pi/2)]
135138
closest_error = min(d)
136139
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)
140+
141+
# Project RMS error onto front axle vector
142+
front_axle_vec = [-np.cos(state.yaw + np.pi / 2),
143+
- np.sin(state.yaw + np.pi / 2)]
144+
error_front_axle = np.dot([dx[target_idx], dy[target_idx]], front_axle_vec)
140145

141146
return target_idx, error_front_axle
142147

0 commit comments

Comments
 (0)