Skip to content

UAV — Longitudinal Dynamics

An unmanned aerial vehicle (UAV) is a remotely piloted or autonomous aircraft. This page mirrors the ELV layout: quick start, math model, derivatives, and API.

  • Quick start

    Launch the environment or the model within minutes.

    See example

  • Model API

    Python class documentation for the UAV longitudinal dynamics.

    Go to API

  • Gymnasium environment

    Ready environment for RL agents.

    Explore

  • Theory

    State equations and numerical parameters.

    Learn more

Control object structure

The model is defined in the state space:

\[\dot{x} = A x + B u, \quad y = C x + D u\]

where:

\[ x = \begin{bmatrix} u & w & q & \theta \end{bmatrix}^{\top}, \quad u_{in} = \eta \]

The typical matrix structure is:

\[ \begin{bmatrix} \dot{u} \\ \dot{w} \\ \dot{q} \\ \dot{\theta} \end{bmatrix} = \begin{bmatrix} x_u & x_w & x_q & x_{\theta} \\ z_u & z_w & z_q & z_{\theta} \\ m_u & m_w & m_q & m_{\theta} \\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} u \\ w \\ q \\ \theta \end{bmatrix} + \begin{bmatrix} x_{\eta} \\ z_{\eta} \\ m_{\eta} \\ 0 \end{bmatrix} \eta \]
  • u: longitudinal speed, m/s
  • w: vertical speed, m/s
  • q: pitch rate, rad/s
  • θ: pitch angle, rad
  • η: stabilizer control deflection, rad
  • x_u, x_w, x_q, x_θ — partial derivatives of longitudinal force \(X\) with respect to \(u, w, q, \theta\)
  • z_u, z_w, z_q, z_θ — partial derivatives of normal force \(Z\)
  • m_u, m_w, m_q, m_θ — partial derivatives of pitch moment \(M\)
  • x_η, z_η, m_η — derivatives with respect to the control \(\eta\)

Units

Angles and angular rates are in radians. API methods can produce values in degrees.

Mathematical model

\[ \dot{x} = A x + B u, \qquad y = C x + D u \]

Numerical matrices (example linearization):

\[ \begin{bmatrix} \dot{u} \\ \dot{w} \\ \dot{q} \\ \dot{\theta} \end{bmatrix} = \begin{bmatrix} -0.1982 & 0.593 & 1.245 & -9.779 \\ -0.7239 & -3.9848 & 18.7028 & -0.6286 \\ 0.3537 & -5.5023 & -5.4722 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} u \\ w \\ q \\ \theta \end{bmatrix} + \begin{bmatrix} 0.2281 \\ -4.6830 \\ -36.1341 \\ 0.0 \end{bmatrix} \eta \]

Derivatives (numerical values)

  • Matrix A (derivatives):
Coefficient Value
x_u -0.1982
x_w 0.593
x_q 1.245
x_θ -9.779
z_u -0.7239
z_w -3.9848
z_q 18.7028
z_θ -0.6286
m_u 0.3537
m_w -5.5023
m_q -5.4722
m_θ 0.0
  • Input η (column B):
Coefficient Value
x_η 0.2281
z_η -4.6830
m_η -36.1341

Sources

  1. A. Rauf, Muhammad Aamir Zafar, Z. Ashraf and H. Akhtar, "Aerodynamic modeling and state-space model extraction of a UAV using DATCOM and Simulink," 2011 3rd International Conference on Computer Research and Development, Shanghai, China, 2011, pp. 88-92, doi: 10.1109/ICCRD.2011.5763860.

Reward

The default reward function returns the negative absolute tracking error for the pitch angle:

\[r_t = -|\theta(t) - \theta_{\text{ref}}(t)|\]

Higher reward (closer to 0) indicates better tracking performance. A custom reward function can be passed via the reward_func parameter.

Quick start

import gymnasium as gym 
import numpy as np

from tensoraerospace.envs import LinearLongitudinalUAV
from tensoraerospace.utils import generate_time_period
from tensoraerospace.signals.standard import unit_step

dt = 0.01
tp = generate_time_period(tn=20, dt=dt)
number_time_steps = len(tp)
reference_signals = unit_step(degree=5, tp=tp, time_step=10, output_rad=True).reshape(1, -1)

env = gym.make(
    'LinearLongitudinalUAV-v0',
    number_time_steps=number_time_steps, 
    initial_state=[[0],[0],[0],[0]],
    reference_signal=reference_signals,
)
state, info = env.reset()
for _ in range(200):
    action = np.array([[0.1]])
    state, reward, terminated, truncated, info = env.step(action)
    if terminated or truncated:
        break
import numpy as np
from tensoraerospace.aerospacemodel import LongitudinalUAV

dt = 0.01
number_time_steps = 200

x0 = np.array([0.0, 0.0, 0.0, 0.0])

model = LongitudinalUAV(
    x0=x0,
    number_time_steps=number_time_steps,
    selected_state_output=["u", "w", "q", "theta"],
    dt=dt,
)

for t in range(number_time_steps - 1):
    u = np.array([[0.05]])
    x_next = model.run_step(u)

Python API

LongitudinalUAV(x0, number_time_steps, selected_state_output=None, t0=0, dt=0.01)

Bases: ModelBase

UAV model in longitudinal control channel.

Parameters:

Name Type Description Default
x0 ndarray | list[float]

Initial state of the control object.

required
number_time_steps int

Number of time steps.

required
selected_state_output optional

Selected states of the control object. Defaults to None.

None
t0 int

Initial time. Defaults to 0.

0
dt float

Discretization frequency. Defaults to 0.01.

0.01
Action space

ele: elevator [deg]

State space

u: Longitudinal aircraft velocity [m/s] w: Normal aircraft velocity [m/s] q: Pitch angular velocity [deg/s] theta: Pitch [deg]

Output space

u: Longitudinal aircraft velocity [m/s] w: Normal aircraft velocity [m/s] q: Pitch angular velocity [deg/s] theta: Pitch [deg]

Initialize LongitudinalUAV instance.

Parameters:

Name Type Description Default
x0 ndarray | list[float]

Initial state of the control object.

required
number_time_steps int

Number of time steps.

required
selected_state_output list[str] | None

Selected states of the control object. Defaults to None.

None
t0 float

Initial time. Defaults to 0.

0
dt float

Discretization frequency. Defaults to 0.01.

0.01

import_linear_system()

Load (set) stored linearized system matrices.

initialise_system(x0, number_time_steps)

Initialize the system and allocate history buffers.

Parameters:

Name Type Description Default
x0 ndarray | list[float]

Initial state.

required
number_time_steps int

Number of simulation steps.

required

run_step(ut_0)

Run one discrete-time simulation step.

Parameters:

Name Type Description Default
ut_0 ndarray

Control vector.

required

Returns:

Type Description
ndarray

np.ndarray: Next state at time t+1.

update_system_attributes()

Update time-dependent attributes after each simulation step.

get_state(state_name, to_deg=False, to_rad=False)

Return the time history of a state.

Parameters:

Name Type Description Default
state_name str

State name.

required
to_deg bool

Convert radians to degrees.

False
to_rad bool

Convert degrees to radians.

False

Returns:

Type Description
ndarray

np.ndarray: State history array.

get_control(control_name, to_deg=False, to_rad=False)

Return the time history of a control input.

Parameters:

Name Type Description Default
control_name str

Control signal name.

required
to_deg bool

Convert radians to degrees.

False
to_rad bool

Convert degrees to radians.

False

Returns:

Type Description
ndarray

np.ndarray: Control history array.

get_output(state_name, to_deg=False, to_rad=False)

Return the time history of an output signal.

Parameters:

Name Type Description Default
state_name str

Output name.

required
to_deg bool

Convert radians to degrees.

False
to_rad bool

Convert degrees to radians.

False

Returns:

Type Description
ndarray

np.ndarray: Output history array.

plot_output(output_name, time, lang='rus', to_deg=False, to_rad=False, figsize=(10, 10))

Plot an output signal over time.

Parameters:

Name Type Description Default
output_name str

Output name.

required
time ndarray

Time vector.

required
lang str

Axis label language ('rus' or 'eng').

'rus'
to_deg bool

Convert radians to degrees.

False
to_rad bool

Convert degrees to radians.

False
figsize tuple

Figure size.

(10, 10)

Returns:

Type Description
Figure

matplotlib.figure.Figure: Figure object.

LinearLongitudinalUAV(initial_state, reference_signal, number_time_steps, tracking_states=None, state_space=None, control_space=None, output_space=None, reward_func=None)

Bases: Env

Simulation of LongitudinalUAV control object in OpenAI Gym environment for training AI agents.

Parameters:

Name Type Description Default
initial_state ndarray | list[float]

Initial state.

required
reference_signal ndarray | Callable

Reference signal.

required
number_time_steps int

Number of simulation steps.

required
tracking_states list[str] | None

Tracked states.

None
state_space list[str] | None

State space.

None
control_space list[str] | None

Control space.

None
output_space list[str] | None

Full output space (including noise).

None
reward_func Callable | None

Reward function (WIP status).

None

Initialize UAV longitudinal environment.

reward(state, ref_signal, ts) staticmethod

Evaluate control performance.

Parameters:

Name Type Description Default
state ndarray

Current state.

required
ref_signal ndarray

Reference signal.

required
ts int

Time step.

required

Returns:

Name Type Description
float float

Control evaluation reward.

step(action)

Execute one simulation step.

Parameters:

Name Type Description Default
action ndarray

Control signal array for selected actuators.

required

Returns:

Name Type Description
tuple tuple[ndarray, float, bool, bool, dict[str, float]]

Tuple containing: - next_state (np.ndarray): Next state of the control object. - reward (np.ndarray): Evaluation of control algorithm actions. - done (bool): Simulation status, whether completed or not. - truncated (bool): Whether episode was truncated. - info (dict): Additional information.

reset(seed=None, options=None)

Reset simulation environment to initial conditions.

Parameters:

Name Type Description Default
seed int

Random seed. Defaults to None.

None
options dict

Additional initialization options. Defaults to None.

None

Returns:

Name Type Description
tuple tuple[ndarray, dict[str, float]]

Tuple containing: - observation (np.ndarray): Initial observation. - info (dict): Additional information.

render()

Visual rendering of actions in the environment. Work in progress.

Raises:

Type Description
NotImplementedError

Rendering is not yet implemented.