Permalink
130 lines (110 sloc) 7.55 KB

AirSim on Unity

  • AirSim on Unity allows you to run your simulators in the Unity Engine. This project comes with some sample Unity projects and a wrapper around the AirLib library to run as a native plugin in Unity.
  • Included are two basic Unity Projects, one for a Car simulator and another for a Drone simulator. They are meant to be lightweight, and can be used to verify your setup is correct.
  • Check out the Unity blogpost for overview on the release.

Warning: Experimental Release

This project is still in early development, expect some rough edges. We are working to fully support the full AirLib API and feature set, but some things may be missing. Click here for the list of currently supported APIs.

Windows

Building from source

Install Unity

Build Airsim

  • Install Visual Studio 2017. Make sure to select VC++ and Windows SDK 8.1 while installing VS 2017.

  • Start x64 Native Tools Command Prompt for VS 2017.

  • Clone the repo: git clone https://github.com/Microsoft/AirSim.git, and go the AirSim directory by cd AirSim.

  • Run build.cmd from the command line.

Build Unity Project

  • Go inside the AirSim\Unity directory: cd Unity.
  • Build the unity project: build.cmd.
  • Additionally, there is a free environment Windridge City which you can download from Unity Asset Store. And, of course, you can always create your own environment.

Linux

Necessary Packages

The linux wrapper requires Boost filesystem, which you can install by running the following command:

sudo apt-get install libboost-all-dev

Download and Install Unity for Linux

Warning: Unity Editor for Linux is still in Beta. Expect some rough edges.

Unity Editor

  • Download the editor by doing one of the following:
    1. Navigate to the latest post on this thread and click the download link
    2. Open a terminal window and enter the following command:
      wget https://beta.unity3d.com/download/dad990bf2728/UnitySetup-2018.2.7f1
      
  • Install The editor
chmod +x UnitySetup-2018.2.7f1
./UnitySetup-2018.2.7f1

Build Airsim in Linux

  • Open a new terminal window on your linux machine
  • Clone the repo: git clone https://github.com/Microsoft/AirSim.git, and go the AirSim directory by cd AirSim.
  • Run setup.sh and subsequently build.sh from the the terminal.

Generate AirsimWrapper Shared Library

  • On your linux machine, navigate to your AirSim repository, and run the following commands in a terminal window:
     cd Unity
     ./build.sh
    

This will generate the necessary shared library and copy it to the UnityDemo Plugins folder.

Usage

  • Start Unity and click Open project.
  • Select the folder AirSim\Unity\UnityDemo, and then hit the button Select Folder.
  • In the bottom pane, Click on Projects->Assets->Scenes. Then, Double-click on SimModeSelector. This will load the SimModeSelector scene into the scene hierarchy pane. DO NOT add CarDemo or DroneDemo scene into the scene hierarchy pane.
  • Hit the play button to start the simulation (and hit play again to stop the simulation. .
  • Alternatively, you can change the SimMode in your Settings.json file. (You can read more about Settings.json here)
  • Controlling the car:
    Use WASD or the Arrow keys or the AirSim client.
  • Controlling the drone:
    Keyboard control is not currently available for drone flight.
  • Changing camera views:
    Keys 0, 1, 2, 3 are used to toggle windows of different camera views.
  • Recording simulation data:
    Press Record button(Red button) located at the right bottom corner of the screen, to toggle recording of the simulation data. The recorded data can be found at Documents\AirSim\(Date of recording)

Cross-Compiling to Linux

Unity Editor supports compiling projects to Linux systems. After following the steps to build AirSim and Unity on Windows, do the following:

Linux Pre-Requisites

Before being able to run Unity Binaries with the Airsim plugin, be sure have airsim and airsim unity built on your linux machine by following the Linux build steps above.

Package UnityDemo Binary On Windows

Install Necessary Components

In order to package your project for linux, the Linux Build Support Unity add-on must be installed.

  • Open Unity Hub, and click the Add component button in the dropdown window under more options to the right of your Unity 2018.2.15f1 tab. Adding components
  • Make sure the Linux Build Support Platform is selected Adding components Once this component is successfully installed, you are ready to build Unity Projects for Linux!

Build the Project

  • On your Windows machine, build the Unity Demo by navigating to the build settings option in the toolbar File -> Build Settings
  • Make sure the following scenes are set to be built:
    1. SimModeSelector
    2. CarDemo
    3. DroneDemo
  • Set the target operating system to linux, and choose the version appropriate for your system (x86 vs x86_64)
  • Click Build
  • Transport the built project as well as the generated folder "{project_name}_Data" to your linux machine

Copy The AirsimWrapper Library to the Project Plugins folder

  • On your linux machine, navigate to your AirSim repository, and run the following commands in a terminal window:
     cp Unity/linux-build/libAirsimWrapper.so path/to/your/project/{project_name}_Data/Plugins/{os_version}
    

This will generate the necessary shared library to allow Airsim to communicate with Unity and copy it to the plugins folder of your project binary.

Run the Project Binary

  • Open a terminal and navigate to your project directory
  • Set your project binary as an executable file:
chmod +x "{project_name}.{configuration}"
  • Run the binary file
./{project_name}.{configuration}

Using Airsim API

  • For quickstart with the Python APIs for the car or the drone, simply run the hello_car.py or the hello_drone.py script accordingly.
  • Details of the AirSim C++ and Python APIs are here.

Acknowledgements

  • The drone object was provided by user 31415926 on sketchfab. It is licensed under the CC License.