@@ -26,6 +26,8 @@ def __init__(self, x=0.0, y=0.0, yaw=0.0, v=0.0):
26
26
self .y = y
27
27
self .yaw = yaw
28
28
self .v = v
29
+ self .rear_x = self .x - ((L / 2 ) * math .cos (self .yaw ))
30
+ self .rear_y = self .y - ((L / 2 ) * math .sin (self .yaw ))
29
31
30
32
31
33
def update (state , a , delta ):
@@ -34,6 +36,8 @@ def update(state, a, delta):
34
36
state .y = state .y + state .v * math .sin (state .yaw ) * dt
35
37
state .yaw = state .yaw + state .v / L * math .tan (delta ) * dt
36
38
state .v = state .v + a * dt
39
+ state .rear_x = state .x - ((L / 2 ) * math .cos (state .yaw ))
40
+ state .rear_y = state .y - ((L / 2 ) * math .sin (state .yaw ))
37
41
38
42
return state
39
43
@@ -59,7 +63,7 @@ def pure_pursuit_control(state, cx, cy, pind):
59
63
ty = cy [- 1 ]
60
64
ind = len (cx ) - 1
61
65
62
- alpha = math .atan2 (ty - state .y , tx - state .x ) - state .yaw
66
+ alpha = math .atan2 (ty - state .rear_y , tx - state .rear_x ) - state .yaw
63
67
64
68
Lf = k * state .v + Lfc
65
69
@@ -71,8 +75,8 @@ def pure_pursuit_control(state, cx, cy, pind):
71
75
def calc_target_index (state , cx , cy ):
72
76
73
77
# search nearest point index
74
- dx = [state .x - icx for icx in cx ]
75
- dy = [state .y - icy for icy in cy ]
78
+ dx = [state .rear_x - icx for icx in cx ]
79
+ dy = [state .rear_y - icy for icy in cy ]
76
80
d = [abs (math .sqrt (idx ** 2 + idy ** 2 )) for (idx , idy ) in zip (dx , dy )]
77
81
ind = d .index (min (d ))
78
82
L = 0.0
@@ -81,8 +85,8 @@ def calc_target_index(state, cx, cy):
81
85
82
86
# search look ahead target point index
83
87
while Lf > L and (ind + 1 ) < len (cx ):
84
- dx = cx [ind ] - state .x
85
- dy = cy [ind ] - state .y
88
+ dx = cx [ind ] - state .rear_x
89
+ dy = cy [ind ] - state .rear_y
86
90
L = math .sqrt (dx ** 2 + dy ** 2 )
87
91
ind += 1
88
92
0 commit comments