Skip to content

Commit 871cecf

Browse files
authored
Update control.py
1 parent b3ac8ab commit 871cecf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

nav_controller/nav_controller/control.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +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):
109+
def pure_pursuit(current_x, current_y, current_heading, path,index):
110110
global lookahead_distance
111111
closest_point = None
112112
v = speed
113-
for i in range(len(path)):
113+
for i in range(index,len(path)):
114114
x = path[i][0]
115115
y = path[i][1]
116116
distance = math.hypot(current_x - x, current_y - y)
@@ -133,8 +133,7 @@ def pure_pursuit(current_x, current_y, current_heading, path):
133133
sign = 1 if desired_steering_angle > 0 else -1
134134
desired_steering_angle = sign * math.pi/4
135135
v = 0.0
136-
path = path[index-2:]
137-
return v,desired_steering_angle,path
136+
return v,desired_steering_angle,index
138137

139138
def costmap(data,width,height,resolution):
140139
data = np.array(data).reshape(height,width)
@@ -213,12 +212,13 @@ def listener_callback(self,msg):
213212
self.path = bspline_planning(path,len(path)*5) #bspline ile düzeltme
214213
print("Robot Konumu: ",self.x,self.y)
215214
print("Hedefe ilerleniyor...")
215+
self.i = 0
216216
self.flag = 2
217217

218218
def timer_callback(self):
219219
if self.flag == 2:
220220
twist = Twist()
221-
twist.linear.x , twist.angular.z, self.path = pure_pursuit(self.x,self.y,self.yaw,self.path)
221+
twist.linear.x , twist.angular.z,self.i = pure_pursuit(self.x,self.y,self.yaw,self.path,self.i)
222222
if(abs(self.x - self.path[-1][0]) < 0.05 and abs(self.y - self.path[-1][1])< 0.05):
223223
twist.linear.x = 0.0
224224
twist.angular.z = 0.0

0 commit comments

Comments
 (0)