API reference

# API reference

## ISA (atmosphere.jl)

atmosphere_isa(height)

Calculate temperature, pressure, density and sound velocity for the given geopotential height according to International Standard Atmosphere 1976.

References

• [1] U.S. Standard Atmosphere, 1976, U.S. Government Printing Office, Washington, D.C., 1976

From: https://en.wikipedia.org/wiki/U.S.StandardAtmosphere

Layerh (m)p (Pa)T (K)$α$ (K/m)
00101325288.15-0.0065
11100022632.1216.650
2200005474.89216.650.001
332000868.019228.650.0028
447000110.906270.650
55100066.9389270.65-0.0028
6710003.95642214.65-0.002

## Coordinates Systems (coordinates.jl)

body2ecef(xb, yb, zb, lat, lon, psi, theta, phi)

Transform body coordinates to ECEF coordinates.

Arguments

• xb, yb, zb: body coordinates.
• lat: geodetic latitude (rad).
• lon: longitude (rad).
• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).
body2ecef(xb, yb, zb, lat, lon, q0, q1, q2, q3)

Transform body coordinates to ECEF coordinates.

Arguments

• xb, yb, zb: body coordinates.
• lat: geodetic latitude (rad).
• lon: longitude (rad).
• q0, q1, q2, q3: quaternions.
body2hor(xb, yb, zb, psi, theta, phi)

Transform body coordinates to local horizon.

Arguments

• xb, yb, zb: body coordinates.
• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).
body2hor(xb, yb, zb, q0, q1, q2, q3)

Transform body coordinates to local horizon.

Arguments

• xb, yb, zb: body coordinates.
• q0, q1, q2, q3: quaternions.
body2wind(xb, yb, zb, alpha, beta)

Transform body coordinates to wind.

Arguments

• xb, yb, zb: body coordinates.
• alpha, beta: Aerodynamic angles. Angle of attack, angle of side-slip (rad).
ecef2body(xecef, yecef, zecef, lat, lon, psi, theta, phi)

Transform ECEF coordinates to body coordinates.

Arguments

• xecef, yecef, zecef: ECEF (Earth Centered Earth Fixed) coordinates.
• lat: geodetic latitude (rad).
• lon: longitude (rad).
• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).
ecef2body(xecef, yecef, zecef, lat, lon, q0, q1, q2, q3)

Transform ECEF coordinates to body coordinates.

Arguments

• xecef, yecef, zecef: ECEF (Earth Centered Earth Fixed) coordinates.
• lat: geodetic latitude (rad).
• lon: longitude (rad).
• q0, q1, q2, q3: quaternions.
ecef2hor(xecef, yecef, zecef, lat, lon)

Transform ECEF (Earth Fixed Earth Centered) coordinates to local horizon coordinates using geodetic latitude and longitude.

Arguments

• xecef, yecef, zecef: ECEF coordinates.
• lat: geodetic latitude (rad).
• lon: longitude (rad).

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 36, formula 1.4-9)

Notes

X, Y, Z ECEF are defined in a different way in [1]. In order to reproduce this transformation substitute in [1] Y->X, Z->Y, X->Z

[1] Only defines the opposite transformation. However this must be the transpose of hor2ecef.

ecef2llh(xecef, yecef, zecef; ellipsoid=WGS84)

Transform ECEF coordinates to geodetic latitude, longitude and ellipsoidal height for the given ellipsoid (default ellipsoid is WGS84)

References

• [1] Bowring, B. R. (1976). Transformation from spatial to geographical

coordinates. Survey review, 23(181), 323-327.

• [2] Bowring, B. R. (1985). The accuracy of geodetic latitude and height

equations. Survey Review, 28(218), 202-206.

Notes

• The transformation is direct without iterations as [1] introduced the need to

iterate for near Earth positions.

• [2] is an updated of increased accuracy of [1]. The former is used in this

implementation although the latter implementation is commented in the code.

• Model becomes unstable if latitude is close to 90º. An alternative equation

can be found in [2] equation (16) but has not been implemented.

euler2quaternion(psi, theta, phi)

Transform Euler angles orientation to quaternion orientation.

Arguments

• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).

References

• [1] Zipfel, P. H. (2007). Modeling and simulation of aerospace vehicle

dynamics. American Institute of Aeronautics and Astronautics. (page 126, formula 4.78)

hor2body(xh, yh, zh, psi, theta, phi)

Transform local horizon coordinates to body.

Arguments

• xh, yh, zh: local horizon coordinates.
• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).
hor2body(xb, yb, zb, q0, q1, q2, q3)

Transform local horizon corrdinates to body coordinates.

Arguments

• xh, yh, zh: local horizon coordinates.
• q0, q1, q2, q3: quaternions.
hor2ecef(xh, yh, zh, lat, lon)

Transform local horizon coordinates to ECEF (Earth Centered Earth Fixed) coordinates using geodetic latitude and longitude.

Arguments

• xh, yh, zh: local horizon coordinates.
• lat: geodetic latitude (rad).
• lon: longitude (rad).

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 36, formula 1.4-9)

Notes

X, Y, Z ECEF are defined in a different way in [1]. In order to reproduce this transformation substitute in [1] Y->X, Z->Y, X->Z

hor2wind(xh, yh, zh, chi, gamma, mu)

Transform local horizon coordinates to wind.

Arguments

• xh, yh, zh: local horizon coordinates.
• chi, gamma, mu: Velocity angles. Yaw (azimuth), pitch(elevation), roll (rad).
llh2ecef(lat, lon, height; ellipsoid=WGS84)

Transform geodetic latitude, longitude and ellipsoidal height to ECEF for the given ellipsoid (default ellipsoid is WGS84)

References

• [1] Rogers, R. M. (2007). Applied mathematics in integrated navigation

systems. American Institute of Aeronautics and Astronautics. (Page 75, equations 4.20, 4.21, 4.22)

quaternion2euler(q0, q1, q2, q3)

Transform quaternion orientation to Euler angles orientation.

Arguments

• q0, q1, q2, q3: quaternions.

References

• [1] Zipfel, P. H. (2007). Modeling and simulation of aerospace vehicle

dynamics. American Institute of Aeronautics and Astronautics. (page 127, formula 4.82)

rot_matrix_body2ecef(lat, lon, psi, theta, phi)

Rotation matrix to transform from body to ECEF

Arguments

• lat: geodetic latitude (rad).
• lon: longitude (rad).
• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 37, formula 1.4-11)

rot_matrix_body2ecef(lat, lon, q0, q1, q2, q3)

Rotation matrix to transform from body to ECEF

Arguments

• lat: geodetic latitude (rad).
• lon: longitude (rad).
• q0, q1, q2, q3: quaternions.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 37, formula 1.4-11)

rot_matrix_body2hor(q0, q1, q2, q3)

Rotation matrix to transform from body to local horizon.

Arguments

• q0, q1, q2, q3: quaternions.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 41, formula 1.4-23)

rot_matrix_body2hor(psi, theta, phi)

Rotation matrix from body to local horizon

Arguments

• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).
rot_matrix_ecef2body(lat, lon, psi, theta, phi)

Rotation matrix to transform from ECEF to body

Arguments

• lat: geodetic latitude (rad).
• lon: longitude (rad).
• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 37, formula 1.4-11)

rot_matrix_ecef2body(lat, lon, q0, q1, q2, q3)

Rotation matrix to transform from ECEF to body

Arguments

• lat: geodetic latitude (rad).
• lon: longitude (rad).
• q0, q1, q2, q3: quaternions.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 37, formula 1.4-11)

rot_matrix_ecef2hor(lat, lon)

Rotation matrix to transform from ECEF to local horizon.

Arguments

• lat, lon: geodetic latitude and longitude (rad)

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 36, formula 1.4-9)

Notes

X, Y, Z ECEF are defined in a different way in [1]. In order to reproduce this transformation substitute in [1] Y->X, Z->Y, X->Z

rot_matrix_hor2body(q0, q1, q2, q3)

Rotation matrix to transform from local horizon to body.

Arguments

• q0, q1, q2, q3: quaternions.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 41, formula 1.4-23)

rot_matrix_hor2body(psi, theta, phi)

Rotation matrix from body to local horizon

Arguments

• psi, theta, phi: Euler angles. Yaw, pitch, roll (rad).
rot_matrix_hor2ecef(lat, lon)

Rotation matrix to transform from local horizon to ECEF.

Arguments

• lat, lon: geodetic latitude and longitude (rad)

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 36, formula 1.4-9)

Notes

X, Y, Z ECEF are defined in a different way in [1]. In order to reproduce this transformation substitute in [1] Y->X, Z->Y, X->Z

wind2body(xw, yw, zw, alpha, beta)

Transform body coordinates to wind.

Arguments

• xw, yw, zw: wind coordinates.
• alpha, beta: Aerodynamic angles. Angle of attack, angle of side-slip (rad).
wind2hor(xw, yw, zw, chi, gamma, mu)

Transform wind coordinates to local horizon.

Arguments

• xw, yw, zw: wind coordinates.
• chi, gamma, mu: Velocity angles. Yaw (azimuth), pitch(elevation), roll (rad).

## Anemometry (anemometry.jl)

cas2eas(cas, ρ, p)

Calculate equivalent airspeed from calibrated airspeed, density (ρ) and pressure (p) at the current altitude.

cas2tas(cas, ρ, p)

Calculate true airspeed from calibrated airspeed, density (ρ) and pressure (p) at the current altitude.

compressible_qinf(tas, p, a)

Calculate compressible dynamic pressure from Mach number and static pressure (p)

Two different models are used depending on the Mach number:

• Subsonic case: Bernouilli's equation compressible form.
• Supersonic case: to be implemented.

References

• [1] Ward, D. T. (1993). Introduction to flight test engineering. Elsevier Science Ltd. (page 12)
eas2cas(eas, ρ, p)

Calculate calibrated airspeed from equivalent airspeed, density (ρ) and pressure (p) at the current altitude.

eas2tas(qc, ρ)

Calculate true airspeed from equivalent airspeed and density at current altitude (ρ).

References

• [1] Ward, D. T. (1993). Introduction to flight test engineering. Elsevier Science Ltd. (page 13, formula 2.15)
incompressible_qinf(tas, ρ)

Calculate incompressible dynamic pressure from true airspeed (tas) and density (ρ) at current altitude.

References

• [1] Ward, D. T. (1993). Introduction to flight test engineering. Elsevier Science Ltd. (page 13, formula 2.14)
qc2cas(qc)

Calculate calibrated airspeed from ASI (Air Speed indicator), differential pressure between impact pressure and static pressure. qc = pt - ps

References

• [1] Ward, D. T. (1993). Introduction to flight test engineering. Elsevier Science Ltd. (page 13, formula 2.13)
qc2eas(qc, p)

Calculate equivalent airspeed from ASI (Air Speed indicator), differential pressure between impact pressure and static pressure (qc = pt - ps) and p.

References

• [1] Ward, D. T. (1993). Introduction to flight test engineering. Elsevier Science Ltd.
qc2tas(qc, ρ, p)

Calculate true airspeed from ASI (Air Speed indicator), differential pressure between impact pressure and static pressure (qc = pt - ps), rho and p.

References

• [1] Ward, D. T. (1993). Introduction to flight test engineering. Elsevier Science Ltd. (page 12, based on formula 2.11)
cas2tas(cas, ρ, p)

Calculate true airspeed from calibrated airspeed, density (ρ) and pressure (p) at the current altitude.

tas2eas(tas, ρ)

Calculate equivalent airspeed from true airspeed and density at current altitude (ρ).

References

• [1] Ward, D. T. (1993). Introduction to flight test engineering. Elsevier Science Ltd. (page 13, formula 2.15)
tas_alpha_beta_from_uvw(u, v, w)

Calculate true air speed (TAS), angle of attack (α) and angle of side-slip (β) from aerodynamic velocity expressed in body axis.

References

• [1] Etkin, B. (2005). Dynamics of atmospheric flight. Dover Publications (page 114, formulas 4.3,2 and 4.3,3)

## Kinematics (kinematics.jl)

rigid_body_velocity(vel_P, ω, r_PQ)

Calculate the velocity of a point Q of a rigid solid given the velocity of a point P (vel_P), the rotational velocity of the solid (ω) and the relative position of Q wrt P.

If the reference frame 1 is attached to the solid and the velocity is calculated with respect to reference frame 0:

$v_{10}^{Q} = v_{10}^{P} + \omega_{10} \times r^{PQ}$

being:

• $v_{10}^{Q}$ the velocity of point Q, fixed to 1, wrt 0
• $\omega_{10}$ the angular velocity of the solid 1 wrt 0
• $r^{PQ}$ the position of Q wrt P ($r^{Q}-r^{P}$)

Every vector needs to be expressed in the same coordinate system.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (Section 1.3, page 26)

rigid_body_acceleration(acc_P, ω, ω_dot, r_PQ)

Calculate the acceleration of a point Q of a rigid solid given the acceleration of a point P (accP), the rotational velocity of the solid (ω), the rotational acceleration of the solid (ωdot) and the relative position of Q wrt P.

$a_{10}^{Q} = a_{10}^{P} + \omega_{10} \times (\omega_{10} \times r^{PQ}) + \dot{\omega}_{10} \times r^{PQ}$

being:

• $a_{10}^{Q}$ the acceleration of point Q, fixed to 1, wrt 0
• $\omega_{10}$ the angular velocity of the solid 1 wrt 0
• $\dot{\omega}_{10}$ the angular acceleration of the solid 1 wrt 0
• $r^{PQ}$ the position of Q wrt P ($r^{Q}-r^{P}$)

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (Section 1.3, Formaula 1.3-14c, page 26)

## 6 Degrees of Freedom dynamic models (dynamics/)

six_dof_euler_fixed_mass(state, mass, inertia, forces, moments)

Six degrees of freedom dynamic system using Euler angles for attitude representation and assuming fixed mass.

Flat Earth hypothesis is applied and Earth reference frame is considered inertial.

It is considered that the aircraft xb-zb plane is a plane of symmetry so that Jxy and Jyz cross-product of inertia are zero and will not be taken into account.

Arguments

• state::12-element Array{Number,1}: state vector. u, v, w: inertial linear velocity expressed in body axis. (m/s) p, q, r: inertial rotatinal velocity expressed in body axis. (rad/s) ψ, θ, ϕ: attitude given by Euler angles (zyx). Yaw, pitch, roll. (rad) xe, ye, ze: position wrt the inertial system origin expressed in Earth Axis. (m)
• mass::Number: total mass of the aircraft (kg)
• inertia::3×3 Array{Number,2}: inertia tensor (kg·m²)
• forces::3-element Array{Number,1}: total forces expressed in body axis. (N)
• moments::3-element Array{Number,1}: total moments expressed in body axis.(N·m)

Returns

• state_dot: state vector derivative according to the equation of motion, inertial properties and applied forces and moments.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (Section 1.5, equations 1.5-4, page 46)

• [2] Etkin, B. (2005). Dynamics of atmospheric flight. Dover Publications

(Section 5.8, page 148, formulas 5.8,1 to 5.8,7)

• [3] Zipfel, P. H. (2007). Modeling and simulation of aerospace vehicle

dynamics. American Institute of Aeronautics and Astronautics. (page 368, figure 10.2, not taking into account quaternions in angular kinematic equations)

six_dof_quaternion_fixed_mass(state, mass, inertia, forces, moments; k=0.0)

Six degrees of freedom dynamic system using quaternions for attitude representation and assuming fixed mass.

Flat Earth hypothesis is applied and Earth reference frame is considered inertial.

It is considered that the aircraft xb-zb plane is a plane of symmetry so that Jxy and Jyz cross-product of inertia are zero and will not be taken into account.

Arguments

• state::12-element Array{Number,1}: state vector. u, v, w: inertial linear velocity expressed in body axis. (m/s) p, q, r: inertial rotatinal velocity expressed in body axis. (rad/s) q0, q1, q2, q3: attitude given by quaternions. xe, ye, ze: position wrt the inertial system origin expressed in Earth Axis. (m)
• mass::Number: total mass of the aircraft (kg)
• inertia::3×3 Array{Number,2}: inertia tensor (kg·m²)
• forces::3-element Array{Number,1}: total forces expressed in body axis. (N)
• moments::3-element Array{Number,1}: total moments expressed in body axis.(N·m)
• k::Number: orthonormality error factor.

Returns

• state_dot: state vector derivative according to the equation of motion, inertial properties and applied forces and moments.

Notes

• See 1 or 2 for more information on quaternions <-> Euler angles conversions.
• Orthonormality error factor is related to a numerical stability artifact used in angular kinematic equations. Let λ = k * (1 - q0² - q1² - q2² - q3²) be the orthonormality error. The term k·λ·q is added to the angular kinematic equations in order to reduce the numerical integration error. According to reference [2] k·Δt ≤ 1. See 2 for more information on orthonormality error factor.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (Section 1.5, equations 1.5-4, page 46)

• [2] Zipfel, P. H. (2007). Modeling and simulation of aerospace vehicle

dynamics. American Institute of Aeronautics and Astronautics. (page 368, figure 10.2)

six_dof_ecef_quaternion_fixed_mass(state, mass, inertia, forces, moments;
k=0.0, ellipsoid=WGS84)

Six degrees of freedom dynamic system using quaternions for attitude representation and assuming fixed mass.

Ellipsoidal Earth Model is used and the ECEF reference frame is considered inertial.

It is considered that the aircraft xb-zb plane is a plane of symmetry so that Jxy and Jyz cross-product of inertia are zero and will not be taken into account.

Arguments

• state::12-element Array{Number,1}: state vector. u, v, w: inertial linear velocity expressed in body axis. (m/s) p, q, r: inertial rotatinal velocity expressed in body axis. (rad/s) q0, q1, q2, q3: attitude given by quaternions. xe, ye, ze: position wrt the inertial system origin expressed in Earth Axis. (m)
• mass::Number: total mass of the aircraft (kg)
• inertia::3×3 Array{Number,2}: inertia tensor (kg·m²)
• forces::3-element Array{Number,1}: total forces expressed in body axis. (N)
• moments::3-element Array{Number,1}: total moments expressed in body axis.(N·m)
• k::Number: orthonormality error factor.
• ellipsoid::Ellipsoid: ellipsoid model to be used.

Returns

• state_dot: state vector derivative according to the equation of motion, inertial properties and applied forces and moments.

Notes

• See 1 or 2 for more information on quaternions <-> Euler angles conversions.
• Orthonormality error factor is related to a numerical stability artifact used in angular kinematic equations. Let λ = k * (1 - q0² - q1² - q2² - q3²) be the orthonormality error. The term k·λ·q is added to the angular kinematic equations in order to reduce the numerical integration error. According to reference [2] k·Δt ≤ 1. See 2 for more information on orthonormality error factor.
• Implementation based on [1]. However, [2] can also be read.

References

• [1] Stevens, B. L., Lewis, F. L., (1992). Aircraft control and simulation:

dynamics, controls design, and autonomous systems. John Wiley & Sons. (page 45, formula 1.5-1)

• [2] Zipfel, P. H. (2007). Modeling and simulation of aerospace vehicle

dynamics. American Institute of Aeronautics and Astronautics. (page 396, figure 10.6)