-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.py
More file actions
57 lines (42 loc) · 976 Bytes
/
simulation.py
File metadata and controls
57 lines (42 loc) · 976 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 1 14:58:12 2020
@author: ejalaa
"""
import numpy as np
from models.model1D import Model
from control.pid import PID
import matplotlib.pyplot as plt
# %% External forces
def external_force(t):
wind = np.sin(t * 0.07) + 0.5 * np.cos(t * 0.012)
total = wind
return total
# %% Consigne
def w(t):
if t < 150:
return 0
elif 150 < t < 200:
return 10
else:
return 20 * np.cos(t * 0.01)
# %% SIMULATION
if __name__ == "__main__":
import matplotlib.pyplot as plt
m = Model(1, 0, k=0.2)
pid = PID(10, 1.0, 80, 0)
dt = 0.1
TIME = np.arange(0, 400, dt)
W = []
for t in TIME:
fe = external_force(t)
fpid = pid.control(m.x, w(t), t)
W.append(w(t))
f = fe + fpid
# print fe, fpid
m.evolve(f, dt)
ax1, ax2 = m.plot(TIME)
ax1.plot(TIME, W)
plt.show()
plt.show()