Send and Receive MAVLink Packets on Jetson Boards
This example shows how to use MATLAB® Coder™ Support Package for NVIDIA® Jetson® and NVIDIA DRIVE® to send and receive MAVLink packets on a Jetson board via serial from a Pixhawk board.
Using this example, you can create and deploy a Simulink® model that can:
Read the heartbeat of the Pixhawk board.
Read the attitude of the Pixhawk board.
Send MAVLink heartbeat to the host and Pixhawk board.
Target Board Requirements
Pixhawk board. Update the firmware on the Pixhawk board to the latest PX4 stack using QGroundControl (QGC).
Micro USB type-B cable.
Pixhawk telemetry cable (Optional).
NVIDIA Jetson Nano embedded platform.
Ethernet crossover cable to connect the target board and host PC (if you cannot connect the target board to a local network).
Tools, libraries, and environment variables on the target board for the compilers and libraries. For more information, see Install and Setup Prerequisites for NVIDIA Boards.
Power the Pixhawk using the Jetson board USB.
Optionally, connect the Tx and Rx pins of TELEM 1 Port to the Rx and Tx pins on the Jetson board. The MAVLink packets are sent both on the USB and TELEM Port of the Pixhawk board.
Simulink Models for MAVLink Communication
This example uses a preconfigured
jetsoncpu_pixhawk_interface model to send and receive MAVLink packets from the Pixhawk board.
jetsoncpu_pixhawk_interface_host model reads the MAVLink packets send from the Jetson board on the host.
Configure Board Parameters of the Model
To set up a live connection to the Jetson board, specify the device address, username, and password of the Jetson Nano board.
Open the Configuration Parameters dialog box and navigate to the Hardware Implementation pane.
Select your target hardware from the Hardware board drop-down list.
Set the Hardware board to NVIDIA Jetson
In the Target Hardware Resources section, open the Board Parameters pane and enter the device address, username, and password for the Jetson board.
Click Apply and then OK to close the dialog box.
In the Simulink model, double-click the following blocks and verify that the specified parameter values are the same as shown below:
Serial Readblock in the Jetson Pixhawk Interface Target model.
If you want to read MAVLink packets coming from the USB port, set the serial port to /dev/ttyACM0.
If you want to read MAVLink packets coming from the TELEM port, set the serial port to /dev/ttyTHS1. Ensure that the baudrate is set to 57600.
MAVLink Deserializerblock in the Jetson Pixhawk Interface Target model.
MAVLink Blank Messageblocks in the Jetson Pixhawk Interface Target model.
UDP Sendblock in the Jetson Pixhawk Interface Target model.
On the target
UDP Sendblock, the remote IP port has to match the local IP port of the host model
UDP Receiveblock. Ensure that the remote IP address is the IP address of the host computer.
Since the MAVLink packets sent to the Pixhawk board cannot be visualized, they are sent to the host using the UDP block, which can be seen in the Pixhawk Interface Host model.
Serial Writeblock in Jetson Pixhawk Interface Target model.
On the target, the port and baudrate value of the
Serial Writeblock should be the same as the
Serial Sendblock in the Jetson Pixhawk Interface Host model.
On the host
UDP Receiveblock, ensure that the Local address is the IP address of the host computer and the local port number matches the remote port set in the
UDP Sendblock in the target model.
MAVLink Deserializerblock in the Jetson Pixhawk Interface Host model.
Monitor and Tune Model
When you perform monitor and tune the Jetson Pixhawk Interface Target model, the host computer communicates with the target on which the generated executable runs.
To monitor and tune the model, open the Hardware tab and click Monitor & Tune. You can observe from the Diagnostic Viewer that the code is generated for the model and the host connects to the target after loading the generated executable.
While the model is running, observe the Roll, Pitch, and Yaw values in the Display blocks.
Change the orientation of the Pixhawk board and observe the changes in the Roll, Pitch and Yaw values. Observe the changing sequence of the heartbeat messages.
While the target model is running in external mode, simulate the Jetson Pixhawk Interface Host model
Open the Simulation tab and then select Simulation Pacing.
Specify the Stop Time as Inf.
Observe the changing sequence of the heartbeat messages.
To stop external mode, go to the Hardware tab and click the Stop button to terminate external mode simulation.
On the Simulation tab, click Stop button to terminate the simulation.
Other Things to Try
Read other MAVLink messages sent from the Pixhawk board.