-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate_woodpecker.py
66 lines (55 loc) · 1.69 KB
/
simulate_woodpecker.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
import numpy as np
from assimulo.problem import Implicit_Problem #Imports the problem formulation from Assimulo
from assimulo.solvers import IDA #Imports the solver IDA from Assimulo
from woodpecker import *
import matplotlib.pyplot as P
def run_example():
#initial values
t0 = 0
y0 = np.array([0., -0.10344, -0.65, 0., 0. , 0., -0.628993, 0.047088]) #|phi_s| <= 0.1034 rad, |phi_b| <= 0.12 rad
yd0 = np.array([0., 0., 0., 0., 0., 0., 0., 0.])
sw = [False, True, False]
#problem
model = Implicit_Problem(pecker, y0, yd0, t0, sw0=sw)
model.state_events = state_events #from woodpecker.py
model.handle_event = handle_event #from woodpecker.py
model.name = 'Woodpeckermodel'
sim = IDA(model) #create IDA solver
tfinal = 2.0 #final time
ncp = 500 #number control points
sim.suppress_alg = True
sim.rtol=1.e-6
sim.atol[6:8] = 1e6
sim.algvar[6:8] = 0
t, y, yd = sim.simulate(tfinal, ncp) #simulate
#plot
fig, ax = P.subplots()
ax.plot(t, y[:, 0], label='z')
legend = ax.legend(loc='upper center', shadow=True)
P.grid()
P.figure(1)
fig2, ax2 = P.subplots()
ax2.plot(t, y[:, 1], label='phi_s')
ax2.plot(t, y[:, 2], label='phi_b')
legend = ax2.legend(loc='upper center', shadow=True)
P.grid()
P.figure(2)
fig3, ax3 = P.subplots()
ax3.plot(t, y[:, 4], label='phi_sp')
ax3.plot(t, y[:, 5], label='phi_bp')
legend = ax3.legend(loc='upper center', shadow=True)
P.grid()
P.figure(3)
fig4, ax4 = P.subplots()
ax4.plot(t, y[:, 6], label='lambda_1')
ax4.plot(t, y[:, 7], label='lambda_2')
legend = ax4.legend(loc='upper right', shadow=True)
P.grid()
#event data
sim.print_event_data()
#show plots
P.show()
print("...")
P.show()
if __name__=='__main__':
run_example()