Main Content

Deployment and Verification Using PX4 Host Target and jMAVSim

UAV Toolbox Support Package for PX4® Autopilots provides the option to simulate PX4 autopilot algorithms that you develop in Simulink. The workflow is based on PX4 SITL (Software in the Loop). The support package supports simulation of algorithms by generating an executable on the host, referred as PX4 Host Target, and the jMAVSim simulator.

Note

The PX4 Host Target supports code generation and deployment like other supported hardware boards. You can also perform signal monitoring and parameter tuning of the Simulink model by selecting this option.

About jMAVSim

jMAVSim is one of the supported simulators for PX4-based targets. During the hardware setup of UAV Toolbox Support Package for PX4 Autopilots, this simulator is downloaded and installed, and allows you to view the flight of a quadcopter running the PX4 algorithm that you develop in Simulink. By using jMAVSim, you can test the algorithm for the desired take off, flight, and land actions.

Preparing PX4 Host Target and jMAVSim Using Hardware Setup Screens

You can use Hardware Setup process in UAV Toolbox Support Package for PX4 Autopilots to prepare the support package for using the PX4 Host Target and testing the connection with jMAVSim simulator.

Perform these steps as part of Hardware Setup to enable PX4 Host Target and test the jMAVSim simulator:

  1. In the Select a PX4 Autopilot and build configuration Hardware Setup screen, select PX4 Host Target as the PX4 Autopilot board. The supported Build Target file is posix_sitl_default.

    Proceed with the subsequent step of Hardware Setup process to build the firmware and verify that the firmware build is successful.

  2. In the Test Connection Hardware Setup screen, click Launch PX4 Host Target and jMAVSim. The jMAVSim simulator opens in a new window and shows the flight of the quadcopter. This is a test flight using a pre-configured algorithm in the support package to ensure that the necessary components for the simulator are installed.

Launching PX4 Host Target and jMAVSim Simulator from the Simulink Model

After you prepare the flight controller algorithm using the Simulink blocks available in UAV Toolbox Support Package for PX4 Autopilots, you can launch the jMAVSim simulator to verify the flight. To do this:

  1. In the Modeling tab, click Model Settings. In the Configuration Parameters dialog box:

    1. In the Hardware board list, select PX4 Host Target.

    2. Under Target Hardware resources > Build Options, select the Build action as Build, load and run.

    3. Click Apply and then OK.

  2. On the Hardware tab, in the Mode section, select Run on board, and then select one of these options to launch jMAVSim simulator:

    • To view the flight of the PX4 based flight controller based on the algorithm that is present in the Simulink model, click Build, Deploy & Start. The jMAVSim simulator is launched after sometime in a separate window.

    • To view the flight of the PX4 based flight controller based on the algorithm and perform signal monitoring and parameter tuning of the Simulink model, click Monitor & Tune. The jMAVSim simulator is launched in a separate window. You can change the parameters in the Simulink model and view the change in the simulated flight at runtime in the jMAVSim simulator.

Note

It has been observed that on some Ubuntu 18.04 Virtual Machines, there are issues while launching jMAVSim and PX4 Host Target from MATLAB. You might encounter a java crash dialog on these systems in place of the expected jMAVSim and PX4 Host Target Windows. To workaround these behavior, follow the below steps.

  1. Build the Simulink model for PX4 Host Target and wait for the build to complete.

  2. If the jMAVSim and PX4 Host Target are not launched automatically after the build is complete, then launch a Terminal.

  3. Navigate to the PX4 Firmware directory in the launched Terminal.

  4. Execute the following command in Terminal to manually launch both PX4 Host Target and jMAVSim.

    make px4_sitl

  5. To tune parameters and monitor signals, click Connect from Hardware tab of Simulink toolstrip after PX4 Host Target and jMAVSim are launched.

Note

With PX4 Firmware v1.10.2, it has been observed that the PX4 Host Target may exhibit issues with modules not responding after one hour of simulation time.

Note

On Ubuntu 18.04 platform, it is recommended that you set the sample time as 1 millisecond for the Simulink models to be deployed on PX4 Host Target. If the sample time is greater than 1 millisecond, issues may occur while writing to some uORB topics such as actuator_outputs.