Understanding the IRIS with Standoffs Demo
Proper testing of a flight controller (FC) is crucial for safety and continuous integration. Software in the loop (SITL) allows us to run an FC in a simulated environment. Many FC firmwares support SITL including PX4 and Betaflight which allows the FC to execute on an x86 Linux machine and interact with the Gazebo simulator. In this write up we will be looking specifically at Betaflight.
We can also connect to the FC using the configurator by selecting a manual connection and adding,
as the Port value.
To send MultiWii commands over this channel I added TCP support to the pyMultiWii Python module. Using this API we can then send RC commands to the FC and control the drone in a simulated environment.
Before we send commands to the FC we need to get the quadcopter running in the simulated environment. First start Gazebo,
cd /usr/share/gazebo-8/worlds gazebo --verbose ./iris_arducopter_demo.world
Then from your BetaFlight source start the FC in SITL,
You will know the Betaflight FC has connected to the Gazebo ArduCopter if you see the following in the Gazebo output,
[Dbg] [ArduCopterPlugin.cc:573] ArduCopter controller online detected.
A world file is an XML document defining a world including the physical objects it contains, lighting and the physics engine. The XML file uses the SDF format which is a popular way to describe robotic simulators.
In the file
there is a model that is loaded called,
This model is included with the Gazebo installation, its source code is available here. This model actually only contains two files, one of which is an SDF file. This SDF file assembles the quadcopters parts such as the frame, gimbal and rotors as well as loading the all the necessary plugins (libArduCopterPlugin, and libLiftDragPlugin).
iris_with_standoffs model is the quadcopter frame/body which exists
iris_with_standoffs contains the physical characteristics of
the quadcopter including the 3D mesh files.
As for the plugins, the libLiftDragPlugin provides the ability to simulate the aerodynamics of the quadrotor. The ArduCopterPlugin is included with Gazebo, and provides the network interface to allow the FC to communicate with Gazebo. Its source code is available here.
Now that we’ve walked through all the pieces needed for Betaflight SITL we will want to make some modifications to either our world, or quadcopter, after all everything is open source! Thus far everything is included in the Gazebo installation (obviously excluding Betaflight). Gazebo exposes some environment variables allowing us to specify our own locations for models, worlds, plugins, etc. So set these environment variables, clone/fork these repos, and get hacking!