Aviumtechnologies

Pixhawk SIL Connector for Simulink

Simulink C++ S-function for software-in-the-loop simulation with Pixhawk.

pixhawk-sil-connector GitHub repository

Requirements

Note: Tested extensively on Windows with MSVC C/C++ compiler.

Files

SILConnector.h
pixhawk_sil_connector.cpp
make.m
includes.zip (contains the Asio C++ and MAVLink C libraries)

Build instructions

  • Install MATLAB-supported compiler
    https://mathworks.com/support/requirements/supported-compilers.html.
  • Download the "pixhawk_sil_connector.cpp" and "make.m" files and the "includes.zip" archive.
  • Unzip the "includes.zip archive".
  • Run "make.m" to compile the "pixhawk_sil_connector.cpp" file. If successfull a "pixhawk_sil_connector.mexw64" file will be created.

Note: If you are using a compiler other than MSVC (e.g. MinGW64) you need to add the "-lws2_32" flag to the "mex" command in the "make.m" file.

Use instructions

  • Download and install QGroundControl
    http://qgroundcontrol.com/.
  • Create a new "Comm Link" in QGroundControl via the "Application Settings" page. The type of the link must be UDP, thed port 18570, and the server address must be the ip address of the WLS 2 instance. You can use the "ip addr" command to find the ip of the WSL 2 instance. Note that the ip of the WSL isntance will change every time you relaunch the instance.
  • Open and run "pixhawk_sil_connector_example.slx".
  • Build the PX4-Autopilot source code in WSL 2 using the following commands:
    git clone --recursive https://github.com/PX4/PX4-Autopilot
    cd PX4-Autopilot
    git checkout v1.15.0
    git submodule sync --recursive
    git submodule update --init --recursive
    make px4_sitl_default
                        
    https://docs.px4.io/master/en/dev_setup/building_px4.html https://docs.px4.io/main/en/simulation/
  • If you already have a build of the PX4-Autopilot source code start PX4 using the following commands:
    cd build/px4_sitl_default
    export PX4_SIM_HOST_ADDR=x.x.x.x #(the ip of the computer running the Simulink model)
    export PX4_SIM_MODEL=none_iris
    ./bin/px4 -s etc/init.d-posix/rcS

Example use of the Pixhawk SIL connector with PX4 Autopilot running under Windows Subsystem for Linux (WSL).

Pixhawk SIL setup

Pixhawk SIL setup.

Pixhawk SIL connector example Pixhawk SIL connector example sensors

Pixhawk SIL connector example.