-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patheqnmot.jl
More file actions
62 lines (61 loc) · 1.61 KB
/
Copy patheqnmot.jl
File metadata and controls
62 lines (61 loc) · 1.61 KB
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
# DESCRIPTION
# Rigid-body equations of motion.
#
# INPUT
# - xf: fuselage states
# - Ftot: net forces acting at the CG
# - Mtot: net moments acting on the CG
#
# OUTPUT
# - xfdot: rigid-body dynamics
#
# ------------------------------------------------------------------------------
function eqnmot(xf,Ftot,Mtot)
# unpack forces and moments
X=Ftot[1]
Y=Ftot[2]
Z=Ftot[3]
L=Mtot[1]
M=Mtot[2]
N=Mtot[3]
# unpack states
u=xf[1]
v=xf[2]
w=xf[3]
p=xf[4]
q=xf[5]
r=xf[6]
phi=xf[7]
theta=xf[8]
psi=xf[9]
# trig functions
cphi=cos(phi)
sphi=sin(phi)
cthe=cos(theta)
sthe=sin(theta)
cpsi=cos(psi)
spsi=sin(psi)
# state derivative vector
xf_dot=zeros(12)
# equations of motion
# velocities
xfdot=zeros(NFSTATES)
xfdot[1]=X/MASS-G*sthe-q*w+r*v
xfdot[2]=Y/MASS+G*cthe*sphi-r*u+p*w
xfdot[3]=Z/MASS+G*cthe*cphi-p*v+q*u
# angular rates
gam=IX*IZ-IXZ^2;
xfdot[4]=(IZ*L+IXZ*N+IXZ*(IX-IY+IZ)*p*q-(IZ^2-IY*IZ+IXZ^2)*q*r)/gam
xfdot[5]=(M+(IZ-IX)*p*r-IXZ*(p^2-r^2))/IY
xfdot[6]=(IX*N+IXZ*L-IXZ*(IX-IY+IZ)*q*r+(IX^2-IX*IY+IXZ^2)*p*q)/gam
# attitude
xfdot[7]=p+q*sphi*sthe/cthe+r*cphi*sthe/cthe
xfdot[8]=q*cphi-r*sphi
xfdot[9]=q*sphi/cthe+r*cphi/cthe
# position
xfdot[10]=u*cthe*cpsi+v*(sphi*sthe*cpsi-cphi*spsi)+w*(cphi*sthe*cpsi+sphi*spsi)
xfdot[11]=u*cthe*spsi+v*(sphi*sthe*spsi+cphi*cpsi)+w*(cphi*sthe*spsi-sphi*cpsi)
xfdot[12]=-u*sthe+v*sphi*cthe+w*cphi*cthe
# return state derivative vector
return xfdot
end