@@ -106,10 +106,11 @@ def bspline_planning(x, y, sn):
106106
107107 return rx , ry
108108
109- def pure_pursuit (current_x , current_y , current_heading , path ,lookahead_distance ,index ):
109+ def pure_pursuit (current_x , current_y , current_heading , path ):
110+ global lookahead_distance
110111 closest_point = None
111112 v = speed
112- for i in range (index , len (path )):
113+ for i in range (len (path )):
113114 x = path [i ][0 ]
114115 y = path [i ][1 ]
115116 distance = math .hypot (current_x - x , current_y - y )
@@ -132,7 +133,8 @@ def pure_pursuit(current_x, current_y, current_heading, path,lookahead_distance,
132133 sign = 1 if desired_steering_angle > 0 else - 1
133134 desired_steering_angle = sign * math .pi / 4
134135 v = 0.0
135- return v ,desired_steering_angle ,index
136+ path = path [index - 2 :]
137+ return v ,desired_steering_angle ,path
136138
137139def costmap (data ,width ,height ,resolution ):
138140 data = np .array (data ).reshape (height ,width )
@@ -211,13 +213,12 @@ def listener_callback(self,msg):
211213 self .path = bspline_planning (path ,len (path )* 5 ) #bspline ile düzeltme
212214 print ("Robot Konumu: " ,self .x ,self .y )
213215 print ("Hedefe ilerleniyor..." )
214- self .i = 0
215216 self .flag = 2
216217
217218 def timer_callback (self ):
218219 if self .flag == 2 :
219220 twist = Twist ()
220- twist .linear .x , twist .angular .z ,self .i = pure_pursuit (self .x ,self .y ,self .yaw ,self .path , lookahead_distance , self . i )
221+ twist .linear .x , twist .angular .z , self .path = pure_pursuit (self .x ,self .y ,self .yaw ,self .path )
221222 if (abs (self .x - self .path [- 1 ][0 ]) < 0.05 and abs (self .y - self .path [- 1 ][1 ])< 0.05 ):
222223 twist .linear .x = 0.0
223224 twist .angular .z = 0.0
@@ -242,4 +243,3 @@ def main(args=None):
242243
243244if __name__ == '__main__' :
244245 main ()
245-
0 commit comments