In [1]:
import sympy as sm
# make the math look pretty
sm.init_printing()

In [33]:
# define all the symbols we will be using
#env parameters
g = sm.Symbol("g")
rho = sm.Symbol("rho")

#wind parameters
#thermals modelled with vertical airflows only

# vehicle parameters
e = sm.Symbol("e")
alph0 = sm.Symbol("alpha_0")
AR = sm.Symbol("AR")
m = sm.Symbol("m")
l = sm.Symbol("l")
Vh = sm.Symbol("V_H")
Vv = sm.Symbol("V_V")
Rf = sm.Symbol("V_F")
CLmin = sm.Symbol("C_{L_{min}}")
Cd0 = sm.Symbol("C_{D_0}")
Cdf = sm.Symbol("C_{D_f}")
CdL = sm.Symbol("C_{d_L}")
Cde = sm.Symbol("C_{d_e}")
Cdt = sm.Symbol("C_{d_t}")
a0 = sm.Symbol("a_0")


#variables
alpha = sm.Symbol("alpha")
alphaw = sm.Symbol("alpha_w")
beta = sm.Symbol("beta")
betaw = sm.Symbol("beta_w")
x = sm.Symbol("x")
y = sm.Symbol("y")
h = sm.Symbol("h")
chi = sm.Symbol("chi")
gamma = sm.Symbol("gamma")
sigma = sm.Symbol("sigma")
chiw = sm.Symbol("chi_w")
gammaw = sm.Symbol("gamma_w")
sigmaw = sm.Symbol("sigma_w")
V = sm.Symbol("V")
Vw = sm.Symbol("V_w")
D = sm.Symbol("D")
L = sm.Symbol("L")
C = sm.Symbol("C")

In [39]:
# relations
q = 1./2.*rho*(V**2)
qw = 1./2.*rho*(Vw**2)
S = (l**2)/AR
cbar = 1.03*l/AR
lt = 0.28*l
lf = 0.5*l
S = l**2/AR
St = Vh*cbar*S/lt
Sv = Vv*l*S/lt
Sf = 2.0*sm.pi*Rf*l*lf
ARv = 0.5*AR

Rvi = sm.Matrix([[sm.cos(chi),-sm.sin(chi),0.],[sm.sin(chi),sm.cos(chi),0.],[0.,0.,1.]])*sm.Matrix([[sm.cos(gamma),0.,sm.sin(gamma)],[0.,1.,0.],[-sm.sin(gamma),0.,sm.cos(gamma)]])*sm.Matrix([[1.,0.,0.],[0.,sm.cos(sigma),-sm.sin(sigma)],[0.,sm.sin(sigma),sm.cos(sigma)]])
Rbv = sm.Matrix([[sm.cos(alpha),0.,sm.sin(alpha)],[0.,1.,0.],[-sm.sin(alpha),0.,sm.cos(alpha)]])*sm.Matrix([[sm.cos(beta),sm.sin(beta),0.],[-sm.sin(beta),sm.cos(beta),0.],[0.,0.,1.]])

Tiv = Rvi

Rwi = Rvi.subs(chi,chiw).subs(gamma,gammaw).subs(sigma,sigmaw)
Rbw = Rbv.subs(alpha,alphaw).subs(beta,betaw)

#aerodynamics
#lift
CLa = a0 / (1.0+a0/(sm.pi*e*AR))

#drag
CD0 = Cdf*Sf/S + Cdt*(St + Sv)/S + Cde + Cd0
Rwi


Out[39]:
$$\left[\begin{matrix}1.0 \cos{\left (\chi_{w} \right )} \cos{\left (\gamma_{w} \right )} & - 1.0 \sin{\left (\chi_{w} \right )} \cos{\left (\sigma_{w} \right )} + \sin{\left (\gamma_{w} \right )} \sin{\left (\sigma_{w} \right )} \cos{\left (\chi_{w} \right )} & 1.0 \sin{\left (\chi_{w} \right )} \sin{\left (\sigma_{w} \right )} + \sin{\left (\gamma_{w} \right )} \cos{\left (\chi_{w} \right )} \cos{\left (\sigma_{w} \right )}\\1.0 \sin{\left (\chi_{w} \right )} \cos{\left (\gamma_{w} \right )} & \sin{\left (\chi_{w} \right )} \sin{\left (\gamma_{w} \right )} \sin{\left (\sigma_{w} \right )} + 1.0 \cos{\left (\chi_{w} \right )} \cos{\left (\sigma_{w} \right )} & \sin{\left (\chi_{w} \right )} \sin{\left (\gamma_{w} \right )} \cos{\left (\sigma_{w} \right )} - 1.0 \sin{\left (\sigma_{w} \right )} \cos{\left (\chi_{w} \right )}\\- 1.0 \sin{\left (\gamma_{w} \right )} & 1.0 \sin{\left (\sigma_{w} \right )} \cos{\left (\gamma_{w} \right )} & 1.0 \cos{\left (\gamma_{w} \right )} \cos{\left (\sigma_{w} \right )}\end{matrix}\right]$$

In [28]:
# forces
#lift
CL = CLa*(alphaw - alph0)
Lw = qw*S*CL

#side
CC = CLa*Sv/S*betaw
Cw = qw*S*CC

#drag
CD = CD0 + CdL*((CL - CLmin)**2) + (CL**2)/(sm.pi*e*AR) + (Cw**2)/(sm.pi*e*AR)*(S/Sv)
Dw = qw*S*CD

In [24]:
# Dynamics
z = -h
dh = V*sm.sin(gamma)
dz = -dh
dx = V*sm.cos(chi)*sm.cos(gamma)
dy = V*sm.sin(chi)*sm.cos(gamma)
dV = -D/m-g*sm.sin(gamma)
dgamma = 1.0/(m*V)*(L*sm.cos(sigma) + C*sm.sin(sigma))-g/V*sm.cos(gamma)
dchi = 1.0/(m*V*sm.cos(gamma))*(L*sm.sin(sigma) - C*sm.cos(sigma))
f = sm.Matrix([[dh],[dx],[dy],[dV],[dgamma],[dchi]])


Vvec = sm.Matrix([[dx],[dy],[dz]])

f


Out[24]:
$$\left[\begin{matrix}V \sin{\left (\gamma \right )}\\V \cos{\left (\chi \right )} \cos{\left (\gamma \right )}\\V \sin{\left (\chi \right )} \cos{\left (\gamma \right )}\\- \frac{D}{m} - g \sin{\left (\gamma \right )}\\- \frac{g}{V} \cos{\left (\gamma \right )} + \frac{1}{V m} \left(1.0 C \sin{\left (\sigma \right )} + 1.0 L \cos{\left (\sigma \right )}\right)\\\frac{1}{V m \cos{\left (\gamma \right )}} \left(- 1.0 C \cos{\left (\sigma \right )} + 1.0 L \sin{\left (\sigma \right )}\right)\end{matrix}\right]$$

In [85]:
sm.Matrix([f.diff(chi).transpose(), f.diff(gamma).transpose()]).transpose()


Out[85]:
$$\left[\begin{matrix}0 & V \cos{\left (\gamma \right )}\\- V \sin{\left (\chi \right )} \cos{\left (\gamma \right )} & - V \sin{\left (\gamma \right )} \cos{\left (\chi \right )}\\V \cos{\left (\chi \right )} \cos{\left (\gamma \right )} & - V \sin{\left (\chi \right )} \sin{\left (\gamma \right )}\\0 & - g \cos{\left (\gamma \right )}\\0 & \frac{g}{V} \sin{\left (\gamma \right )}\\0 & \frac{\sin{\left (\gamma \right )}}{V m \cos^{2}{\left (\gamma \right )}} \left(- C \cos{\left (\sigma \right )} + L \sin{\left (\sigma \right )}\right)\end{matrix}\right]$$

In [ ]: