虚拟无人机仿真平台AirSim基于Win10部署与简单例程运行

虚拟无人机仿真平台AirSim基于Win10部署与简单例程运行

AirSim是一款基于虚幻引擎的虚拟无人机仿真平台,本篇博客主要介绍如何在win10下部署该平台,同时如何实现一个简单的例程。本篇博客对官方教程以及文档进行汉化加之自己的理解,也罗列出一些遇到的问题与解决方法,希望有帮助。

英文官方教程:https://microsoft.github.io/AirSim/unreal_blocks/

https://microsoft.github.io/AirSim/build_windows/

1.虚幻引擎(UE4)的部署

installer下载链接:https://www.unrealengine.com/zh-CN/download

下载完成登陆后,点击install安装,AirSim当前要求4.25以上版本,总之以安装最新版本为佳。

Unreal Engine Tab UI Screenshot

2.编译AirSim

(1)VS

我们需要用到VS2019以上的版本来开发AirSim。VS2019用社区版的就可以,免费使用的。

打开Visual Studio Installer,点击修改生成工具

image-20210823211023241

确保Desktop Development with C++Windows 10 SDK 10.0.18362被安装且是默认使用的。其中Win10 SDK极为重要,再三确认版本无误,否则编译会出错。

image-20210823211448469

image-20210823211539869

(2)下载源码

源码地址:https://github.com/microsoft/AirSim

官网下载也好,git clone(git clone https://github.com/Microsoft/AirSim.git)也好,下载源码。

官方不推荐下载到C盘,我试了没多大影响,但是在后面一步需要以管理员身份打开。

(3)编译

以管理员身份打开Developer Command Prompt for VS 2019,cd到你刚刚下载的文件夹下(即cd …/AirSim)。

输入:build.cmd。编译时间还蛮久的,编译成功能够打开Unreal\Plugins。

image-20210823212715206

3.生成VS工程 完成编译

在这一步之前,先打开Epic Game Launcher,登陆后会让你关联.uproject后缀,选择关联。(否则会出现“projectfiles不是内部命令”的报错)

然后打开Visual Studio Installer,点击修改VS2019,安装.Net Framework 4.x SDK(老样子我安装了最新的)(否则会出现“.NET Framework SDK at 4.6.0 or higher”的报错)

image-20210823214120434

然后打开AirSim\Unreal\Environments\Blocks,运行update_from_git.bat批处理文件,会生成Block.sln。

image-20210823214605175

点击打开Block.sln,进入VS。F5。

4.操作指南

进入虚幻编辑器界面,点击运行,弹窗选择“是”进入汽车模式,“否”进入无人机模式。

image-20210823215132035

按键指南如下:

image-20210823215241628

注意这里的roll、pitch、yaw啥的和无人机没有关系,实际上它并不支持键盘操作虚拟无人机。按M进入第三人称手动控制摄像角度,按F进入第一人称FPV摄像角度,按B进入默认第三人称跟随角度。数字1、2、3、0控制副窗。

5.简单例程运行

用Pycharm打开AirSim\PythonClient,安装requirements.txt。

首先在虚幻编辑器中运行,然后运行orbit.py,这是一个起飞无人机绕圈的例程。

https://microsoft.github.io/AirSim/orbit/

image-20210823220118312

image-20210823220205757
按T可以看到飞机的行驶轨迹。

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个基于 Windows 平台的蓝牙虚拟串口的 C 语言例程: ```c #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <bluetoothapis.h> int main(int argc, char *argv[]) { HANDLE hComm; DCB dcb; COMMTIMEOUTS timeouts; DWORD bytesWritten, bytesRead; char buffer[1024]; // 初始化蓝牙 API if (BluetoothSetMode(NULL, BLUETOOTH_MODE_CONNECTABLE) != ERROR_SUCCESS) { printf("Failed to initialize Bluetooth API.\n"); return 1; } // 搜索蓝牙设备 BLUETOOTH_DEVICE_SEARCH_PARAMS searchParams = { sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS), 1, 0, 0, 0, 0, 5, NULL }; BLUETOOTH_DEVICE_INFO deviceInfo = { sizeof(BLUETOOTH_DEVICE_INFO), 0 }; HBLUETOOTH_DEVICE_FIND hDeviceFind = BluetoothFindFirstDevice(&searchParams, &deviceInfo); if (hDeviceFind == NULL) { printf("No Bluetooth devices found.\n"); return 1; } // 连接蓝牙设备 BLUETOOTH_DEVICE_INFO device = { sizeof(BLUETOOTH_DEVICE_INFO), 0 }; if (BluetoothGetDeviceInfo(deviceInfo.Address, &device) != ERROR_SUCCESS) { printf("Failed to get device information.\n"); return 1; } BLUETOOTH_SPP_CONNECT_PARAMS sppParams = { sizeof(BLUETOOTH_SPP_CONNECT_PARAMS), deviceInfo.Address, BLUETOOTH_DEFAULT_PORT }; HBLUETOOTH_SPP_CONNECTION hSpp = BluetoothSppConnect(NULL, &sppParams); if (hSpp == NULL) { printf("Failed to connect to SPP service.\n"); return 1; } // 打开虚拟串口 hComm = CreateFile("\\\\.\\COM31", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hComm == INVALID_HANDLE_VALUE) { printf("Failed to open virtual serial port.\n"); return 1; } // 配置串口参数 dcb.DCBlength = sizeof(dcb); if (!GetCommState(hComm, &dcb)) { printf("Failed to get serial port state.\n"); return 1; } dcb.BaudRate = CBR_9600; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; if (!SetCommState(hComm, &dcb)) { printf("Failed to set serial port state.\n"); return 1; } // 配置串口超时 timeouts.ReadIntervalTimeout = 50; timeouts.ReadTotalTimeoutMultiplier = 10; timeouts.ReadTotalTimeoutConstant = 100; timeouts.WriteTotalTimeoutMultiplier = 10; timeouts.WriteTotalTimeoutConstant = 100; if (!SetCommTimeouts(hComm, &timeouts)) { printf("Failed to set serial port timeouts.\n"); return 1; } // 读写数据 while (1) { // 从蓝牙设备读取数据 if (BluetoothSppReceive(hSpp, buffer, sizeof(buffer), &bytesRead) == ERROR_SUCCESS) { // 写入虚拟串口 if (!WriteFile(hComm, buffer, bytesRead, &bytesWritten, NULL)) { printf("Failed to write data to serial port.\n"); return 1; } } // 从虚拟串口读取数据 if (ReadFile(hComm, buffer, sizeof(buffer), &bytesRead, NULL)) { // 发送给蓝牙设备 if (BluetoothSppSend(hSpp, buffer, bytesRead, &bytesWritten) != ERROR_SUCCESS) { printf("Failed to send data to Bluetooth device.\n"); return 1; } } } // 关闭所有句柄 CloseHandle(hComm); BluetoothSppDisconnect(hSpp); BluetoothFindDeviceClose(hDeviceFind); return 0; } ``` 该程序首先初始化 Bluetooth API,然后搜索并连接到蓝牙设备,并打开一个虚拟串口(例如 COM31)。程序配置了串口参数和超时,并在一个循环中不断地从蓝牙设备读取数据并写入虚拟串口,以及从虚拟串口读取数据并发送给蓝牙设备。程序在结束时关闭所有句柄。注意,这只是一个简单例程,实际应用中可能需要更加健壮的错误处理和线程控制。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值