This example shows you how to read the PX4 system parameters using UAV Toolbox Support Package for PX4 Autopilots.
In this example, the pre-configured
PX4 Parameter Read model, 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.
In this example, you will learn how to create and deploy a Simulink model to read PX4 system parameters.
If you are new to Simulink, watch the Simulink Quick Start video.
Perform the initial setup and configuration tasks of the support package using Hardware Setup screens.
To run this example, you will need the following hardware:
Pixhawk Series flight controller
Micro USB type-B cable
Micro-SD card (already used during the initial Hardware Setup)
1. Connect your Pixhawk board to the host computer using the USB cable.
2. Open the
PX4 Parameter Read 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.
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. In the Hardware tab, 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, ensure that you click OK on the dialog box within 5 seconds after reconnecting the flight controller.
The lower left corner of the model window displays status while Simulink prepares, downloads, and runs the model on the hardware.
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.