Numerik Praktikum 7¶
Aufgaben:
Template für Roboterarm Movie¶
# Python Template fuer Movie
#
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.animation import FuncAnimation
fig = plt.figure(figsize=(6,6))
l1, = plt.plot([], [])
l2, = plt.plot([], [],'o')
# p: Funktion zur Berechnung der Punkte auf der Trajektorie
# ti: wird auch für die Berechnung der Winkel benutzt
ti = np.linspace(0,4,int(4/.01+1))
pi = np.array([p(tii) for tii in ti])
# Plot der Punkte der Trajektorie
plt.plot(pi[:,0],pi[:,1],'-',alpha=0.5)
plt.xlim(-3,3)
plt.ylim(-3,3)
plt.gca().set_aspect(1)
plt.gca().add_patch(mpatches.Circle((0,0), 2-1,alpha=0.1))
plt.gca().add_patch(mpatches.Circle((0,0), 2+1,alpha=0.1))
plt.grid()
plt.xlabel('x')
plt.ylabel('y')
# si: Liste der Winkel fuer die Trajektorie
# PG(theta1, theta2): Funktion zur Berechnung der Drehpunkte und des Endpunkts des Roboters. Bsp:
# array([[0. , 0. ], # Ursprung
# [0.58856217, 1.91143783], # 1. Drehpunkt
# [1. , 1. ]]) # 2. Drehpunkt / Endpunkt
def animate(i):
l1.set_data(*PG(*si[i]).T)
l2.set_data(*PG(*si[i]).T)
return l1,l2
ani = FuncAnimation(fig, animate, blit=True, frames=len(si))
ani.save('Trajektorie.gif', writer='pillow', fps=50)
- Downloads:
PDF-Dokumentation: