Main Content

PX4 Hardware-in-the-Loop System Architecture

Hardware-in-the-Loop simulation (HITL) in PX4® is a simulation mode in which normal mode PX4 Firmware is run on real PX4 hardware. The workflow is based on Hardware-in-the-Loop simulation (HITL).

PX4 HITL System Diagram

When the autopilot is configured in the HITL configuration,

  • No sensors are started on hardware and the actuators are disabled.

  • The autopilot is connected to a UAV dynamics simulator (jMAVSim, Gazebo and so on) over an USB.

  • The simulator also bridges the data between autopilot and QGroundControl over UDP.

  • The simulator can also bridge data between autopilot and another computer.

The various modules in PX4 HITL are connected to each other as shown in this image.

PX4 HITL system diagram

PX4 HITL Physical Communication Diagram

The following diagram shows a simplified version of the above diagram for establishing HITL between Pixhawk® 4 and Host Computer.

  • The Pixhawk 4 is configured in HITL mode.

  • The Simulator and QGroundControl is running on Host Computer.

  • The Pixhawk 4 communicates to the Simulator via USB connection between Pixhawk 4 and Host Computer.

  • The Simulator bridges the MAVLink data between Host Computer and Pixhawk 4 via UDP.

PX4 HITL communication

PX4 HITL Physical Communication Diagram for Monitor & Tune (External Mode) Simulation in Simulink

The flight controller algorithm can be deployed from Simulink® on the PX4 Autopilot using the UAV Toolbox Support Package for PX4 Autopilots. In this scenario, you can run Monitor & Tune Simulation to tune the algorithm in real time on the autopilot and log the real time signals in Simulink. In this case an additional serial port is required to establish Monitor & Tune communication with the Autopilot. Since the USB port is already occupied for transferring MAVLink data between host computer and Autopilot in HITL mode, you need to use any of the other available serial ports on the Autopilot. For example, in the below diagram, TELEM1 (/dev/ttyS1) is used on Pixhawk 4 to communicate with Simulink running on Host Computer using Monitor & Tune Simulation. The Tx and Rx from the TELEM1 port on Pixhawk 4 can be connected to the Rx and Tx of the FTDI (Serial to USB Converter) device which is connected to host computer over another USB port. The pinout for the TELEM1 port of Pixhawk 4 can be found here.

PX4 HITL communction - monitor & tune

Consider the following points while configuring a serial port on Pixhawk Autopilot for Monitor & Tune.

Note

The following points are documented for Pixhawk 4 and TELEM1 port, however the points are also valid for any other Autopilot and any other serial port on the Autopilot.

  • Ensure that the MAVLink is not enabled on the port where you want to enable Monitor & Tune. The MAVLink can be disabled on such port by removing the port from MAV_0_CONFIG or MAV_1_CONFIG or MAV_2_CONFIG from QGroundControl.

  • Use a Serial to USB Converter (FTDI) to communicate with the host. Ensure that the Tx and Rx of TELEM1 are connected to Rx and Tx of FTDI (Tx of TELEM1 -> Rx of FTDI and vice-versa). Follow the pinout diagram for Pixhawk 4 found here. For other Autopilots, search for correct pinout and do the connection accordingly.

  • For some Autopilots, the maximum baud rate that you can set for communication is 115200. It is recommended to set 921600 for advanced Autopilots or 115200 if you see connection or data drop issues in Monitor & Tune.