@@ -26,6 +26,8 @@ def __init__(self, x=0.0, y=0.0, yaw=0.0, v=0.0):
2626 self .y = y
2727 self .yaw = yaw
2828 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 ))
2931
3032
3133def update (state , a , delta ):
@@ -34,6 +36,8 @@ def update(state, a, delta):
3436 state .y = state .y + state .v * math .sin (state .yaw ) * dt
3537 state .yaw = state .yaw + state .v / L * math .tan (delta ) * dt
3638 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 ))
3741
3842 return state
3943
@@ -59,7 +63,7 @@ def pure_pursuit_control(state, cx, cy, pind):
5963 ty = cy [- 1 ]
6064 ind = len (cx ) - 1
6165
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
6367
6468 Lf = k * state .v + Lfc
6569
@@ -71,8 +75,8 @@ def pure_pursuit_control(state, cx, cy, pind):
7175def calc_target_index (state , cx , cy ):
7276
7377 # 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 ]
7680 d = [abs (math .sqrt (idx ** 2 + idy ** 2 )) for (idx , idy ) in zip (dx , dy )]
7781 ind = d .index (min (d ))
7882 L = 0.0
@@ -81,8 +85,8 @@ def calc_target_index(state, cx, cy):
8185
8286 # search look ahead target point index
8387 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
8690 L = math .sqrt (dx ** 2 + dy ** 2 )
8791 ind += 1
8892
0 commit comments