From PaparazziUAV
Jump to: navigation, search

Hardware In The Loop Simulation

Hardware in the loop simulations (HITL) are a way to test an embedded system (the real hardware and software) by simulating its environment, ie. sensor inputs, and comparing its output, ie. actuator outputs, to expected output values.


While the Software In The Loop simulation (SITL) executes the airborne code on the ground host, HITL is a way to run the autopilot code on the actual hardware in an environment where sensors and actuators are simulated. Two processes are involved:

  • The real autopilot code on the control board;
  • A flight model combined with a model of the actuators and the sensors.

Commands computed by the autopilot are sent to the flight model which sends back simulated values of the sensors output (e.g infrared and GPS).

In Paparazzi, the link between the two processes is done through the telemetry/datalink:

  • Commands are sent through the standard COMMANDS telemetry message. Since the refresh rate must be high enough, a special telemetry file will be used (settings/hitl.xml)
  • Sensor values are sent through the HITL_UBX (GPS) and HITL_INFRARED datalink messages.


The airborne code has to be compiled with a specific flag to use these HITL messages instead of the sensors. The following line must be added in the makefile section of the airframe file (here for a Tiny 1 board where the modem is plugged to the UART0):


Note that a high baudrate (at least 57600) is required to allow the COMMANDS messages to be correctly transmitted.

The code has to be compiled (ap target) as usual and uploaded to the board. The HITL A/C entry provides an example of configuration for a Tiny 1 board (set UART1_BAUD for a Tiny 2).

 <aircraft name="HITL" ac_id="7"

The HITL session entry gives an example of the corresponding session involving the simhitl simulator agent, ran with the -ac HITL option (the name of the simulated aircraft), and the standard link, server and GCS. The link can be done with a serial cable (probably through USB) or with the installed modem.

 <session name="HITL">
  <program name="Hardware in the Loop">
   <arg flag="-a" constant="HITL"/>
   <arg flag="-noground"/>
   <arg flag="-boot"/>
  <program name="Data Link">
   <arg flag="-s" constant="57600"/>

Datalink through the USB link

As explained in this page, the USB link (used to flash the board) can replace the serial link. It is probably the easiest way to run a HITL session since a single cable is required between the host and the board. Using a USB powered developement board (such as this one), HITL simulation becomes as easy as the SITL one.

The hitl_usb.xml airframe file contains a minimal configuration (it is worth noticing that the useless servos section has been removed in this file) of HITL with serial USB. The specific lines of the makefile section are:

File: hitl_usb.xml
 ap.srcs += downlink.c $(SRC_ARCH)/uart_hw.c $(SRC_ARCH)/usb_ser_hw.c datalink.c pprz_transport.c
 ap.srcs += $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbcontrol.c
 ap.srcs += $(SRC_ARCH)/lpcusb/usbstdreq.c $(SRC_ARCH)/lpcusb/usbinit.c

Compile it and flash it as usual.

The port to use for the link agent is then /dev/ttyACM0