exit on key

This commit is contained in:
Göktuğ Karakaşlı
2019-12-07 14:30:18 +03:00
parent 268f4d0c90
commit d019e416ba
53 changed files with 114 additions and 7 deletions

View File

@@ -8,7 +8,6 @@ from math import cos, sin
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
class Quadrotor(): class Quadrotor():
def __init__(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0, size=0.25, show_animation=True): def __init__(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0, size=0.25, show_animation=True):
self.p1 = np.array([size / 2, 0, 0, 1]).T self.p1 = np.array([size / 2, 0, 0, 1]).T
@@ -24,6 +23,9 @@ class Quadrotor():
if self.show_animation: if self.show_animation:
plt.ion() plt.ion()
fig = plt.figure() fig = plt.figure()
fig.canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
self.ax = fig.add_subplot(111, projection='3d') self.ax = fig.add_subplot(111, projection='3d')
self.update_pose(x, y, z, roll, pitch, yaw) self.update_pose(x, y, z, roll, pitch, yaw)
@@ -81,4 +83,4 @@ class Quadrotor():
plt.ylim(-5, 5) plt.ylim(-5, 5)
self.ax.set_zlim(0, 10) self.ax.set_zlim(0, 10)
plt.pause(0.001) plt.pause(0.001)

View File

@@ -567,6 +567,8 @@ def plot_animation(X, U): # pragma: no cover
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
rig.canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
for k in range(K): for k in range(K):
plt.cla() plt.cla()

View File

@@ -162,6 +162,8 @@ def astar_torus(grid, start_node, goal_node):
for i in range(1, len(route)): for i in range(1, len(route)):
grid[route[i]] = 6 grid[route[i]] = 6
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.imshow(grid, cmap=cmap, norm=norm, interpolation=None) plt.imshow(grid, cmap=cmap, norm=norm, interpolation=None)
plt.show() plt.show()
plt.pause(1e-2) plt.pause(1e-2)
@@ -262,4 +264,4 @@ class NLinkArm(object):
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -193,6 +193,8 @@ def astar_torus(grid, start_node, goal_node):
for i in range(1, len(route)): for i in range(1, len(route)):
grid[route[i]] = 6 grid[route[i]] = 6
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.imshow(grid, cmap=cmap, norm=norm, interpolation=None) plt.imshow(grid, cmap=cmap, norm=norm, interpolation=None)
plt.show() plt.show()
plt.pause(1e-2) plt.pause(1e-2)

View File

@@ -51,6 +51,8 @@ class NLinkArm(object):
def plot(self): # pragma: no cover def plot(self): # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
for i in range(self.n_links + 1): for i in range(self.n_links + 1):
if i is not self.n_links: if i is not self.n_links:

View File

@@ -114,6 +114,8 @@ def animation():
def main(): # pragma: no cover def main(): # pragma: no cover
fig = plt.figure() fig = plt.figure()
fig.canvas.mpl_connect("button_press_event", click) fig.canvas.mpl_connect("button_press_event", click)
fig.canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
two_joint_arm() two_joint_arm()

View File

@@ -111,6 +111,8 @@ class BipedalPlanner(object):
if c > len(com_trajectory_for_plot): if c > len(com_trajectory_for_plot):
# set up plotter # set up plotter
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
ax.set_zlim(0, z_c * 2) ax.set_zlim(0, z_c * 2)
ax.set_aspect('equal', 'datalim') ax.set_aspect('equal', 'datalim')

View File

@@ -213,6 +213,8 @@ def main():
if show_animation: if show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
for i in range(len(z[:, 0])): for i in range(len(z[:, 0])):
plt.plot([xTrue[0, 0], z[i, 2]], [xTrue[1, 0], z[i, 3]], "-k") plt.plot([xTrue[0, 0], z[i, 2]], [xTrue[1, 0], z[i, 3]], "-k")

View File

@@ -191,6 +191,8 @@ def main():
if show_animation: if show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(hz[0, :], hz[1, :], ".g") plt.plot(hz[0, :], hz[1, :], ".g")
plt.plot(hxTrue[0, :].flatten(), plt.plot(hxTrue[0, :].flatten(),
hxTrue[1, :].flatten(), "-b") hxTrue[1, :].flatten(), "-b")

View File

@@ -233,6 +233,8 @@ def main():
if show_animation: if show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
draw_heat_map(grid_map.data, mx, my) draw_heat_map(grid_map.data, mx, my)
plt.plot(xTrue[0, :], xTrue[1, :], "xr") plt.plot(xTrue[0, :], xTrue[1, :], "xr")
plt.plot(RF_ID[:, 0], RF_ID[:, 1], ".k") plt.plot(RF_ID[:, 0], RF_ID[:, 1], ".k")

View File

@@ -230,6 +230,8 @@ def main():
if show_animation: if show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
for i in range(len(z[:, 0])): for i in range(len(z[:, 0])):
plt.plot([xTrue[0, 0], z[i, 1]], [xTrue[1, 0], z[i, 2]], "-k") plt.plot([xTrue[0, 0], z[i, 1]], [xTrue[1, 0], z[i, 2]], "-k")

View File

@@ -240,6 +240,8 @@ def main():
if show_animation: if show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(hz[0, :], hz[1, :], ".g") plt.plot(hz[0, :], hz[1, :], ".g")
plt.plot(np.array(hxTrue[0, :]).flatten(), plt.plot(np.array(hxTrue[0, :]).flatten(),
np.array(hxTrue[1, :]).flatten(), "-b") np.array(hxTrue[1, :]).flatten(), "-b")

View File

@@ -124,6 +124,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.axis("equal") plt.axis("equal")
plt.plot(0.0, 0.0, "*r") plt.plot(0.0, 0.0, "*r")
plot_circle(cx, cy, cr) plot_circle(cx, cy, cr)

View File

@@ -73,6 +73,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
draw_heatmap(gmap, minx, maxx, miny, maxy, xyreso) draw_heatmap(gmap, minx, maxx, miny, maxy, xyreso)
plt.plot(ox, oy, "xr") plt.plot(ox, oy, "xr")
plt.plot(0.0, 0.0, "ob") plt.plot(0.0, 0.0, "ob")

View File

@@ -163,6 +163,8 @@ def main():
# for animation # for animation
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
inds = calc_association(cx, cy, clusters) inds = calc_association(cx, cy, clusters)
for ic in inds: for ic in inds:
x, y = calc_labeled_points(ic, clusters) x, y = calc_labeled_points(ic, clusters)

View File

@@ -124,6 +124,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
draw_heatmap(pmap, minx, maxx, miny, maxy, xyreso) draw_heatmap(pmap, minx, maxx, miny, maxy, xyreso)
plt.plot(ox, oy, "xr") plt.plot(ox, oy, "xr")
plt.plot(0.0, 0.0, "ob") plt.plot(0.0, 0.0, "ob")

View File

@@ -242,6 +242,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.axis("equal") plt.axis("equal")
plt.plot(0.0, 0.0, "*r") plt.plot(0.0, 0.0, "*r")
v1.plot() v1.plot()

View File

@@ -79,6 +79,8 @@ class AStarPlanner:
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.plot(self.calc_grid_position(current.x, self.minx), plt.plot(self.calc_grid_position(current.x, self.minx),
self.calc_grid_position(current.y, self.miny), "xc") self.calc_grid_position(current.y, self.miny), "xc")
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closed_set.keys()) % 10 == 0: if len(closed_set.keys()) % 10 == 0:
plt.pause(0.001) plt.pause(0.001)

View File

@@ -534,6 +534,8 @@ class BITStar(object):
def draw_graph(self, xCenter=None, cBest=None, cMin=None, etheta=None, def draw_graph(self, xCenter=None, cBest=None, cMin=None, etheta=None,
samples=None, start=None, end=None): samples=None, start=None, end=None):
plt.clf() plt.clf()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
for rnd in samples: for rnd in samples:
if rnd is not None: if rnd is not None:
plt.plot(rnd[0], rnd[1], "^k") plt.plot(rnd[0], rnd[1], "^k")

View File

@@ -135,6 +135,8 @@ def closed_loop_prediction(cx, cy, cyaw, speed_profile, goal):
if target_ind % 1 == 0 and animation: # pragma: no cover if target_ind % 1 == 0 and animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(cx, cy, "-r", label="course") plt.plot(cx, cy, "-r", label="course")
plt.plot(x, y, "ob", label="trajectory") plt.plot(x, y, "ob", label="trajectory")
plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") plt.plot(cx[target_ind], cy[target_ind], "xg", label="target")

View File

@@ -69,6 +69,8 @@ class Dijkstra:
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.plot(self.calc_position(current.x, self.minx), plt.plot(self.calc_position(current.x, self.minx),
self.calc_position(current.y, self.miny), "xc") self.calc_position(current.y, self.miny), "xc")
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closedset.keys()) % 10 == 0: if len(closedset.keys()) % 10 == 0:
plt.pause(0.001) plt.pause(0.001)

View File

@@ -318,6 +318,8 @@ def test():
if show_animation: if show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(px, py, label="final course " + str(mode)) plt.plot(px, py, label="final course " + str(mode))
# plotting # plotting

View File

@@ -268,6 +268,8 @@ def main(gx=10.0, gy=10.0, robot_type=RobotType.circle):
if show_animation: if show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(predicted_trajectory[:, 0], predicted_trajectory[:, 1], "-g") plt.plot(predicted_trajectory[:, 0], predicted_trajectory[:, 1], "-g")
plt.plot(x[0], x[1], "xr") plt.plot(x[0], x[1], "xr")
plt.plot(goal[0], goal[1], "xb") plt.plot(goal[0], goal[1], "xb")

View File

@@ -213,6 +213,8 @@ def test1():
if show_animation: if show_animation:
# plot the path # plot the path
plt.plot(pos[0, :], pos[1, :]) plt.plot(pos[0, :], pos[1, :])
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.pause(1.0) plt.pause(1.0)
if show_animation: if show_animation:

View File

@@ -347,6 +347,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(tx, ty) plt.plot(tx, ty)
plt.plot(ob[:, 0], ob[:, 1], "xk") plt.plot(ob[:, 0], ob[:, 1], "xk")
plt.plot(path.x[1:], path.y[1:], "-or") plt.plot(path.x[1:], path.y[1:], "-or")

View File

@@ -213,6 +213,8 @@ def sweep_path_search(sweep_searcher, gmap, grid_search_animation=False):
if grid_search_animation: if grid_search_animation:
fig, ax = plt.subplots() fig, ax = plt.subplots()
fig.canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
while True: while True:
cxind, cyind = sweep_searcher.move_target_grid(cxind, cyind, gmap) cxind, cyind = sweep_searcher.move_target_grid(cxind, cyind, gmap)
@@ -266,6 +268,8 @@ def planning_animation(ox, oy, reso): # pragma: no cover
if do_animation: if do_animation:
for ipx, ipy in zip(px, py): for ipx, ipy in zip(px, py):
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(ox, oy, "-xb") plt.plot(ox, oy, "-xb")
plt.plot(px, py, "-r") plt.plot(px, py, "-r")
plt.plot(ipx, ipy, "or") plt.plot(ipx, ipy, "or")

View File

@@ -78,6 +78,8 @@ def dp_planning(sx, sy, gx, gy, ox, oy, reso, rr):
# show graph # show graph
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.plot(current.x * reso, current.y * reso, "xc") plt.plot(current.x * reso, current.y * reso, "xc")
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closedset.keys()) % 10 == 0: if len(closedset.keys()) % 10 == 0:
plt.pause(0.001) plt.pause(0.001)
@@ -228,4 +230,4 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
show_animation = True show_animation = True
main() main()

View File

@@ -327,6 +327,8 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.plot(current.xlist[-1], current.ylist[-1], "xc") plt.plot(current.xlist[-1], current.ylist[-1], "xc")
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if len(closedList.keys()) % 10 == 0: if len(closedList.keys()) % 10 == 0:
plt.pause(0.001) plt.pause(0.001)

View File

@@ -266,8 +266,9 @@ class InformedRRTStar:
return path return path
def draw_graph(self, xCenter=None, cBest=None, cMin=None, etheta=None, rnd=None): def draw_graph(self, xCenter=None, cBest=None, cMin=None, etheta=None, rnd=None):
plt.clf() plt.clf()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None: if rnd is not None:
plt.plot(rnd[0], rnd[1], "^k") plt.plot(rnd[0], rnd[1], "^k")
if cBest != float('inf'): if cBest != float('inf'):

View File

@@ -54,6 +54,8 @@ class LQRPlanner:
# animation # animation
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(sx, sy, "or") plt.plot(sx, sy, "or")
plt.plot(gx, gy, "ob") plt.plot(gx, gy, "ob")
plt.plot(rx, ry, "-r") plt.plot(rx, ry, "-r")

View File

@@ -102,6 +102,8 @@ class LQRRRTStar(RRTStar):
def draw_graph(self, rnd=None): def draw_graph(self, rnd=None):
plt.clf() plt.clf()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None: if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k") plt.plot(rnd.x, rnd.y, "^k")
for node in self.node_list: for node in self.node_list:

View File

@@ -98,6 +98,8 @@ def potential_field_planning(sx, sy, gx, gy, ox, oy, reso, rr):
if show_animation: if show_animation:
draw_heatmap(pmap) draw_heatmap(pmap)
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(ix, iy, "*k") plt.plot(ix, iy, "*k")
plt.plot(gix, giy, "*m") plt.plot(gix, giy, "*m")

View File

@@ -194,6 +194,8 @@ def dijkstra_planning(sx, sy, gx, gy, ox, oy, rr, road_map, sample_x, sample_y):
# show graph # show graph
if show_animation and len(closedset.keys()) % 2 == 0: if show_animation and len(closedset.keys()) % 2 == 0:
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(current.x, current.y, "xg") plt.plot(current.x, current.y, "xg")
plt.pause(0.001) plt.pause(0.001)

View File

@@ -151,6 +151,8 @@ def quintic_polynomials_planner(sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
for i, _ in enumerate(time): for i, _ in enumerate(time):
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.grid(True) plt.grid(True)
plt.axis("equal") plt.axis("equal")
plot_arrow(sx, sy, syaw) plot_arrow(sx, sy, syaw)

View File

@@ -138,6 +138,8 @@ class RRT:
def draw_graph(self, rnd=None): def draw_graph(self, rnd=None):
plt.clf() plt.clf()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None: if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k") plt.plot(rnd.x, rnd.y, "^k")
for node in self.node_list: for node in self.node_list:

View File

@@ -106,6 +106,8 @@ class RRTDubins(RRT):
def draw_graph(self, rnd=None): # pragma: no cover def draw_graph(self, rnd=None): # pragma: no cover
plt.clf() plt.clf()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None: if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k") plt.plot(rnd.x, rnd.y, "^k")
for node in self.node_list: for node in self.node_list:

View File

@@ -112,6 +112,8 @@ class RRTStarDubins(RRTStar):
def draw_graph(self, rnd=None): def draw_graph(self, rnd=None):
plt.clf() plt.clf()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None: if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k") plt.plot(rnd.x, rnd.y, "^k")
for node in self.node_list: for node in self.node_list:

View File

@@ -122,6 +122,8 @@ class RRTStarReedsShepp(RRTStar):
def draw_graph(self, rnd=None): def draw_graph(self, rnd=None):
plt.clf() plt.clf()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if rnd is not None: if rnd is not None:
plt.plot(rnd.x, rnd.y, "^k") plt.plot(rnd.x, rnd.y, "^k")
for node in self.node_list: for node in self.node_list:

View File

@@ -395,6 +395,8 @@ def test():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(px, py, label="final course " + str(mode)) plt.plot(px, py, label="final course " + str(mode))
# plotting # plotting

View File

@@ -185,6 +185,8 @@ def dijkstra_planning(sx, sy, gx, gy, ox, oy, rr, road_map, sample_x, sample_y):
# show graph # show graph
if show_animation and len(closedset.keys()) % 2 == 0: # pragma: no cover if show_animation and len(closedset.keys()) % 2 == 0: # pragma: no cover
plt.plot(current.x, current.y, "xg") plt.plot(current.x, current.y, "xg")
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.pause(0.001) plt.pause(0.001)
if c_id == (len(road_map) - 1): if c_id == (len(road_map) - 1):

View File

@@ -546,6 +546,8 @@ def animation(plant, controller, dt):
steer = math.atan2(controller.history_u_2[t] * WB / v, 1.0) steer = math.atan2(controller.history_u_2[t] * WB / v, 1.0)
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(plant.history_x, plant.history_y, "-r", label="trajectory") plt.plot(plant.history_x, plant.history_y, "-r", label="trajectory")
plot_car(x, y, yaw, steer=steer) plot_car(x, y, yaw, steer=steer)
plt.axis("equal") plt.axis("equal")

View File

@@ -224,6 +224,8 @@ def do_simulation(cx, cy, cyaw, ck, speed_profile, goal):
if target_ind % 1 == 0 and show_animation: if target_ind % 1 == 0 and show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(cx, cy, "-r", label="course") plt.plot(cx, cy, "-r", label="course")
plt.plot(x, y, "ob", label="trajectory") plt.plot(x, y, "ob", label="trajectory")
plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") plt.plot(cx[target_ind], cy[target_ind], "xg", label="target")

View File

@@ -203,6 +203,8 @@ def closed_loop_prediction(cx, cy, cyaw, ck, speed_profile, goal):
if target_ind % 1 == 0 and show_animation: if target_ind % 1 == 0 and show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(cx, cy, "-r", label="course") plt.plot(cx, cy, "-r", label="course")
plt.plot(x, y, "ob", label="trajectory") plt.plot(x, y, "ob", label="trajectory")
plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") plt.plot(cx[target_ind], cy[target_ind], "xg", label="target")

View File

@@ -429,6 +429,8 @@ def do_simulation(cx, cy, cyaw, ck, sp, dl, initial_state):
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if ox is not None: if ox is not None:
plt.plot(ox, oy, "xr", label="MPC") plt.plot(ox, oy, "xr", label="MPC")
plt.plot(cx, cy, "-r", label="course") plt.plot(cx, cy, "-r", label="course")

View File

@@ -93,6 +93,9 @@ def plot_vehicle(x, y, theta, x_traj, y_traj): # pragma: no cover
plt.plot(x_traj, y_traj, 'b--') plt.plot(x_traj, y_traj, 'b--')
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.xlim(0, 20) plt.xlim(0, 20)
plt.ylim(0, 20) plt.ylim(0, 20)

View File

@@ -166,6 +166,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plot_arrow(state.x, state.y, state.yaw) plot_arrow(state.x, state.y, state.yaw)
plt.plot(cx, cy, "-r", label="course") plt.plot(cx, cy, "-r", label="course")
plt.plot(x, y, "-b", label="trajectory") plt.plot(x, y, "-b", label="trajectory")

View File

@@ -149,6 +149,8 @@ def closed_loop_prediction(cx, cy, cyaw, ck, speed_profile, goal):
if target_ind % 1 == 0 and show_animation: if target_ind % 1 == 0 and show_animation:
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(cx, cy, "-r", label="course") plt.plot(cx, cy, "-r", label="course")
plt.plot(x, y, "ob", label="trajectory") plt.plot(x, y, "ob", label="trajectory")
plt.plot(cx[target_ind], cy[target_ind], "xg", label="target") plt.plot(cx[target_ind], cy[target_ind], "xg", label="target")

View File

@@ -186,6 +186,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(cx, cy, ".r", label="course") plt.plot(cx, cy, ".r", label="course")
plt.plot(x, y, "-b", label="trajectory") plt.plot(x, y, "-b", label="trajectory")
plt.plot(cx[target_idx], cy[target_idx], "xg", label="target") plt.plot(cx[target_idx], cy[target_idx], "xg", label="target")

View File

@@ -235,6 +235,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(RFID[:, 0], RFID[:, 1], "*k") plt.plot(RFID[:, 0], RFID[:, 1], "*k")
plt.plot(xEst[0], xEst[1], ".r") plt.plot(xEst[0], xEst[1], ".r")

View File

@@ -365,6 +365,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(RFID[:, 0], RFID[:, 1], "*k") plt.plot(RFID[:, 0], RFID[:, 1], "*k")
for i in range(N_PARTICLE): for i in range(N_PARTICLE):

View File

@@ -390,6 +390,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(RFID[:, 0], RFID[:, 1], "*k") plt.plot(RFID[:, 0], RFID[:, 1], "*k")
for iz in range(len(z[:, 0])): for iz in range(len(z[:, 0])):

View File

@@ -303,7 +303,8 @@ def main():
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(RFID[:, 0], RFID[:, 1], "*k") plt.plot(RFID[:, 0], RFID[:, 1], "*k")
plt.plot(hxTrue[0, :].flatten(), plt.plot(hxTrue[0, :].flatten(),
@@ -319,4 +320,4 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -36,6 +36,8 @@ def icp_matching(previous_points, current_points):
if show_animation: # pragma: no cover if show_animation: # pragma: no cover
plt.cla() plt.cla()
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(previous_points[0, :], previous_points[1, :], ".r") plt.plot(previous_points[0, :], previous_points[1, :], ".r")
plt.plot(current_points[0, :], current_points[1, :], ".b") plt.plot(current_points[0, :], current_points[1, :], ".b")
plt.plot(0.0, 0.0, "xr") plt.plot(0.0, 0.0, "xr")