Main Content

Reading GPS Data over UAVCAN

This example showcases the connectivity with the UAVCAN peripherals connected to the PX4 Autopilot, using UAV Toolbox Support Package for PX4® Autopilots. In this example, the UAVCAN GPS receiver is used as the UAVCAN peripheral.

UAVCAN driver module of PX4 establishes connectivity with the peripheral and the GPS data is published over uORB message. This example uses a pre-defined Simulink model (px4demo_readGPS) that contains the GPS block. The GPS block gets the GPS data by reading the sensor_gps uORB message.

Prerequisites

Required Hardware

To run this example, you will need the following hardware:

Hardware Connection

Connect the UAVCAN GPS module to the CAN1/CAN port of the PX4 Autopilot and power up the PX4 Autopilot.

Task 1 - Enable UAVCAN Module Using QGroundControl

In this task, you will enable the UAVCAN module using the parameter UAVCAN_ENABLE. You can set different values for UAVCAN_ENABLE parameter and their behavior is listed below.

0 - UAVCAN disabled.

1 - Enables support for UAVCAN sensors without dynamic node ID allocation and firmware update.

2 - Enables support for UAVCAN sensors with dynamic node ID allocation and firmware update.

3 - Enables support for UAVCAN sensors and actuators with dynamic node ID allocation and firmware update. Also sets the motor control outputs to UAVCAN.

As this example uses UAVCAN senor, set the UAVCAN_ENABLE parameter value to 2. If you are interfacing an UAVCAN actuator such as ESC, consider setting the UAVCAN_ENABLE parameter value to 3.

Set the UAVCAN_ENABLE parameter value to 2 using QGroundControl as described here.

Note: PX4 CAN Transmit and PX4 CAN Receive blocks cannot be used when UAVCAN is enabled. Disable the UAVCAN before using the PX4 CAN Transmit and Receive blocks.

Task 2 - Signal Monitoring and Parameter Tuning

In this task, you will configure and run the pre-defined Simulink model (px4demo_readGPS) model in Monitor and Tune action to verify the GPS data. This model contains the GPS block that reads sensor_gps uORB topic. After you verify the GPS data, you deploy the model to the PX4 hardware board.

1. Open the px4demo_readGPS model.

In the example model, the GPS block is used to read GPS values. This block accepts signals from the sensor_gps uORB message, and outputs the required values.

2. Double-click the GPS block. By default, signals corresponding to Latitude, Longitude, and Altitude(MSL) are selected as outputs. You can add the other signals as output by selecting the corresponding checkboxes.

Note: The Status output indicates if the uORB message was received during a previous time step or not. A value of 0 indicates that the uORB data at the output is the latest, and a value of 1 indicates that the uORB data was received during the previous time step. This output can be used to trigger subsystems for processing new messages received in the uORB network.

3. In the Modeling tab, click Model Settings.

4. In the Configuration Parameters dialog box, navigate to the Hardware Implementation pane:

  • Set the Hardware board to the same PX4 hardware board that you selected during Hardware Setup screens.

  • In the Target Hardware Resources section, set the Build options to Build, load and run to automatically download the generated binary file on to the connected Pixhawk Series flight controller.

  • Enter the serial port of the host computer to which the Pixhawk Series flight controller is connected, in the Serial port for firmware upload field.

  • In the External mode pane, select the option Use the same host serial port for External mode as used for firmware upload.

5. Navigate to Solver pane and select the option Treat each discrete rate as a separate task. Click OK.

6. In the Simulation tab, set the Stop time to inf.

7. Connect the USB cable from the PX4 flight controller to the host computer.

8. On the Hardware tab, in the Mode section, select Run on board and then click Monitor & Tune to start signal monitoring and parameter tuning.

9. Verify the output GPS values in the Scope display. The values correspond to the current GPS position of the PX4 flight controller.

10. Stop the Monitor and Tune operation by clicking Stop in the Hardware tab.

Deploy Simulink Model

To deploy the Simulink model, on the Hardware tab, in the Mode section, select Run on board and then click Build, Deploy & Start. The model is deployed to the PX4 hardware board.