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.
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.
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:
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
Proceed with the subsequent step of Hardware Setup process to build the firmware and verify that the firmware build is successful.
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:
In the Modeling tab, click Model Settings. In the Configuration Parameters dialog box:
In the Hardware board list, select PX4 Host Target.
Under Target Hardware resources > Build Options, select the Build action as Build, load and run.
Click Apply and then OK.
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.
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.
Build the Simulink model for PX4 Host Target and wait for the build to complete.
If the jMAVSim and PX4 Host Target are not launched automatically after the build is complete, then launch a Terminal.
Navigate to the PX4 Firmware directory in the launched Terminal.
Execute the following command in Terminal to manually launch both PX4 Host Target and jMAVSim.
To tune parameters and monitor signals, click Connect from Hardware tab of Simulink toolstrip after PX4 Host Target and jMAVSim are launched.
With PX4 Firmware v1.12.3, it has been observed that the PX4 Host Target may exhibit issues with modules not responding after one hour of simulation time.
With PX4 Firmware v1.12.3, it has been observed that the drone in SITL mode crashes sporadically.
Set the number of EKF instances to
1to reduce the crashes substantially. To do this, set
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