Skip to content

Commit e977705

Browse files
author
Tullio Facchinetti
committed
Improved the animation of the arm navigation example
1 parent 11a3f86 commit e977705

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ArmNavigation/arm_obstacle_navigation/arm_obstacle_navigation_2.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@
1313
plt.ion()
1414

1515
# Simulation parameters
16-
M = 50
16+
M = 50 # number of squares to divide the x-y axes of the configuration space
17+
# M = 200 # number of squares to divide the x-y axes of the configuration space
18+
delay = 0.5 # delay between consecutive frames in the simulation
1719
obstacles = [[1.75, 0.3, 0.6], [0.55, 1.5, 0.5], [0, -1, 0.7]]
1820

1921

22+
in_pause = False
23+
24+
2025
def press(event):
2126
"""Exit from the simulation."""
27+
global in_pause
2228
if event.key == 'q' or event.key == 'Q':
2329
print('Quitting upon request.')
2430
sys.exit(0)
31+
if event.key == ' ':
32+
in_pause = not in_pause
2533

2634

2735
def main():
@@ -39,6 +47,7 @@ def main():
3947

4048

4149
def animate(grid, arm, route):
50+
global in_pause
4251
fig, axs = plt.subplots(1, 2)
4352
fig.canvas.mpl_connect('key_press_event', press)
4453
colors = ['white', 'black', 'red', 'pink', 'yellow', 'green', 'orange']
@@ -59,7 +68,12 @@ def animate(grid, arm, route):
5968
plt.show()
6069
# Uncomment here to save the sequence of frames
6170
# plt.savefig('frame{:04d}.png'.format(i))
62-
plt.pause(0.1)
71+
while in_pause:
72+
plt.pause(delay)
73+
plt.pause(delay)
74+
in_pause = True
75+
while in_pause:
76+
plt.pause(delay)
6377

6478

6579
def detect_collision(line_seg, circle):

0 commit comments

Comments
 (0)