The UAV Toolbox Support Package for PX4® Autopilots provides the option to deploy the controller on the PX4 Autopilot and verify the algorithm by running Hardware-in-the-Loop (HITL) simulation. The workflow is based on Hardware in the Loop Simulation (HITL).
The UAV Toolbox Support Package for PX4 Autopilots supports enabling Hardware-in-the-loop (HITL) simulation mode in which the Simulink generated code integrated with PX4 firmware is run on real flight controller hardware. This feature helps you in testing most of the actual flight code on the real hardware.
Perform these steps, which are a part of the Hardware Setup process in the UAV Toolbox Support Package for PX4 Autopilots, to enable the PX4 Autopilot for HITL simulation.
In the Select a PX4 Autopilot and Build Target Hardware Setup screen, select any Pixhawk Series board as the Hardware board. For example, PX4 Pixhawk 1. Click Next.
This feature supports only Pixhawk Series board and does not support PX4 Host Target.
In the Select System Startup Script in PX4 Hardware Setup screen, select Use default startup script(rcS) and click Next.
In the Download QGroundControl Hardware Setup screen, download and install QGC. After installation, click Verify Installation and then click Next
Proceed with the subsequent steps in the Hardware Setup process to build the firmware and verify that the build is successful.
After completing the Hardware setup process, prepare the flight controller algorithm using the Simulink blocks available in the UAV Toolbox Support Package for PX4 Autopilots.
In the Modeling tab, click Model Settings.
In the Configuration Parameters dialog box, choose any Pixhawk Series board.
Click HITL and then select Enable HITL Mode. Enabling HITL mode ensures that the jMAVSim simulator is automatically configured and launched to run along with the Simulink model.
Click External mode and select
/dev/ttyS6 as the Hardware board serial
If you select PX4 Pixhawk 1 hardware board, then configure /dev/ttyS6 tab. If you select any other Pixhawk Series board, configure the appropriate /dev/tty tab.
For more information, see Using External Mode over FTDI with Pixhawk 1.
Clear the Use the same host serial port for External mode as used for firmware upload option.
In the Host Serial port parameter, enter the host serial port number on the host computer for External mode communication.
Click MAVLink and ensure that Enable MAVLink on /dev/ttyACM0 option is selected.
Click /dev/ttyS6 and set the Baud rate
115200. Do not change any other parameters.
Click Apply and then click OK.
Perform these steps to configure and setup QGroundControl (QGC).
Upload PX4 v1.10.2 released firmware to the Pixhawk autopilot. Ensure that the
cmake file is not modified to exclude PX4 controllers and the
rc.txt is not present. To download firmware for your PX4
board go to PX4
Firmware. For example, download
Pixhawk 1 board.
The PX4 firmware version supported for R2021b is PX4 v1.10.2. However as v1.10.2 firmware image is not available for download in PX4 repository, use v1.10.1 for the setup process.
In the QGC, navigate to Vehicle Setup >
Firmware. Select Advanced settings and
Custom firmware file from the drop-down list. In
Firmware Setup option, click Ok and
Continue with the onscreen instructions to install the firmware.
Connect the autopilot to QGC via USB.
Enable HITL mode.
Navigate to Setup > Safety section.
Select Enabled from the HITL Enabled list.
Navigate to Setup > Airframes.
HIL QuadCopter and then click
Apply and Restart on top-right of the Airframe
In the General tab of the settings menu, clear all AutoConnect options except UDP.
This selection is done only for HITL mode. Later, if you want to connect to a non HITL hardware, return to this settings menu and select Pixhawk option also.
Select Virtual Joystick.
In the General tab, from Fly View of the settings menu, select Virtual Joystick option.
Configure Joystick and Failsafe. Set the following parameters to use a joystick instead of an RC remote control transmitter:
Ensure there are no warnings in the Vehicle Settings tab of QGC. Only the Power tab can be in red (with warning). If you see warnings for the Flight Modes tab, set it up by picking a mode for each of the channels. Sometimes, the Sensor Calibration tab can be in red. You can go ahead with it.
Ensure that SD card is inserted in the hardware for the mission upload from QGC to work.
Close the QGC.