# To speed up nearest point search, doing it at only first time. if self.old_nearest_point_index isNone: # search nearest point index dx = [state.rear_x - icx for icx in self.cx] dy = [state.rear_y - icy for icy in self.cy] d = np.hypot(dx, dy) ind = np.argmin(d) self.old_nearest_point_index = ind else: ind = self.old_nearest_point_index distance_this_index = state.calc_distance(self.cx[ind], self.cy[ind]) whileTrue: distance_next_index = state.calc_distance(self.cx[ind + 1], self.cy[ind + 1]) if distance_this_index < distance_next_index: break ind = ind + 1if (ind + 1) < len(self.cx) else ind distance_this_index = distance_next_index self.old_nearest_point_index = ind
# search look ahead target point index # 搜索前瞻目标点索引 while Lf > state.calc_distance(self.cx[ind], self.cy[ind]): if (ind + 1) >= len(self.cx): break# not exceed goal ind += 1