1616except :
1717 raise
1818
19-
2019Kp = 1.0 # speed propotional gain
2120# steering control parameter
2221KTH = 1.0
2625L = 2.9 # [m]
2726
2827show_animation = True
29- # show_animation = False
30-
3128
3229class State :
33-
3430 def __init__ (self , x = 0.0 , y = 0.0 , yaw = 0.0 , v = 0.0 ):
3531 self .x = x
3632 self .y = y
3733 self .yaw = yaw
3834 self .v = v
3935
40-
41- def update (state , a , delta ):
42-
43- state .x = state .x + state .v * math .cos (state .yaw ) * dt
44- state .y = state .y + state .v * math .sin (state .yaw ) * dt
45- state .yaw = state .yaw + state .v / L * math .tan (delta ) * dt
46- state .v = state .v + a * dt
47-
48- return state
49-
36+ def update (self , a , delta , dt ):
37+ self .x = self .x + self .v * math .cos (self .yaw ) * dt
38+ self .y = self .y + self .v * math .sin (self .yaw ) * dt
39+ self .yaw = self .yaw + self .v / L * math .tan (delta ) * dt
40+ self .v = self .v + a * dt
5041
5142def PIDControl (target , current ):
5243 a = Kp * (target - current )
53-
5444 return a
5545
56-
5746def pi_2_pi (angle ):
5847 while (angle > math .pi ):
5948 angle = angle - 2.0 * math .pi
@@ -63,7 +52,6 @@ def pi_2_pi(angle):
6352
6453 return angle
6554
66-
6755def rear_wheel_feedback_control (state , cx , cy , cyaw , ck , preind ):
6856 ind , e = calc_nearest_index (state , cx , cy , cyaw )
6957
@@ -78,7 +66,6 @@ def rear_wheel_feedback_control(state, cx, cy, cyaw, ck, preind):
7866 return 0.0 , ind
7967
8068 delta = math .atan2 (L * omega / v , 1.0 )
81- # print(k, v, e, th_e, omega, delta)
8269
8370 return delta , ind
8471
@@ -104,9 +91,7 @@ def calc_nearest_index(state, cx, cy, cyaw):
10491
10592 return ind , mind
10693
107-
10894def closed_loop_prediction (cx , cy , cyaw , ck , speed_profile , goal ):
109-
11095 T = 500.0 # max simulation time
11196 goal_dis = 0.3
11297 stop_speed = 0.05
@@ -126,7 +111,7 @@ def closed_loop_prediction(cx, cy, cyaw, ck, speed_profile, goal):
126111 di , target_ind = rear_wheel_feedback_control (
127112 state , cx , cy , cyaw , ck , target_ind )
128113 ai = PIDControl (speed_profile [target_ind ], state .v )
129- state = update (state , ai , di )
114+ state . update (ai , di , dt )
130115
131116 if abs (state .v ) <= stop_speed :
132117 target_ind += 1
@@ -163,11 +148,8 @@ def closed_loop_prediction(cx, cy, cyaw, ck, speed_profile, goal):
163148
164149 return t , x , y , yaw , v , goal_flag
165150
166-
167151def calc_speed_profile (cx , cy , cyaw , target_speed ):
168-
169152 speed_profile = [target_speed ] * len (cx )
170-
171153 direction = 1.0
172154
173155 # Set stop point
@@ -190,7 +172,6 @@ def calc_speed_profile(cx, cy, cyaw, target_speed):
190172
191173 return speed_profile
192174
193-
194175def main ():
195176 print ("rear wheel feedback tracking start!!" )
196177 ax = [0.0 , 6.0 , 12.5 , 5.0 , 7.5 , 3.0 , - 1.0 ]
@@ -237,6 +218,5 @@ def main():
237218
238219 plt .show ()
239220
240-
241221if __name__ == '__main__' :
242222 main ()
0 commit comments