【PyFME-Python Flight Mechanics Engine】python实现飞行控制仿真(一)——PyFME库安装和测试
程序员文章站
2022-08-06 08:57:51
一、PyFME安装【目前关于PyFME的介绍比较少,利用很长时间才摸索整理出来,如需转载请标注来源】因为PyFME不是标准的第三方库,无法使用pip直接安装(目前pip直接安装的是0.1版本的),可以直接去GitHub网站下载源代码进行安装和使用,源码网址:https://github.com/AeroPython/PyFME1、首先在pycharm中创建虚拟环境,创建过程参考https://blog.csdn.net/weixin_40493501/article/details...
一、PyFME安装
【目前关于PyFME的介绍比较少,利用很长时间才摸索整理出来,如需转载请标注来源】
【虚拟环境文件和测试代码下载地址:https://download.csdn.net/download/weixin_40493501/12668803】
因为PyFME不是标准的第三方库,无法使用pip直接安装(目前pip直接安装的是0.1版本的),可以直接去GitHub网站下载源代码进行安装和使用,源码网址:https://github.com/AeroPython/PyFME
1、首先在pycharm中创建虚拟环境,创建过程参考https://blog.csdn.net/weixin_40493501/article/details/107632104
2、在虚拟环境中单独安装下载后的PyFME压缩包
首先解压,在pycharm的terminal窗口下转至解压的文件夹下依次运行:
python setup.py build
python setup.py install
两条命令依次运行,不要同时运行,在运行第二条命令时等待时间会较长,因为虚拟环境中没有任何的第三方库,需要根据PyFME进行逐一配置
二、测试
# -*- coding: UTF-8 -*-
# 版本:
# 开发时间:2020/7/28 19:46
# 用户:
# Function:
import matplotlib.pyplot as plt
from pyfme.aircrafts import Cessna172
from pyfme.environment.atmosphere import ISA1976
from pyfme.environment.wind import NoWind
from pyfme.environment.gravity import VerticalConstant
from pyfme.environment.environment import Environment
from pyfme.utils.trimmer import steady_state_trim
from pyfme.models.state.position import EarthPosition
from pyfme.models import EulerFlatEarth
from pyfme.utils.input_generator import Constant
from pyfme.simulator import Simulation
aircraft = Cessna172()
print(f"Aircraft mass: {aircraft.mass} kg")
print(f"Aircraft inertia tensor: \n {aircraft.inertia} kg/m²")
print(f"forces: {aircraft.total_forces} N")
print(f"moments: {aircraft.total_moments} N·m")
atmosphere = ISA1976()
gravity = VerticalConstant()
wind = NoWind()
environment = Environment(atmosphere, gravity, wind)
pos = EarthPosition(x=0, y=0, height=1000)
psi = 0.5 # rad
TAS = 45 # m/s
controls0 = {'delta_elevator': 0, 'delta_aileron': 0, 'delta_rudder': 0, 'delta_t': 0.5}
trimmed_state, trimmed_controls = steady_state_trim(
aircraft,
environment,
pos,
psi,
TAS,
controls0
)
environment.update(trimmed_state)
forces, moments = aircraft.calculate_forces_and_moments(trimmed_state, environment, controls0)
system = EulerFlatEarth(t0=0, full_state=trimmed_state)
controls = controls = {
'delta_elevator': Constant(trimmed_controls['delta_elevator']),
'delta_aileron': Constant(trimmed_controls['delta_aileron']),
'delta_rudder': Constant(trimmed_controls['delta_rudder']),
'delta_t': Constant(trimmed_controls['delta_t'])
}
sim = Simulation(aircraft, system, environment, controls)
results = sim.propagate(15)
kwargs = {'marker': '.',
'subplots': True,
'sharex': True,
'figsize': (12, 6)}
results.plot(y=['x_earth', 'y_earth', 'height'], **kwargs);
results.plot(y=['psi', 'theta', 'phi'], **kwargs);
results.plot(y=['v_north', 'v_east', 'v_down'], **kwargs);
results.plot(y=['p', 'q', 'r'], **kwargs);
results.plot(y=['alpha', 'beta', 'TAS'], **kwargs);
results.plot(y=['Fx', 'Fy', 'Fz'], **kwargs);
results.plot(y=['Mx', 'My', 'Mz'], **kwargs);
results.plot(y=['elevator', 'aileron', 'rudder', 'thrust'], **kwargs);
plt.show()
本文地址:https://blog.csdn.net/weixin_40493501/article/details/107643264
上一篇: asp之日期和时间函数示例
下一篇: 揭秘百度人脸识别搜索 人脸检测以图搜图