БПЛА (UAV) — продольная динамика¶
Беспилотный летательный аппарат (UAV) — дистанционно управляемое или автономное воздушное судно. Страница оформлена по аналогии с ELV: быстрый старт, математика, производные и API.
Как устроен объект управления¶
Модель задана в пространстве состояний:
Где:
Типовая структура матриц:
- u: продольная скорость, м/с
- w: нормальная скорость, м/с
- q: угловая скорость тангажа, рад/с
- θ: тангаж, рад
- η: управляющее отклонение стабилизатора, рад
- x_u, x_w, x_q, x_θ — частные производные продольной силы \(X\) по \(u, w, q, \theta\)
- z_u, z_w, z_q, z_θ — частные производные нормальной силы \(Z\)
- m_u, m_w, m_q, m_θ — частные производные момента тангажа \(M\)
- x_η, z_η, m_η — производные по управляющему \(\eta\)
О единицах измерения
Углы и угловые скорости — в радианах. Методы API поддерживают выдачу в градусах.
Математическая модель¶
Численные матрицы (пример линеаризации):
Производные (численные значения)¶
- Матрица A (производные):
| Коэффициент | Значение |
|---|---|
| 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 |
- Вход η (столбец B):
| Коэффициент | Значение |
|---|---|
| x_η | 0.2281 |
| z_η | -4.6830 |
| m_η | -36.1341 |
Источники¶
- 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.
Награда¶
Функция награды по умолчанию возвращает отрицательную абсолютную ошибку отслеживания угла тангажа:
Чем выше награда (ближе к 0), тем лучше качество отслеживания. Пользовательская функция награды может быть передана через параметр reward_func.
Быстрый старт¶
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. |