Main Content

PX4 Hardware-in-the-Loop (HITL) Simulation with Manual Control for Fixed-Wing Plant in Simulink

This example shows how to use the UAV Toolbox Support Package for PX4® Autopilots and take manual control inputs from Joystick / RC Transmitter and control the fixed-wing flight.

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.


  1. Open MATLAB®.

  2. Open the example MATLAB project by executing this command at the MATLAB command prompt:

  3. Once you open the project, click the Project Shortcuts tab on the MATLAB toolstrip and click Launch Manual Control Mode to launch the ManualControl controller.

    Alternatively, execute this command at the MATLAB command prompt.


    Manul control model

  4. In the Project Shortcuts tab, click Launch UAV Dynamics to launch the Simulink plant model named UAV_Dynamics_Autopilot_Communication.

    Alternatively, execute this command at the MATLAB command prompt.

  5. In the Simulink plant model, set the serial ports in MAVLink Bridge Source and MAVLink Bridge Sink blocks.

Run the Simulink Plant Model, Configure QGroundControl and Fly UAV

  1. Open QGC and connect to PX4. If the serial port is already disabled, run the Simulink plant model (UAV_Dynamics_Autopilot_Communication) so that the QGC gets connected to PX4 Controller.

  2. In the QGC, navigate to Vehicle Setup > Parameters.

  3. Set the input device in COM_RC_IN_MODE parameter.

    • If you are using a RC Transmitter, Select RC Transmitter option. For information on connection and calibration, see Radio (Remote Control) Setup.

    • If you are using a gamepad or joystick on the host, select Virtual RC by Joystick option. For more information, see Joystick Setup.

    Select input device

  4. Click Radio and move each sticks that control aileron, elevator, rudder, and throttle. Note the channel value changes in the Channel Monitor.

    Radio setup

    If the mapping is incorrect in the example model or between the channel number and controlled axes, correct it.

  5. Click Build, Deploy & Start from Deploy section of Hardware tab in the Simulink Toolstrip of the controller model ManualControl.

  6. After starting the Simulink plant model, move the left stick to right-bottom to arm the vehicle. Provide only the throttle for the drone to takeoff.


The moments along roll, pitch, and yaw axis exerted by the ground is not modelled. High control inputs can make the simulated plant turn to improbable angles.