def nh_steer(self, q_nearest, q_rand, epsilon):
"""
For a car like robot, where it takes two control input (u_speed, u_phi)
All possible combinations of control inputs are generated and used to find the closest q_new to q_rand
:param q_nearest:
:param q_rand:
:param epsilon:
:return:
"""
L = 20.0 # Length between midpoints of front and rear axle of the car like robot
u_speed, u_phi = [-1.0, 1.0], [-math.pi/4, 0, math.pi/4]
controls = list(itertools.product(u_speed, u_phi))
# euler = lambda t_i, q, u_s, u_p, L: (u_s*math.cos(q[2]), u_s*math.sin(q[2]), u_s/L*math.tan(u_p))
result = []
ctrls_path = {c: [] for c in controls}
for ctrl in controls:
q_new = q_nearest
for t_i in range(epsilon): # h is assumed to be 1 here for euler integration
q_new = tuple(map(add, q_new, self.euler(t_i, q_new, ctrl[0], ctrl[1], L)))
ctrls_path[ctrl].append(q_new)
result.append((ctrl[0], ctrl[1], q_new))
q_news = [x[2] for x in result]
_, _, idx = self.nearest_neighbour(q_rand, np.array(q_news))
return result[idx], ctrls_path
评论列表
文章目录