Hardware in the loop simulation is a simulation mode where the autopilot is connected to the simulator and all flight code runs on the autopilot. This approach has the benefit of testing the actual flight code on the real processor.
PX4 supports HITL for multicopters (using jMAVSim) and fixed wing (using X-Plane demo or full). Flightgear support is present as well, but we generally recommend X-Plane. To enable it, configure it via the airframe menu.
- Make sure QGroundControl is not running (or accessing the device via serial port)
- Run jMAVSim in HITL mode (replace the serial port if necessary):
./Tools/jmavsim_run.sh -q -d /dev/ttyACM0 -b 921600
- The console will display mavlink text messages from the autopilot.
- Then run QGroundControl and connect via default UDP configuration.
In X-Plane two key settings have to be made: In Settings -> Data Input and Output, set these checkboxes:
In Settings -> Net Connections in the Data tab, set localhost and port 49005 as IP address, as shown in the screenshot below:
Widgets -> HIL Config, then select X-Plane 10 in the drop-down and hit connect. Once the system is connected, battery status, GPS status and aircraft position should all become valid:
If a joystick is preferred over a radio remote control, set the parameter COM_RC_IN_MODE
to 1
. It can be found in the Commander parameter group.
Switch to the flight planning view and put a single waypoint in front of the plane. Click on the sync icon to send the waypoint.
Then select MISSION from the flight mode menu in the toolbar and click on DISARMED to arm the plane. It will take off and loiter around the takeoff waypoint.