About
MulticopterSim is a simple multicopter flight simulator using Unreal Engine. It runs on Windows, using sockets to communicate stick demands, vehicle state and camera images with flight-control programs written in various languages. This approach supports rapid prototyping of flight-control algorithms without having to recompile the simulator itself.
Prerequisites
Hardware
I am currently developing MulticopterSim on an HP Z440 workstation with 32GB RAM and NVIDIA GeForce GTX 1080 Ti. It may however be possible to develop on a less βloadedβ machine β see here for the minimum requirements recommended by Unreal Engine.
For a realistic flying experience, you will also likely want some sort of game controller or R/C transmitter. MulticopterSim currently supports the following controllers through the Joystick class:
- PS4 controller
- XBox One controller
- XBox 360 controller
- XBox 360 controller clone
- PS3 controller clone
- Logitech Extreme Pro 3D joystick
- Logitech F310 gamepad
- FrSky Taranis TX9 RC transmitter with mini USB cable
- FrSky XSR-Sim dongle
- Spektrum WS1000 dongle
- Great Planes RealFlight Interlink
If you don't have a controller, MulticopterSim will use input from the numeric keypad on your keyboard (make sure that NumLock is turned on!) The key mappings are based on those used in Microsoft Flight Simulator.
Toolchain
You will need Unreal Engine 5 (UE5) and Visual Studio C++. I am attempting to use the latest versions, which as of the time of this writing are UE5.2.0 and Visual Studio 2022. To install UE5 and Visual Studio, follow the directions here.
Building
-
Clone this repository.
-
Right-click on the Simulator/MulticopterSim.uproject file and select Generate Visual Studio project file to generate a .sln file
-
Double-click on the resulting MulticopterSim.sln file to launch VisualStudio. The first time you do this, you may have to wait a few minutes while Visual Studio parses up all of the UE5 files needed to build the project.
-
In VisualStudio, hit the F5 key to build the project and launch UnrealEditor.
-
In UnrealEditor, select one of the maps in Content Drawer/MulticopterSim/Maps. Then open the Content/C++ Classes/MulticopterSim/vehicles folder and drag the Phantom pawn into the map.
-
To enable interaction outside of the editor, the first time you run the simulator you will want to go to Edit -> Editor Preferences -> Performance and disable the option Use Less CPU when in Background:
Testing
Clone the SimFlightControl repository. Run the launch.py script in SimFlightControl/python/. It will tell you to hit the Play button back in the simulator. When you hit the button, the vehicle should rise quickly to an altitude of 10 meters.
Image processing
If you have Python OpenCV installed on your computer, you can try out the simulated camera feature of MulticopterSim by un-commenting the vehicle.addCamera() line in the source code. Running the Python launch program again, you should see a 640x480 image showing edge detection in OpenCV. This feature can be glitchy the first time you try it.
Design principles
The core of MulticopterSim is the C++ VehicleThread class. This class provides support for running the vehicle dynamics and the PID control regime on its own thread, after it first disables the built-in physics in UE5. The dynamics used are based directly on the model presented in this paper, written as a standalone, header-only C++ class that can be easily adapted for other simulators and applications if desired. This class also supports different frame configurations (quadcopter, hexacopter) via virtual methods.
The Camera class can be instantiated to transmit the images collected by a simulated gimbal-mounted camera on the vehicle, using a library like OpenCV. Computer-vision algorithms running in a Camera subclass can then be used as input to the PID control running in the VehicleThread. The following figure illustrates this arrangement, using a traditional cascade-control (slow outer loop / fast inner loop) diagram:
Citing MulticopterSim
Please cite MulticopterSim as:
@ARTICLE{10.3389/fnbot.2020.00016,
AUTHOR={Levy, Simon D.},
TITLE={Robustness Through Simplicity: A Minimalist Gateway to Neurorobotic Flight},
JOURNAL={Frontiers in Neurorobotics},
VOLUME={14},
YEAR={2020},
URL={https://www.frontiersin.org/articles/10.3389/fnbot.2020.00016},
DOI={10.3389/fnbot.2020.00016},
ISSN={1662-5218}
}