Skip to main content

Initial Configuration and Python API Call of AirSim

· 3 min read
Muel - Nova
Anime Would PWN This WORLD into 2D
🤖AI Summary

nova在这篇文章中详细介绍了如何在Windows系统上配置和使用AirSim,以帮助读者实现模拟无人机控制。

首先,作者描述了如何安装Unreal Engine 4,要点包括下载Epic Games Launcher并选择合适的引擎版本。接着,作者说明了编译AirSim所需的准备工作,包括安装Visual Studio 2019以及必要的组件和SDK。

在创建Unreal项目部分,nova提供了详细的步骤,告诉读者如何通过Epic Games Launcher创建一个自定义的Unreal环境,并配置相应的项目文件以支持AirSim插件。

最后,作者简要介绍了如何使用Python API来控制无人机,强调了使用Conda和Python 3.8的环境配置,并提供了一个基本的例子展示了如何通过代码实现无人机的简单控制。

(Since the logo could not be found, I stole a banner_img())

Install Unreal Engine 4

  1. Download Epic Games Launcher.
  2. Run Epic Games Launcher and download a version of Unreal Engine 4 >= 4.25.

Compile AirSim

Preparation

Install Visual Studio 2019, and make sure to include Desktop Development with C++ and Windows 10 SDK >= 10.0.18362 (usually selected by default).

Start Compilation

  1. Clone AirSim to your local machine by using git clone https://github.com/microsoft/AirSim.git.
  2. Use Developer Command Prompt for VS 2019 to navigate to the AirSim directory and run build.cmd.

Create Unreal Project

Microsoft Official Tutorial and Explanation

While AirSim comes with the "Blocks Environment" that can be used, we will opt to create our own Unreal Environment.

  • In Epic Games Launcher, go to "Learn" and download "Landscape Mountains" (or any other environment of your choice).

  • Click on File, create a new C++ Class with the default name.

  • Copy %PATH%/AirSim/Unreal/Plugins to your project directory.

    If you cannot locate the Plugins, run update_to_git.bat in the %PATH%/AirSim/Unreal/Environments\Blocks directory using Developer Command Prompt for VS 2019.

  • Edit %Projects%.uproject, add AdditionalDependencies and Plugins, so your file should look like this:

    {
    "FileVersion": 3,
    "EngineAssociation": "4.27",
    "Category": "Samples",
    "Description": "",
    "Modules": [
    {
    "Name": "LandscapeMountains",
    "Type": "Runtime",
    "LoadingPhase": "Default",
    "AdditionalDependencies": [
    "AirSim"
    ]
    }
    ],
    "TargetPlatforms": [
    "MacNoEditor",
    "WindowsNoEditor"
    ],
    "Plugins": [
    {
    "Name": "AirSim",
    "Enabled": true
    }
    ]
    }
  • Right-click on the %Project%.uproject file and select Generate Visual Studio Project Files.

  • Open %Project%.sln file using VS, choose "DebugGame Editor" and "Win64" as build configurations, and run the project.

  • You should now be able to use AirSim in your own Unreal environment; remember to save your settings!

Run Python API

In this section, I am using Conda + Python 3.8 environment.

Begin by installing the required packages:

 pip install msgpack-rpc-python
pip install airsim

Start with basic drone controls.

First, obtain the drone Client for API control and remember to unlock the drone.

Use .join() to control the drone with Async methods to ensure one action completes before the next one begins.

Here is a simple example:

import airsim

client = airsim.MultirotorClient() # Connect to the drone
client.enableApiControl(True) # Gain control
client.armDisarm(True) # Unlock
client.takeoffAsync().join() # Take off
client.landAsync(),join() # Land
client.armDisarm(False)
client.enableApiControl(False)
info

This Content is generated by ChatGPT and might be wrong / incomplete, refer to Chinese version if you find something wrong.

Loading Comments...