Main Content

PX4 Hardware-in-the-Loop (HITL) Simulation with Fixed-Wing Plant and Hardcoded Mission in Simulink

This topic shows how to use the UAV Toolbox Support Package for PX4® Autopilots to verify the controller design by deploying the design on the Pixhawk® hardware board. This is done in HITL mode with fixed-wing UAV Dynamics contained in Simulink®. The mission is hardcoded in MATLAB® and is executed by the GNC model once armed.

Before starting with Simulink, ensure that you go through PX4 Hardware-in-the-Loop (HITL) Simulation with Fixed-Wing Plant in Simulink example and perform Step 1, Step 2, and Step 3.

Run the UAV Dynamics Model, Upload Mission from QGroundControl and Fly UAV*

  1. To use the mission hardcoded in MATLAB, run the following command in MATLAB command prompt.

    isMissionFromQGC = 0;
  2. In the Simulink toolstrip of the Plant model (UAV_Dynamics_Autopilot_Communication), on the Simulation tab, click Run to simulate the model.

    Run model

  3. Enable the Joystick in QGC.

    Waypoints are hardcoded and stored in a InitWaypoints.m data file. For more information on the structure, see Mission Data UAV Path Manager. As the waypoints are hardcoded, do not add a mission in QGC. Enable Virtual Joystick in QGC Application Settings as shown below.Virtual Joystick

  4. Change the flight mode to Manual in the QGC.

    Note

    The mission is hardcoded in MATLAB and is executed by the GNC model once armed. It is not possible to arm the UAV in the mission mode.

    QGC not ready

  5. Drag the left joystick to the bottom-right corner for a couple of seconds to arm the UAV. The flight starts to execute.

    Joystick

    An image of the expected flight trajectory is shown here.

    Sample flight