Read PX4 System Parameters Using PX4 Autopilots Support Package
This example shows you how to read the PX4® system parameters using UAV Toolbox Support Package for PX4 Autopilots.
Introduction
In this example, the pre-configured model (px4demo_Read_Parameter), is used to demonstrate how to read the Gyroscope calibration parameters like offset and scaling, and use them along with raw Gyroscope values from a PX4 flight controller.
The PX4 flight controller uses many parameters to store and access during various operations. Much of these include sensor/actuator calibration data and are stored in flash memory which is accessible by MTD via NuttX.
You can read the default parameters or follow the guide to create your own parameters.
In this example, you will learn how to create and deploy a Simulink® model to read PX4 system parameters.
Prerequisites
If you are new to Simulink, watch the Simulink Quick Start video.
Perform the initial Setup and Configuration of the support package using Hardware Setup screens.
Required Hardware
To run this example, you will need the following hardware.
Supported PX4 Autopilot
Micro USB type-B cable
Micro-SD card (already used during the Performing PX4 System Startup from SD Card)
Task 1 - Configure the Model for Pixhawk Hardware
1. Connect your Pixhawk® board to the host computer using the USB cable.
2. Open the px4demo_Read_Parameter model.
This model is configured to use the PX4 Pixhawk Series boards, and it contains six PX4 Parameter Read blocks that can read six different PX4 system parameters.
3. To configure the model, go to the Modeling tab and click Model Settings.
4. In the Configurations Parameters dialog box, select Hardware Implementation.
5. Set the Target Hardware as the PX4 Autopilot hardware you have selected during hardware setup screens.
6. From the Groups list under Target hardware resources, select Build options. In the Serial port for firmware upload field, enter the serial port to which the hardware PX4 flight controller is connected to host computer.
7. From the Groups list under Target hardware resources, select External mode. In the hardware board serial port, select /dev/ttyACM0.
8. Click Apply and then OK to close the dialog box.
Task 2 - Configure and Run the Model
In this task, you will configure and run the Simulink model. While running the model, you can select either Monitor and Tune option or the Connected IO option. For more information, see Monitor and Tune the Model Running on PX4 Autopilots and Communicate with Hardware Using Connected I/O.
Perform these steps to configure and run the model.
1. In the Simulation tab, specify the stop time for parameter tuning simulation. The default value for the Stop time parameter is 10.0 seconds. To run the model for an indefinite period, enter inf.
2. Run the model using one of the following options.
Monitor & Tune: To run the model for signal monitoring and parameter tuning, on the Hardware tab, in the Mode section, select Run on board and then click Monitor & Tune to start signal monitoring and parameter tuning.
Wait for the code generation to be completed. Whenever the dialog box appears instructing you to reconnect the flight controller to the serial port, click OK and then reconnect the PX4 Autopilot on the host computer.
The lower left corner of the model window displays status while Simulink prepares, downloads, and runs the model on the hardware.
Connected IO: To run this model in the Connected I/O mode, on the Hardware tab, in the Mode section, select Connected IO and then click Run with IO.
If the Connected IO firmware is not deployed on the hardware, then the dialog box instructing you to reconnect the flight controller to the serial port appears otherwise the dialog box is not displayed. If the dialog box appears, click OK and then reconnect the PX4 Autopilot on the host computer.
3. At each time step, the Read parameter block reads the parameter mentioned in the PX4 Parameter Read block and provides the same as output.
4. Observe the outputs in the Offset-Scaled Gyro Readings Display block.
5. To stop running the model on your hardware, click Stop in the Hardware tab of the Simulink toolstrip.