This is a project for simplifying the use of the AirSim drone simulator.
Airsim is a simulator for drones, cars and more, built on Unreal Engine. It is open-source, cross platform, and supports hardware-in-loop with popular flight controllers such as PX4 for physically and visually realistic simulations. It is developed as an Unreal plugin that can simply be dropped into any Unreal environment. Airsim's goal is to develop AirSim as a platform for AI research to experiment with deep learning, computer vision and reinforcement learning algorithms for autonomous vehicles. For this purpose, AirSim also exposes APIs to retrieve data and control vehicles in a platform independent way.
But, AirSim is hard to work with. That's why we made this package.
This project works on windows. Linux and MacOS weren't tested.
Download one of the environments in the Environments section, one built by Airsim, or build one yourself.
Clone or download this repository into your project.
Install the python prerequisites using pip:
pip install -r requirements.txt
Copy settings.json
to C:\Users\<username>\Documents\AirSim\
.
For keyboard control (optional) install vJoy.
Create a new python file and paste the following in it:
from simple_airsim.api import coordinate_system
from simple_airsim.api.drone import Drone
from simple_airsim.api.gui_manager import GUIManager
from simple_airsim.api.manager import Manager
def my_algorithm(drone: Drone):
# Add your code here
pass
if __name__ == '__main__':
with Manager(coordinate_system.AIRSIM, method=my_algorithm) as man:
with GUIManager(man, 10, 10, 10, 3) as gui:
gui.start()
Your algorithm will be inside my_algorithm
.
Look at the following example:
import time
from simple_airsim.api import coordinate_system
from simple_airsim.api.drone import Drone
from simple_airsim.api.gui_manager import GUIManager
from simple_airsim.api.manager import Manager
def square(drone: Drone):
drone.takeoff(True)
while True:
for i in range(4):
drone.move_by(1, 0, 0, True)
drone.turn_by(0, 0, 90, True)
time.sleep(0.1)
if __name__ == '__main__':
with Manager(coordinate_system.AIRSIM, method=square) as man:
with GUIManager(man, 10, 10, 10, 3) as gui:
gui.start()
This code will make the drone fly in a square.
The simulative drone is controlled using calls to a Drone object. The following calls are supported:
Starts the drone. The drone will stay in place until the next command is sent.
Cancel the last command and stay in place.
Lands the drone.
Moves by a specified relative distance (in x, y, z).
Turns by a specified relative angle (in roll, pitch, yaw).
Sets the desired roll, and pitch, the desired turn speed in the yaw, and the desired height in the z.
Returns the drone's position in relation to it's starting point, as a dictionary of 'x', 'y', and 'z' in meters.
Returns the drone's orientation in relation to it's starting point, as a dictionary of 'roll', 'pitch' and 'yaw', in degrees.
Returns the drone's velocity in all directions an angles as a dictionary of 'x', 'y', 'z', 'roll', 'pitch', and 'yaw'. The distances are in meters per second, an the angles are in degrees per second.
Returns the distances from the closest object in all siz directions as a dictionary of 'up', 'down', 'right', 'left', 'front', and 'back', in meters.
Most of the calls also have a 'wait' variable that when set to True will cause the call to only return when finished executing.
When in Manual Mode, the drone can be controlled using the keyboard, where w/s is throttle, a/d is yaw, up/down is pitch and right/left is roll.
We built a few environments to use with this project.
Link: Google Drive.
A simple square track for testing. Link: Google Drive.
Link: Google Drive.
A single-floor house based on a image of a house plan. Link: Google Drive (Additional files: Google Drive).