Skip to main content

Initial Configuration and Python API Call of AirSim

· 3 min read
MuelNova
Pwner who wants to write codes.

(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...