@@ -61,9 +61,6 @@ def pure_pursuit_control(state, cx, cy, pind):
6161
6262    alpha  =  math .atan2 (ty  -  state .y , tx  -  state .x ) -  state .yaw 
6363
64-     if  state .v  <  0 :  # back 
65-         alpha  =  math .pi  -  alpha 
66- 
6764    Lf  =  k  *  state .v  +  Lfc 
6865
6966    delta  =  math .atan2 (2.0  *  L  *  math .sin (alpha ) /  Lf , 1.0 )
@@ -92,6 +89,20 @@ def calc_target_index(state, cx, cy):
9289    return  ind 
9390
9491
92+ def  plot_arrow (x , y , yaw , length = 1.0 , width = 0.5 , fc = "r" , ec = "k" ):
93+     """ 
94+     Plot arrow 
95+     """ 
96+ 
97+     if  not  isinstance (x , float ):
98+         for  (ix , iy , iyaw ) in  zip (x , y , yaw ):
99+             plot_arrow (ix , iy , iyaw )
100+     else :
101+         plt .arrow (x , y , length  *  math .cos (yaw ), length  *  math .sin (yaw ),
102+                   fc = fc , ec = ec , head_width = width , head_length = width )
103+         plt .plot (x , y )
104+ 
105+ 
95106def  main ():
96107    #  target course 
97108    cx  =  np .arange (0 , 50 , 0.1 )
@@ -128,7 +139,8 @@ def main():
128139
129140        if  show_animation :  # pragma: no cover 
130141            plt .cla ()
131-             plt .plot (cx , cy , ".r" , label = "course" )
142+             plot_arrow (state .x , state .y , state .yaw )
143+             plt .plot (cx , cy , "-r" , label = "course" )
132144            plt .plot (x , y , "-b" , label = "trajectory" )
133145            plt .plot (cx [target_ind ], cy [target_ind ], "xg" , label = "target" )
134146            plt .axis ("equal" )
0 commit comments