Skip to main content

A UAV FDM model for sim

Project description

uav_fdm 无人机动力学模型

概述

本项目将matlab代码生成的三自由度飞行动力学模型C++类通过SWIG进行包装,并通过pip发布。

编译安装

本地编译

python setup.py build_ext --inplace

安装编译

python setup.py install --user

pip安装

pip install uav-fdm

接口说明

模块名称为uav_fdm; 其中的类名称为uav_fdm

初始化

类的初始化函数为uav_fdm.uav_fdm(x0, y0, alt0, gs0, gamma0, psi0, phi0)

参数 说明 单位
x0 初始x m
y0 初始y m
alt0 初始高度 m
gs0 初始地速 m/s
gamma0 初始航迹倾角 rad
psi0 初始真航向 rad
phi0 初始滚转角 rad

仿真步进

类的仿真步进函数为[t, x, y, alt, v_n, v_e, hdot, phi, psi_t, gamma, gs, tas] = uav1.update(dt, tas_c, hdot_c, psi_c, w_n, w_e)

输入参数 说明 单位
dt 步进时间(为0.05s整倍数) s
tas_c 真空速指令 m/s
hdot_c 升降速率指令 m/s
psi_c 航向角指令 rad
w_n 北风速度 m/s
w_e 东风速度 m/s
输出变量 说明 单位
t 时间 s
x x m
y y m
alt 高度 m
v_n 北向速度 m/s
v_e 东向速度 m/s
hdot 天向速度 m/s
phi 滚转角 rad
psi_t 真航向角(-pi~pi) rad
gamma 航迹倾角 rad
gs 地速 m/s
tas 真空速 m/s

指令限制

  • 飞行真空速指令限制14~24m/s
  • 升级速率指令限制-3~3m/s
  • 偏航角指令限制-pi~pi rad

使用示例

import uav_fdm

if __name__ == '__main__':
    x0 = 23  # 初始x(m)
    y0 = 110  # 初始y(m)
    alt0 = 130  # 初始高度(m)
    gs0 = 22  # 初始地速(m/s)
    gamma0 = 0  # 初始航迹倾角(rad)
    psi0 = 3.14  # 初始真航向(rad)
    phi0 = 0  # 初始滚转角(rad)

    # 初始化uav1
    uav1 = uav_fdm.uav_fdm(x0, y0, alt0, gs0, gamma0, psi0, phi0)

    # 进行5秒平飞仿真
    tas_c = 22  # 真空速指令(m/s)
    hdot_c = 0  # 升降速率指令(m/s)
    psi_c = 3.14  # 航向角指令(rad)
    w_n = 0  # 北风速度(m/s)
    w_e = 0  # 东风速度(m/s)
    t = 0
    dt = 1  # 按1秒推进
    while t < 5:
        [t, x, y, alt, v_n, v_e, hdot, phi, psi_t, gamma, gs, tas] = uav1.update(
            dt, tas_c, hdot_c, psi_c, w_n, w_e)
        print(f'{t:.0f} {x:.0f} {y:.0f} {alt:.2f} {gs:.2f} {psi_t*57.3:.2f} {phi*57.3:.2f}')

    # 进行15秒转弯仿真
    tas_c = 22  # 真空速指令(m/s)
    hdot_c = 0  # 升降速率指令(m/s)
    psi_c = 1.57082  # 航向角指令(rad)
    w_n = 0  # 北风速度(m/s)
    w_e = 0  # 东风速度(m/s)
    t = 0
    dt = 1  # 按1秒推进
    while t < 20:
        [t, x, y, alt, v_n, v_e, hdot, phi, psi_t, gamma, gs, tas] = uav1.update(
            dt, tas_c, hdot_c, psi_c, w_n, w_e)
        print(f'{t:.0f} {x:.0f} {y:.0f} {alt:.2f} {gs:.2f} {psi_t*57.3:.2f} {phi*57.3:.2f}')

    # 进行5秒爬升仿真
    tas_c = 22  # 真空速指令(m/s)
    hdot_c = 1  # 升降速率指令(m/s)
    psi_c = 1.57082  # 航向角指令(rad)
    w_n = 0  # 北风速度(m/s)
    w_e = 0  # 东风速度(m/s)
    t = 0
    dt = 1  # 按1秒推进
    while t < 25:
        [t, x, y, alt, v_n, v_e, hdot, phi, psi_t, gamma, gs, tas] = uav1.update(
            dt, tas_c, hdot_c, psi_c, w_n, w_e)
        print(f'{t:.0f} {x:.0f} {y:.0f} {alt:.2f} {gs:.2f} {psi_t*57.3:.2f} {phi*57.3:.2f}')

    # 进行5秒加速仿真
    tas_c = 24  # 真空速指令(m/s)
    hdot_c = 0  # 升降速率指令(m/s)
    psi_c = 1.57082  # 航向角指令(rad)
    w_n = 0  # 北风速度(m/s)
    w_e = 0  # 东风速度(m/s)
    t = 0
    dt = 1  # 按1秒推进
    while t < 30:
        [t, x, y, alt, v_n, v_e, hdot, phi, psi_t, gamma, gs, tas] = uav1.update(
            dt, tas_c, hdot_c, psi_c, w_n, w_e)
        print(f'{t:.0f} {x:.0f} {y:.0f} {alt:.2f} {gs:.2f} {psi_t*57.3:.2f} {phi*57.3:.2f}')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uav-fdm-0.2.1.tar.gz (63.2 kB view details)

Uploaded Source

File details

Details for the file uav-fdm-0.2.1.tar.gz.

File metadata

  • Download URL: uav-fdm-0.2.1.tar.gz
  • Upload date:
  • Size: 63.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for uav-fdm-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bd36c17ed73d67b64f65dd336c913ab9f43e2ab02ecd039f09c0c6b6fb1c661a
MD5 efbbbf5c9cf7e0ead1fcb81a3313c354
BLAKE2b-256 0b2b381853e49de6b7c6d438a0698391a234f6714dc0bff0f4f0d3517cf2c564

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page