[原][osgEarth][JSBSim]重新整理使用JSBSim飞机动力模拟的使用

本文详细介绍如何利用JSBSim进行飞行模拟,包括通过修改FGInput和FGOutput类实现与外部程序的UDP/TCP通信,进而发送控制指令及接收飞机状态数据的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JSBSim是一个模拟飞机飞行空气动力学的,这些都不用深入理解,只要知道自己程序怎么和JSBSim交互就行了

我使用的是JSBSim-Win32-0.9.13

原理:改写jsbsim的FGInput 和FGOutput两个类

使其能通过udp或者tcp与自己的程序进程通信,以实现自己程序通过网络端,发送控制命令并获取飞机姿态的目的。

 

udp通信的例子:简单的udp通信

进阶版udp和tcp通信的例子:基于winsocket2的TCP\UDP使用例子

 

JSBSim的简单介绍(转):飞行模拟软件JSBSim的操作(FGFCS类)

JSBSim的使用--飞行控制组件及其配置

 

实现的本端发送tcp飞机控制端 和 获取udp飞机姿态的部分:TCP|UDP与飞行模拟软件JSBSim的通信,现实模型飞行!

 

实现JSBSim端部分:

FGInput部分

 输入参数:

fcs/aileron-cmd-norm normalized aileron command    规范化副翼命令    使飞机做横滚机动
fcs/elevator-cmd-norm normalized elevator command   规范化升降舵命令
fcs/rudder-cmd-norm       方向舵
fcs/steer-cmd-norm        驾驶
fcs/flap-cmd-norm        襟翼  基本效用是在飞行中增加升力,便于起飞降落
fcs/speedbrake-cmd-norm      减速板,又称阻力板,飞机上用于增加阻力以减低飞行速度的可操纵面
fcs/spoiler-cmd-norm        扰流器,通过上下摆动来调节飞机的飞行时速
fcs/pitch-trim-cmd-norm    俯仰配平
fcs/roll-trim-cmd-norm    旋转配平
fcs/yaw-trim-cmd-norm    偏航配平
gear/gear-cmd-norm      齿轮、传动装置
fcs/left-aileron-pos-rad    副翼
fcs/left-aileron-pos-deg
fcs/left-aileron-pos-norm
fcs/mag-left-aileron-pos-rad
fcs/right-aileron-pos-rad
fcs/right-aileron-pos-deg
fcs/right-aileron-pos-norm
fcs/mag-right-aileron-pos-rad
fcs/elevator-pos-rad    升降舵
fcs/elevator-pos-deg
fcs/elevator-pos-norm
fcs/mag-elevator-pos-rad
fcs/rudder-pos-rad    方向舵
fcs/rudder-pos-deg
fcs/rudder-pos-norm
fcs/mag-rudder-pos-rad
fcs/flap-pos-rad    襟翼
fcs/flap-pos-deg
fcs/flap-pos-norm
fcs/speedbrake-pos-rad    减速板
fcs/speedbrake-pos-deg
fcs/speedbrake-pos-norm
fcs/mag-speedbrake-pos-rad
fcs/spoiler-pos-rad      扰流板
fcs/spoiler-pos-deg
fcs/spoiler-pos-norm
fcs/mag-spoiler-pos-rad
fcs/wing-fold-pos-norm    机翼折叠
gear/gear-pos-norm
gear/tailhook-pos-norm    制动钩

另加:
fcs/left-brake-cmd-norm  刹车
fcs/right-brake-cmd-norm
fcs/center-brake-cmd-norm
propulsion/starter_cmd    推进
fcs/throttle-cmd-norm[0]    油门推杆

 

FGOutput部分

输出:

position/long-gc-deg    经度
position/lat-gc-deg    纬度
position/h-sl-ft    高度

attitude/roll-rad    
attitude/pitch-rad
attitude/heading-true-rad

velocities/vc-kts    空速(节|海里/小时)
velocities/h-dot-fps    爬升率(英尺/秒)
velocities/v-north-fps    北向速度(英尺/秒)
velocities/v-east-fps    东向速度(英尺/秒)
velocities/v-down-fps    降速(英尺/秒)

fcs/throttle-pos-norm
fcs/elevator-pos-deg
fcs/left-aileron-pos-deg
fcs/right-aileron-pos-deg
fcs/rudder-pos-deg

inertia/weight-lbs
inertia/empty-weight-lbs
propulsion/total-fuel-lbs

forces/fbx-prop-lbs
forces/fby-prop-lbs
forces/fbz-prop-lbs

velocities/x-fps
velocities/y-fps
velocities/z-fps

accelerations/xdot-ft_sec2
accelerations/ydot-ft_sec2
accelerations/zdot-ft_sec2

fcs/left-gear-pos-deg
fcs/right-gear-pos-deg
fcs/head-gear-pos-deg
fcs/left-flap-pos-deg
fcs/right-flap-pos-deg
fcs/left-elevator-deg
fcs/right-elevator-deg
fcs/left-rudder-deg
fcs/right-rudder-deg

 

本端多线程部分(发送和接受数据都是另开线程)

 

本端开启关闭JSBSim进程部分:

 

 

本端使用摇杆部分:

 摇杆基础:摇杆开发

 

03-29
### AirSim 使用指南与安装教程 #### 1. AirSim 简介 AirSim 是由微软开发的一个开源跨平台飞行模拟器,支持无人机和其他车辆的高精度物理仿真。它基于 Unreal Engine 和 Unity 开发环境运行,并提供了丰富的 API 接口用于研究和测试自动驾驶技术。 --- #### 2. Windows 平台下的 AirSim 安装教程 ##### **环境准备** - 需要安装 Unity Hub 和指定版本的 Unity 编辑器(例如 Unity 2019.3.12)。可以通过 Unity 官方网站的历史版本页面下载所需版本[^2]。 - 如果计划使用 Unreal Engine 版本,则需要先安装 Epic Games Launcher 并获取对应版本的引擎。 ##### **AirSim 的克隆与配置** 1. 打开命令行工具并执行以下 Git 命令来克隆 AirSim 存储库: ```bash git clone https://github.com/microsoft/AirSim.git cd AirSim ``` 2. 根据所选的游戏引擎(Unreal 或 Unity),进入对应的子目录完成构建过程。对于 Unity 用户,可以跳过编译步骤直接集成到项目中。 3. 构建完成后,在 `settings.json` 文件中定义场景参数以及传感器设置等内容[^4]。 --- #### 3. QGroundControl 与 PX4 SITL 整合说明 为了实现更复杂的实验需求,通常会将 AirSim 结合 PX4 Flight Stack 进行 Software-in-the-loop (SITL) 测试。此方法允许开发者通过 MAVLink 协议连接虚拟控单元至地面站软件如 QGroundControl[^3]。 具体操作如下: - 启动 PX4 SITL 实例; - 设置网络端口号以便于两者间通信; - 加载自定义任务逻辑并通过调试接口验证行为表现是否符合预期。 --- #### 4. 示例代码片段:启动简单 Python 控制脚本 下面展示如何利用 AirSim 提供的 Python SDK 来操控模型移动位置: ```python import airsim client = airsim.MultirotorClient() client.confirmConnection() # Takeoff and hover at a certain altitude. print("Taking off...") client.enableApiControl(True) client.armDisarm(True) takeoff_future = client.takeoffAsync(timeout_sec=5).join() move_future = client.moveToZAsync(-7, velocity=5).join() # Move up by 7 meters. print("Hovering after reaching target height.") time.sleep(5) landing_future = client.landAsync().join() client.armDisarm(False) client.reset() ``` 上述程序实现了基本起、悬停及降落功能演示。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值