I'm trying to animate the links of a robot without success. FuncAnimation never calls the animate function -- the print statement is never executed. Any help would be greatly appreciated. My code:
def foo():
joints = np.array([robot_kinematics.getJoints(a[0]) for a in path])
# this is [5x9x3]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
colors = 'brgymcwkk'
lines = [ax.plot([], [], [])[0] for i,c in enumerate(colors)]
pt = ax.plot([], [], [])[0]
def animate(i,lines,pts):
print ('called')
for j,line in enumerate(lines):
line.set_data(joints[i,j,0:2])
line.set_3d_properties(joints[i,j,2])
pts.set_data(joints[i,:,0:2])
pts.set_3d_properties(joints[i,:,2])
return lines,pts
a = animation.FuncAnimation(fig, animate, 25, fargs=(lines,pt),interval=50, blit=False)
plt.show()
foo()
The object created by FuncAnimation must be assigned to a global variable apparently; if it's assigned to a local variable, as I did here, nothing will happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With