-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyro_animation.py
75 lines (64 loc) · 2.54 KB
/
pyro_animation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import matplotlib.pyplot as pltp
from matplotlib import animation, rc
from sympy import *
import numpy as np
from IPython.display import HTML
Animatrix = []
COMindex = []
PoseX = []
PoseY = []
PoseZ = []
fig_anim = []
line = []
time_text = []
time_template = []
ax = []
ani = []
delta_time = []
def init():
global line, time_text
line.set_data([],[])
time_text.set_text('')
return line, time_text
def animator(i):
global line, time_text, time_template
thisx = flatten(PoseX[:,i].T)
thisy = flatten(PoseY[:,i].T)
line.set_data(thisx, thisy)
time_text.set_text(time_template % (i * delta_time))
return line, time_text
def fireAnimation(animationMatrix, idCOM, q_var, q_value, parameters, values, dt, orientation = [0,1,2]):
global Animatrix, Idcom, line, time_template, time_text, fig_anim, ax, ani, delta_time
delta_time = dt
Animatrix = animationMatrix
COMindex = idCOM
evaluatePose(Animatrix, q_var, q_value, parameters, values, orientation)
fig_anim = plt.figure()
ax = fig_anim.add_subplot(111, autoscale_on=False, xlim=(-1.2, 1.2), ylim=(-1.2, 1.2))
ax.grid()
line, = ax.plot([], [],'o-',lw=2)
ax.set_aspect('equal')
time_template = 'time = %.1fs'
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)
rc('animation', html='html5')
ani = animation.FuncAnimation(fig_anim, animator, np.arange(1, PoseX.shape[1]), interval = delta_time * 1000, blit = True, init_func = init)
#ani.save("animationVid.mp4", fps = 30, extra_args=['-vcodec', 'libx264'])
#plt.show()
return ani
def evalVars(matrix, q_var, q_value_x, parameters, values):
vMat = matrix
for i in range(len(q_var)):
vMat = vMat.subs(q_var[i], q_value_x[i])
for i in range(len(parameters)):
vMat = vMat.subs(parameters[i], values[i])
return vMat
def evaluatePose(matrix,q_var, q_value, parameters, values, orientation):
global PoseX, PoseY, PoseZ
PoseX = zeros(matrix.shape[0],q_value.shape[0])
PoseY = zeros(matrix.shape[0],q_value.shape[0])
PoseZ = zeros(matrix.shape[0],q_value.shape[0])
for i in range(q_value.shape[0]):
PoseX[0,i] = np.sign(orientation[0] + 0.1) * evalVars(matrix[:,abs(orientation[0])], q_var, q_value[i,:], parameters, values)
PoseY[0,i] = np.sign(orientation[1] + 0.1) * evalVars(matrix[:,abs(orientation[1])], q_var, q_value[i,:], parameters, values)
PoseZ[0,i] = np.sign(orientation[2] + 0.1) * evalVars(matrix[:,abs(orientation[2])], q_var, q_value[i,:], parameters, values)
return PoseX, PoseY, PoseZ