Main Content

Deployment on Unsupported PX4 Autopilots from Simulink

This topic helps you to get started with an autopilot that does not belong to set of officially tested autopilots. This topic uses Cube Orange as an example for deploying Simulink® generated code. However, Cube Orange is an officially supported PX4® Autopilot. For information on deployment on Cube Orange Autopilot from Simulink, see Deployment on Cube Orange Autopilot from Simulink.

Before starting with Simulink, ensure that you install the latest stable version of QGroundControl and able to upload latest stable version of PX4 Firmware from QGroundControl. If you are facing issue with USB connection, It is recommended to install Mission planner and do a clean re-installation of latest drivers as described in this page.

After you successfully upload the PX4 firmware from QGroundControl, get started with UAV Toolbox Support Package for PX4 Autopilots.

Select Custom PX4 Autopilot Hardware Setup

  1. If the support package is already installed, start the hardware setup by opening the Add-On Manager.

  2. In the Add-On Manager, start the hardware setup process by clicking Setup button, .

    After starting, the Hardware Setup window provides instructions for configuring the support package to work with your hardware.

  3. In the Select a PX4 Autopilot and Build Target screen, select My board is not listed here.

    Select PX4 Autopilot board

  4. Browse to the corresponding CMake Build target (cubepilot_cubeorange_default) in your PX4 Firmware for building.

    Select PX4 Autopilot board

    Select PX4 Autopilot board

  5. Verify the correct make command to build the firmware for Cube Orange and then click Build Firmware.

    Select PX4 Autopilot board

  6. For Cube Orange, the bootloader COM Port and the main communications COM Port are different. Because of this issue, you might not be able to complete the Test connection step in hardware setup. You can skip this step.

Select PX4 Pixhawk Series as the Simulink Target Hardware

After hardware setup is completed and the PX4 Firmware is successfully built for the selected build target, you can use your Cube Orange autopilot in Simulink by selecting PX4 Pixhawk® Series as Hardware board in the Simulink model configuration settings.

Configuration parameters

The selected CMake build target in hardware setup automatically appears in CMake configuration.

CMake configuration

Set COM Port for Upload and Communication in Simulink

In some Cube Orange boards, the bootloader COM Port for uploading the firmware and the main communications COM Port are different.  When you connect to such boards, the bootloader port appears first in the Device Manager. The port shows for a few seconds and then the main communications port appears. The bootloader COM port is needed for firmware upload and the communication port is needed for MAVLink communication or Monitor and Tune simulation.

For example, below is a snapshot of the Device Manager window when a Cube Orange is connected. After connecting, a COM port called ProfiCNC Cube (COM13) comes up under ports. This is the bootloader port needed for firmware upload. This port stays for a while after which the board loads the main Firmware and the main communication port Cube Orange PX4 (COM14) comes up. Hence, for this board COM13 is the bootloader port and COM14 is the communications port.

COM Port

Ensure that you specify the correct COM ports for firmware upload and MAVLink communication. You will be unable to upload the firmware if you specify the communication COM port value instead of bootloader COM port value for firmware upload. In such cases, perform the following steps to set the upload and communication port correctly for a Pixhawk board in the Simulink model for different modes of simulation.

Set Bootloader COM Port for Firmware Upload and Deploy

  1. For the Simulink model, launch the Model Settings.

    A sample image of the default settings for hardware implementation is shown here.

  2. Enter the bootloader serial port in Serial Port for firmware upload (This should be the bootloader port).

  3. Deploy the Simulink model. On the Hardware tab, in the Mode section, select Run on board and then click Build, Deploy & Start.

Set Communication COM Port for Monitor & Tune (External Mode)

  1. Perform the settings for Build options as shown in the topic Set Bootloader COM Port for Firmware Upload and Deploy.

  2. In External mode tab, clear the Use the same host serial port for External Mode as used for firmware upload option and mention the main communications port in Host Serial Port (this must be different from the bootloader port you mentioned earlier in Build options).

  3. Run the model in External Mode.

Set Communication COM Port for PIL

  1. Perform the settings for Build options as shown in the topic Set Bootloader COM Port for Firmware Upload and Deploy.

  2. In PIL Tab, clear the Use the same host serial port for PIL as used for firmware upload option and mention the main communications port in Host Serial port (this must be different from the bootloader port you mentioned earlier in Build options).

Limitations

  • Connected I/O Simulation is not supported with PX4 Pixhawk Series boards.

  • In the PX4 HITL Simulation with jMAVSim example, jMAVSim does not launch automatically from Simulink. To launch jMAVSim simulator Manually,

    • Navigate to the installed Cygwin™ Toolchain directory in your PC.

    • Launch the batch file run-console.bat. This opens the Cygwin console.

    • Change the directory to Firmware folder of the downloaded PX4 Firmware and run the following command. Provide the communication COM port as an argument.

      ./Tools/jmavsim_run.sh -q -s -d COM13 -b 921600 -r 250

  • In the MAT-file logging on SD card example, provide communication COM port as an input argument to the getMATFilesFromPixhawk function. Automatic detection of COM port is not supported with Cube orange.

    getMATFilesFromPixhawk('px4demo_log','DeleteAfterRetrieval', true,'COMPort','COM13')