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.
Prerequisites
Target Board Requirements
Pixhawk board. Update the firmware on the Pixhawk board to the latest PX4 stack using QGroundControl documentation.
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.
Hardware Connections
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.
open_system('jetsoncpu_pixhawk_interface')
The jetsoncpu_pixhawk_interface_host
model reads the MAVLink packets send from the Jetson board on the host.
open_system('jetsoncpu_pixhawk_interface_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.
Configure Blocks
In the Simulink model, double-click the following blocks and verify that the specified parameter values are the same as shown below:
Serial Read
block 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 Deserializer
block in the Jetson Pixhawk Interface Target model.
MAVLink Serializer
andMAVLink Blank Message
blocks in the Jetson Pixhawk Interface Target model.
UDP Send
block in the Jetson Pixhawk Interface Target model.On the target
UDP Send
block, the remote IP port has to match the local IP port of the host modelUDP Receive
block. 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 Write
block in Jetson Pixhawk Interface Target model.On the target, the port and baudrate value of the
Serial Write
block should be the same as theSerial Read
block.
Serial Send
block in the Jetson Pixhawk Interface Host model.On the host
UDP Receive
block, ensure that the Local address is the IP address of the host computer and the local port number matches the remote port set in theUDP Send
block in the target model.
MAVLink Deserializer
block 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.