-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplant.py
68 lines (55 loc) · 2.28 KB
/
plant.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
import numpy as np
from math import sin
from scipy.integrate import odeint
from numpy import linspace
class plant:
def __init__(self):
return
def helicopter(self, y, t, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, u0, u1):
x, y1, y2, z1, z2 = y
#u0 = np.real(a10*x**2*sin((2*a2*a7 - a4*x**2 + x*(4*a3*a2**2*x**2 - 4*a1*a2*a4*x**2 - 4*a7*a2*a4 + a4**2*x**2)**0.5 + 2*a1*a2*x**2)/(2*a2**2*x**2)) - a8*x - a9*x**2 - a11)
#u1 = np.real((a13*(x*(4*a3*a2**2*x**2 - 4*a1*a2*a4*x**2 - 4*a6*a2*a4*y2**2 - 4*a5*a2*a4*y2 - 4*a7*a2*a4 + a4**2*x**2)**0.5 + 2*a2*a7 - a4*x**2 + 2*a2*a5*y2 + 2*a1*a2*x**2 + 2*a2*a6*y2**2))/(2*a2**2*x**2) - a14*x**2*sin(z1) - a12)
dydt = [a8 * x + a10 * (x ** 2) * sin(z1) + a9 * (x ** 2) + a11 + u0 , y2, (x**2) * (a1 + a2 * z1 - (a3 + a4 * z1)**(1 / 2)) + a5 * y2 + a6 * (y2**2) + a7, z2, a13 * z1 + a14 * (x ** 2) * sin(z1) + a15 * z2 + a12 + u1]
return dydt
def Predict(self, x):
t = linspace(0, 0.0002, 5000)
a1 = 5.19791e-4
a2 = 1.51992e-2
a3 = 2.70183e-7
a4 = 1.58009e-5
a5 = -0.1
a6 = -0.1
a7 = -17.67
a8 = -0.7
a9 = -0.0028
a10 = -0.0028
a11 = -13.92
a12 = 434.88
a13 = -800
a14 = -0.1
a15 = -65
u0, u1 = x[5:]
sol = odeint(self.helicopter, x[:5], t, args=(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, u0, u1))
end = len(sol)
sol[end-1]=np.real(sol[end-1])
if sol[end-1,0] < 74.25:
sol[end-1,0] = 74.25
if sol[end-1,0] > 180:
sol[end-1,0] = 180
if sol[end-1,1] < 0:
sol[end-1,1] = 0.00001
if sol[end-1,1] > 2:
sol[end-1,1] = 2
if sol[end-1,2] < -2.85:
sol[end-1,2] = -2.85
if sol[end-1,2] > 5.70:
sol[end-1,2] = 5.70
if sol[end-1,3] < (1.75 * 10 ** (-2)):
sol[end-1,3] = (1.75 * 10 ** (-2))
if sol[end-1,3] > (2.45 * 10 ** (-1)):
sol[end-1,3] = (2.45 * 10 ** (-1))
if sol[end-1,4] < -9.52:
sol[end-1,4] = -9.52
if sol[end-1,4] > 9.52:
sol[end-1,4] = 9.52
return sol[end-1]