Skip to content

Commit 75c6b76

Browse files
committed
stanley_controller first release
1 parent 17e2803 commit 75c6b76

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed
4.57 MB
Loading

PathTracking/stanley_controller/stanley_controller.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
author: Atsushi Sakai (@Atsushi_twi)
66
77
"""
8-
# import numpy as np
98
import math
109
import matplotlib.pyplot as plt
1110

1211
from pycubicspline import pycubicspline
1312

14-
k = 0.5 # look forward gain
13+
14+
k = 0.5 # control gain
1515
Kp = 1.0 # speed propotional gain
1616
dt = 0.1 # [s] time difference
1717
L = 2.9 # [m] Wheel base of vehicle
@@ -62,9 +62,6 @@ def stanley_control(state, cx, cy, cyaw, pind):
6262
theta_d = math.atan2(k * efa, state.v)
6363
delta = theta_e + theta_d
6464

65-
print(delta, theta_e, theta_d, state.yaw, cyaw[ind], efa)
66-
# input()
67-
6865
return delta, ind
6966

7067

@@ -91,8 +88,7 @@ def calc_target_index(state, cx, cy):
9188
mind = min(d)
9289
ind = d.index(mind)
9390

94-
tyaw = math.atan2(fy - cy[ind], fx - cx[ind]) - state.yaw
95-
print(tyaw)
91+
tyaw = pi_2_pi(math.atan2(fy - cy[ind], fx - cx[ind]) - state.yaw)
9692
if tyaw > 0.0:
9793
mind = - mind
9894

@@ -101,8 +97,8 @@ def calc_target_index(state, cx, cy):
10197

10298
def main():
10399
# target course
104-
ax = [0.0, 100.0, 100.0, 50.0]
105-
ay = [0.0, 0.0, -30.0, -20.0]
100+
ax = [0.0, 100.0, 100.0, 50.0, 60.0]
101+
ay = [0.0, 0.0, -30.0, -20.0, 0.0]
106102

107103
cx, cy, cyaw, ck, s = pycubicspline.calc_spline_course(ax, ay, ds=0.1)
108104

tests/test_stanley_controller.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from unittest import TestCase
2+
3+
import sys
4+
sys.path.append("./PathTracking/stanley_controller/")
5+
6+
from PathTracking.stanley_controller import stanley_controller as m
7+
8+
print("stanley controller test")
9+
10+
11+
class Test(TestCase):
12+
13+
def test1(self):
14+
m.show_animation = False
15+
m.main()

0 commit comments

Comments
 (0)