PX4 is a great platform to implement a UAV system based on a opensource autopilot. One of the great features of PX4 is that you can run a SITL simulation(Software in the loop simulation) to simulate your flight on simulation. This is useful as you can check new mission or control algorithms before actually flying the quadrotor and possibly damaging it. This article shows will show you how to run a SITL for PX4 and how to interact with it through gazebo and qgroundcontrol. The article has mainly the same contents as the tutorial but is reorganized and more specific for the purpose of offboard control.
A brief introduction to Software in the loop simulation
Software in the Loop is a simulation of a system which is modeled and run under software without any hardware. To develop a control software, usually the system will have to pass three simulation verification before the software is implemented into a real system.
The first is sometimes called MITL(Model-In-The-Loop) which only includes a mathematical model of the controller. The next is to verify the controller in a SITl(Software-In-The-Loop). Software in the loop simulations verify the actual software integration of the controller to see if there is any unforeseen problems within the system. The third process is the PITL(Processor-In-The-Loop) which verifies there are no problems within the processor calculations. The last procedure is to have a HITL(Hardware-In-The-Loop) which includes the major hardware components in the control system to verify the controller is working properly.
PX4 is a flight control platform and can be run on SITL mode. The diagram shows a simple example of a px4 in SITL mode.
The PX4 SITL can be interfaced using MAVLink (Similar to the real flight controller) through a UDP port.
Running the simulation
The current article is implemented based on ROS indigo. Other versions of ROS that has been after ROS indigo should work, but have not been verified. For installation instructions of ROS, try this tutorial.
Gazebo6 should be used for the PX4 gazebo plugin. You can check which specific version to use with ROS here.
PX4 and jMAVSim should be installed and compliled to run PX4 in SITL mode.
Clone the PX4 source.
mkdir -p ~/src cd ~/src git clone https://github.com/PX4/Firmware.git cd Firmware git submodule update --init --recursive cd ..
Running the simulation
Different airframes can be selected to run the simulation. Supported airframes include Multirotors(with/without optical flow sensors), Planes, VTOL(tail sitters, quadplanes).
The default quadrotor model is IRIS from 3DRobotics.
cd ~/src/Firmware make posix_sitl_default gazebo
Quadrotor with Optical Flow
cd ~/src/Firmware make posix gazebo_iris_opt_flow
Typhoon H 480
cd ~/src/Firmware make posix gazebo_typhoon_h480
cd ~/src/Firmware make posix_sitl_default gazebo_standard_vtol
cd ~/src/Firmware make posix_sitl_default gazebo_tailsitter
When the SITL is running properly, the log screen will appear as below.
Interfacing SITL with qgroundcontrol
The default UDP address for the mavlink is as follows
– to connect to a specific IP: “udp://:email@example.com:14557”
– to connect to a local host: “udp://:firstname.lastname@example.org:14557”
If qgroundcontrol is installed properly, it will automatically connect to the UDP port while the simulation is running.
Mission with Quadrotor
Mission with Standard VTOL
You can also change parameter files and do automatic missions just as if you are interacting with the real flight controller.
Interfacing SITL with ROS
The biggest advantage of interfacing to SITL through ROS has the same interface with interfacing with a real flight controller. You only need to change the fcl_url on MAVROS.
roslaunch mavros px4.launch fcu_url:=”udp://:email@example.com:14557″
It is good to have arguments on fcu_url in the launch file to be able to change between SITL and the real board to speed up the process.