Skip to content

Commit ad5e1aa

Browse files
authored
Merge pull request AtsushiSakai#259 from goktug97/close_on_key
Close on key
2 parents bf86cc8 + 9ca7d8f commit ad5e1aa

File tree

53 files changed

+168
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+168
-8
lines changed

AerialNavigation/drone_3d_trajectory_following/Quadrotor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import numpy as np
99
import matplotlib.pyplot as plt
1010

11-
1211
class Quadrotor():
1312
def __init__(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0, size=0.25, show_animation=True):
1413
self.p1 = np.array([size / 2, 0, 0, 1]).T
@@ -24,6 +23,10 @@ def __init__(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0, size=0.25, show_animat
2423
if self.show_animation:
2524
plt.ion()
2625
fig = plt.figure()
26+
# for stopping simulation with the esc key.
27+
fig.canvas.mpl_connect('key_release_event',
28+
lambda event: [exit(0) if event.key == 'escape' else None])
29+
2730
self.ax = fig.add_subplot(111, projection='3d')
2831

2932
self.update_pose(x, y, z, roll, pitch, yaw)
@@ -81,4 +84,4 @@ def plot(self): # pragma: no cover
8184
plt.ylim(-5, 5)
8285
self.ax.set_zlim(0, 10)
8386

84-
plt.pause(0.001)
87+
plt.pause(0.001)

AerialNavigation/rocket_powered_landing/rocket_powered_landing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ def plot_animation(X, U): # pragma: no cover
567567

568568
fig = plt.figure()
569569
ax = fig.gca(projection='3d')
570+
# for stopping simulation with the esc key.
571+
fig.canvas.mpl_connect('key_release_event',
572+
lambda event: [exit(0) if event.key == 'escape' else None])
570573

571574
for k in range(K):
572575
plt.cla()

ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ def astar_torus(grid, start_node, goal_node):
162162
for i in range(1, len(route)):
163163
grid[route[i]] = 6
164164
plt.cla()
165+
# for stopping simulation with the esc key.
166+
plt.gcf().canvas.mpl_connect('key_release_event',
167+
lambda event: [exit(0) if event.key == 'escape' else None])
165168
plt.imshow(grid, cmap=cmap, norm=norm, interpolation=None)
166169
plt.show()
167170
plt.pause(1e-2)
@@ -262,4 +265,4 @@ def plot(self, obstacles=[]): # pragma: no cover
262265

263266

264267
if __name__ == '__main__':
265-
main()
268+
main()

ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation_2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ def astar_torus(grid, start_node, goal_node):
193193
for i in range(1, len(route)):
194194
grid[route[i]] = 6
195195
plt.cla()
196+
# for stopping simulation with the esc key.
197+
plt.gcf().canvas.mpl_connect('key_release_event',
198+
lambda event: [exit(0) if event.key == 'escape' else None])
196199
plt.imshow(grid, cmap=cmap, norm=norm, interpolation=None)
197200
plt.show()
198201
plt.pause(1e-2)

ArmNavigation/n_joint_arm_to_point_control/NLinkArm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def update_points(self):
5151

5252
def plot(self): # pragma: no cover
5353
plt.cla()
54+
# for stopping simulation with the esc key.
55+
plt.gcf().canvas.mpl_connect('key_release_event',
56+
lambda event: [exit(0) if event.key == 'escape' else None])
5457

5558
for i in range(self.n_links + 1):
5659
if i is not self.n_links:

ArmNavigation/two_joint_arm_to_point_control/two_joint_arm_to_point_control.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def animation():
114114
def main(): # pragma: no cover
115115
fig = plt.figure()
116116
fig.canvas.mpl_connect("button_press_event", click)
117+
# for stopping simulation with the esc key.
118+
fig.canvas.mpl_connect('key_release_event',
119+
lambda event: [exit(0) if event.key == 'escape' else None])
117120
two_joint_arm()
118121

119122

Bipedal/bipedal_planner/bipedal_planner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def walk(self, T_sup=0.8, z_c=0.8, a=10, b=1, plot=False):
111111
if c > len(com_trajectory_for_plot):
112112
# set up plotter
113113
plt.cla()
114+
# for stopping simulation with the esc key.
115+
plt.gcf().canvas.mpl_connect('key_release_event',
116+
lambda event: [exit(0) if event.key == 'escape' else None])
114117
ax.set_zlim(0, z_c * 2)
115118
ax.set_aspect('equal', 'datalim')
116119

Localization/ensemble_kalman_filter/ensemble_kalman_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ def main():
213213

214214
if show_animation:
215215
plt.cla()
216+
# for stopping simulation with the esc key.
217+
plt.gcf().canvas.mpl_connect('key_release_event',
218+
lambda event: [exit(0) if event.key == 'escape' else None])
216219

217220
for i in range(len(z[:, 0])):
218221
plt.plot([xTrue[0, 0], z[i, 2]], [xTrue[1, 0], z[i, 3]], "-k")

Localization/extended_kalman_filter/extended_kalman_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def main():
191191

192192
if show_animation:
193193
plt.cla()
194+
# for stopping simulation with the esc key.
195+
plt.gcf().canvas.mpl_connect('key_release_event',
196+
lambda event: [exit(0) if event.key == 'escape' else None])
194197
plt.plot(hz[0, :], hz[1, :], ".g")
195198
plt.plot(hxTrue[0, :].flatten(),
196199
hxTrue[1, :].flatten(), "-b")

Localization/histogram_filter/histogram_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def main():
233233

234234
if show_animation:
235235
plt.cla()
236+
# for stopping simulation with the esc key.
237+
plt.gcf().canvas.mpl_connect('key_release_event',
238+
lambda event: [exit(0) if event.key == 'escape' else None])
236239
draw_heat_map(grid_map.data, mx, my)
237240
plt.plot(xTrue[0, :], xTrue[1, :], "xr")
238241
plt.plot(RF_ID[:, 0], RF_ID[:, 1], ".k")

Localization/particle_filter/particle_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ def main():
230230

231231
if show_animation:
232232
plt.cla()
233+
# for stopping simulation with the esc key.
234+
plt.gcf().canvas.mpl_connect('key_release_event',
235+
lambda event: [exit(0) if event.key == 'escape' else None])
233236

234237
for i in range(len(z[:, 0])):
235238
plt.plot([xTrue[0, 0], z[i, 1]], [xTrue[1, 0], z[i, 2]], "-k")

Localization/unscented_kalman_filter/unscented_kalman_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ def main():
240240

241241
if show_animation:
242242
plt.cla()
243+
# for stopping simulation with the esc key.
244+
plt.gcf().canvas.mpl_connect('key_release_event',
245+
lambda event: [exit(0) if event.key == 'escape' else None])
243246
plt.plot(hz[0, :], hz[1, :], ".g")
244247
plt.plot(np.array(hxTrue[0, :]).flatten(),
245248
np.array(hxTrue[1, :]).flatten(), "-b")

Mapping/circle_fitting/circle_fitting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def main():
124124

125125
if show_animation: # pragma: no cover
126126
plt.cla()
127+
# for stopping simulation with the esc key.
128+
plt.gcf().canvas.mpl_connect('key_release_event',
129+
lambda event: [exit(0) if event.key == 'escape' else None])
127130
plt.axis("equal")
128131
plt.plot(0.0, 0.0, "*r")
129132
plot_circle(cx, cy, cr)

Mapping/gaussian_grid_map/gaussian_grid_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def main():
7373

7474
if show_animation: # pragma: no cover
7575
plt.cla()
76+
# for stopping simulation with the esc key.
77+
plt.gcf().canvas.mpl_connect('key_release_event',
78+
lambda event: [exit(0) if event.key == 'escape' else None])
7679
draw_heatmap(gmap, minx, maxx, miny, maxy, xyreso)
7780
plt.plot(ox, oy, "xr")
7881
plt.plot(0.0, 0.0, "ob")

Mapping/kmeans_clustering/kmeans_clustering.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ def main():
133133
# for animation
134134
if show_animation: # pragma: no cover
135135
plt.cla()
136+
# for stopping simulation with the esc key.
137+
plt.gcf().canvas.mpl_connect('key_release_event',
138+
lambda event: [exit(0) if event.key == 'escape' else None])
136139
clusters.plot_cluster()
137-
138140
plt.plot(cx, cy, "or")
139141
plt.xlim(-2.0, 10.0)
140142
plt.ylim(-2.0, 10.0)

Mapping/raycasting_grid_map/raycasting_grid_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def main():
124124

125125
if show_animation: # pragma: no cover
126126
plt.cla()
127+
# for stopping simulation with the esc key.
128+
plt.gcf().canvas.mpl_connect('key_release_event',
129+
lambda event: [exit(0) if event.key == 'escape' else None])
127130
draw_heatmap(pmap, minx, maxx, miny, maxy, xyreso)
128131
plt.plot(ox, oy, "xr")
129132
plt.plot(0.0, 0.0, "ob")

Mapping/rectangle_fitting/rectangle_fitting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ def main():
242242

243243
if show_animation: # pragma: no cover
244244
plt.cla()
245+
# for stopping simulation with the esc key.
246+
plt.gcf().canvas.mpl_connect('key_release_event',
247+
lambda event: [exit(0) if event.key == 'escape' else None])
245248
plt.axis("equal")
246249
plt.plot(0.0, 0.0, "*r")
247250
v1.plot()

PathPlanning/AStar/a_star.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def planning(self, sx, sy, gx, gy):
7979
if show_animation: # pragma: no cover
8080
plt.plot(self.calc_grid_position(current.x, self.minx),
8181
self.calc_grid_position(current.y, self.miny), "xc")
82+
# for stopping simulation with the esc key.
83+
plt.gcf().canvas.mpl_connect('key_release_event',
84+
lambda event: [exit(0) if event.key == 'escape' else None])
8285
if len(closed_set.keys()) % 10 == 0:
8386
plt.pause(0.001)
8487

PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ def update_graph(self):
534534
def draw_graph(self, xCenter=None, cBest=None, cMin=None, etheta=None,
535535
samples=None, start=None, end=None):
536536
plt.clf()
537+
# for stopping simulation with the esc key.
538+
plt.gcf().canvas.mpl_connect('key_release_event',
539+
lambda event: [exit(0) if event.key == 'escape' else None])
537540
for rnd in samples:
538541
if rnd is not None:
539542
plt.plot(rnd[0], rnd[1], "^k")

PathPlanning/ClosedLoopRRTStar/pure_pursuit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ def closed_loop_prediction(cx, cy, cyaw, speed_profile, goal):
135135

136136
if target_ind % 1 == 0 and animation: # pragma: no cover
137137
plt.cla()
138+
# for stopping simulation with the esc key.
139+
plt.gcf().canvas.mpl_connect('key_release_event',
140+
lambda event: [exit(0) if event.key == 'escape' else None])
138141
plt.plot(cx, cy, "-r", label="course")
139142
plt.plot(x, y, "ob", label="trajectory")
140143
plt.plot(cx[target_ind], cy[target_ind], "xg", label="target")

PathPlanning/Dijkstra/dijkstra.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def planning(self, sx, sy, gx, gy):
6969
if show_animation: # pragma: no cover
7070
plt.plot(self.calc_position(current.x, self.minx),
7171
self.calc_position(current.y, self.miny), "xc")
72+
# for stopping simulation with the esc key.
73+
plt.gcf().canvas.mpl_connect('key_release_event',
74+
lambda event: [exit(0) if event.key == 'escape' else None])
7275
if len(closedset.keys()) % 10 == 0:
7376
plt.pause(0.001)
7477

PathPlanning/DubinsPath/dubins_path_planning.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ def test():
318318

319319
if show_animation:
320320
plt.cla()
321+
# for stopping simulation with the esc key.
322+
plt.gcf().canvas.mpl_connect('key_release_event',
323+
lambda event: [exit(0) if event.key == 'escape' else None])
321324
plt.plot(px, py, label="final course " + str(mode))
322325

323326
# plotting

PathPlanning/DynamicWindowApproach/dynamic_window_approach.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ def main(gx=10.0, gy=10.0, robot_type=RobotType.circle):
268268

269269
if show_animation:
270270
plt.cla()
271+
# for stopping simulation with the esc key.
272+
plt.gcf().canvas.mpl_connect('key_release_event',
273+
lambda event: [exit(0) if event.key == 'escape' else None])
271274
plt.plot(predicted_trajectory[:, 0], predicted_trajectory[:, 1], "-g")
272275
plt.plot(x[0], x[1], "xr")
273276
plt.plot(goal[0], goal[1], "xb")

PathPlanning/Eta3SplinePath/eta3_spline_path.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ def test1():
213213
if show_animation:
214214
# plot the path
215215
plt.plot(pos[0, :], pos[1, :])
216+
# for stopping simulation with the esc key.
217+
plt.gcf().canvas.mpl_connect('key_release_event',
218+
lambda event: [exit(0) if event.key == 'escape' else None])
216219
plt.pause(1.0)
217220

218221
if show_animation:

PathPlanning/FrenetOptimalTrajectory/frenet_optimal_trajectory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ def main():
347347

348348
if show_animation: # pragma: no cover
349349
plt.cla()
350+
# for stopping simulation with the esc key.
351+
plt.gcf().canvas.mpl_connect('key_release_event',
352+
lambda event: [exit(0) if event.key == 'escape' else None])
350353
plt.plot(tx, ty)
351354
plt.plot(ob[:, 0], ob[:, 1], "xk")
352355
plt.plot(path.x[1:], path.y[1:], "-or")

PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ def sweep_path_search(sweep_searcher, gmap, grid_search_animation=False):
213213

214214
if grid_search_animation:
215215
fig, ax = plt.subplots()
216+
# for stopping simulation with the esc key.
217+
fig.canvas.mpl_connect('key_release_event',
218+
lambda event: [exit(0) if event.key == 'escape' else None])
216219

217220
while True:
218221
cxind, cyind = sweep_searcher.move_target_grid(cxind, cyind, gmap)
@@ -266,6 +269,9 @@ def planning_animation(ox, oy, reso): # pragma: no cover
266269
if do_animation:
267270
for ipx, ipy in zip(px, py):
268271
plt.cla()
272+
# for stopping simulation with the esc key.
273+
plt.gcf().canvas.mpl_connect('key_release_event',
274+
lambda event: [exit(0) if event.key == 'escape' else None])
269275
plt.plot(ox, oy, "-xb")
270276
plt.plot(px, py, "-r")
271277
plt.plot(ipx, ipy, "or")

PathPlanning/HybridAStar/a_star.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def dp_planning(sx, sy, gx, gy, ox, oy, reso, rr):
7878
# show graph
7979
if show_animation: # pragma: no cover
8080
plt.plot(current.x * reso, current.y * reso, "xc")
81+
# for stopping simulation with the esc key.
82+
plt.gcf().canvas.mpl_connect('key_release_event',
83+
lambda event: [exit(0) if event.key == 'escape' else None])
8184
if len(closedset.keys()) % 10 == 0:
8285
plt.pause(0.001)
8386

@@ -228,4 +231,4 @@ def main():
228231

229232
if __name__ == '__main__':
230233
show_animation = True
231-
main()
234+
main()

PathPlanning/HybridAStar/hybrid_a_star.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ def hybrid_a_star_planning(start, goal, ox, oy, xyreso, yawreso):
327327

328328
if show_animation: # pragma: no cover
329329
plt.plot(current.xlist[-1], current.ylist[-1], "xc")
330+
# for stopping simulation with the esc key.
331+
plt.gcf().canvas.mpl_connect('key_release_event',
332+
lambda event: [exit(0) if event.key == 'escape' else None])
330333
if len(closedList.keys()) % 10 == 0:
331334
plt.pause(0.001)
332335

PathPlanning/InformedRRTStar/informed_rrt_star.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ def get_final_course(self, lastIndex):
266266
return path
267267

268268
def draw_graph(self, xCenter=None, cBest=None, cMin=None, etheta=None, rnd=None):
269-
270269
plt.clf()
270+
# for stopping simulation with the esc key.
271+
plt.gcf().canvas.mpl_connect('key_release_event',
272+
lambda event: [exit(0) if event.key == 'escape' else None])
271273
if rnd is not None:
272274
plt.plot(rnd[0], rnd[1], "^k")
273275
if cBest != float('inf'):

PathPlanning/LQRPlanner/LQRplanner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def lqr_planning(self, sx, sy, gx, gy, show_animation=True):
5454

5555
# animation
5656
if show_animation: # pragma: no cover
57+
# for stopping simulation with the esc key.
58+
plt.gcf().canvas.mpl_connect('key_release_event',
59+
lambda event: [exit(0) if event.key == 'escape' else None])
5760
plt.plot(sx, sy, "or")
5861
plt.plot(gx, gy, "ob")
5962
plt.plot(rx, ry, "-r")

PathPlanning/LQRRRTStar/lqr_rrt_star.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def planning(self, animation=True, search_until_max_iter=True):
102102

103103
def draw_graph(self, rnd=None):
104104
plt.clf()
105+
# for stopping simulation with the esc key.
106+
plt.gcf().canvas.mpl_connect('key_release_event',
107+
lambda event: [exit(0) if event.key == 'escape' else None])
105108
if rnd is not None:
106109
plt.plot(rnd.x, rnd.y, "^k")
107110
for node in self.node_list:

PathPlanning/PotentialFieldPlanning/potential_field_planning.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def potential_field_planning(sx, sy, gx, gy, ox, oy, reso, rr):
9898

9999
if show_animation:
100100
draw_heatmap(pmap)
101+
# for stopping simulation with the esc key.
102+
plt.gcf().canvas.mpl_connect('key_release_event',
103+
lambda event: [exit(0) if event.key == 'escape' else None])
101104
plt.plot(ix, iy, "*k")
102105
plt.plot(gix, giy, "*m")
103106

PathPlanning/ProbabilisticRoadMap/probabilistic_road_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ def dijkstra_planning(sx, sy, gx, gy, ox, oy, rr, road_map, sample_x, sample_y):
194194

195195
# show graph
196196
if show_animation and len(closedset.keys()) % 2 == 0:
197+
# for stopping simulation with the esc key.
198+
plt.gcf().canvas.mpl_connect('key_release_event',
199+
lambda event: [exit(0) if event.key == 'escape' else None])
197200
plt.plot(current.x, current.y, "xg")
198201
plt.pause(0.001)
199202

PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def quintic_polynomials_planner(sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_
151151
if show_animation: # pragma: no cover
152152
for i, _ in enumerate(time):
153153
plt.cla()
154+
# for stopping simulation with the esc key.
155+
plt.gcf().canvas.mpl_connect('key_release_event',
156+
lambda event: [exit(0) if event.key == 'escape' else None])
154157
plt.grid(True)
155158
plt.axis("equal")
156159
plot_arrow(sx, sy, syaw)

PathPlanning/RRT/rrt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def get_random_node(self):
138138

139139
def draw_graph(self, rnd=None):
140140
plt.clf()
141+
# for stopping simulation with the esc key.
142+
plt.gcf().canvas.mpl_connect('key_release_event',
143+
lambda event: [exit(0) if event.key == 'escape' else None])
141144
if rnd is not None:
142145
plt.plot(rnd.x, rnd.y, "^k")
143146
for node in self.node_list:

0 commit comments

Comments
 (0)