Create a MAVLink dialect object using the common.xml file.
Create a local MAVLink client object that represents a simulated UAV. Specify these options:
MAVLink message definition — dialect
MAVLink system ID — 1
MAVLink component ID — 1
MAVLink component type — MAV_TYPE_QUADROTOR
MAVLink autopilot type — MAV_AUTOPILOT_GENERIC
Connect the local simulated UAV to a random open UDP port by using the connect object function.
List all MAVLink clients that are connected to the simulated UAV by using the listClients object function. The output contains only the simulated UAV, which shows that no other MAVLink client is connected to the simulated UAV.
ans=1×4 table
SystemID ComponentID ComponentType AutopilotType
________ ___________ ____________________ _______________________
1 1 "MAV_TYPE_QUADROTOR" "MAV_AUTOPILOT_GENERIC"
Launch QGroundControl.
To establish a connection with QGroundControl, first create a blank heartbeat message by using the createmsg object function.
Assign the component type and autopilot type of the simulated UAV, and the system status, to the heartbeat message fields.
Create a timer callback function. Configure the callback function to send the heartbeat message to QGroundControl through a UDP connection using the sendudpmsg object function.
Create a timer object with a fixed rate execution mode, period of 1 second, and the timer callback function.
Start the timer object. The local simulated UAV broadcasts the heartbeat message at 1 Hz, and QGroundControl connects to the simulated UAV.
List the MAVLink clients again to verify that QGroundControl is now connected. The output shows that QGroundControl is a connected MAVLink client with a component type of MAV_TYPE_GCS.
Once you have finished running the example, stop and delete the timer object to end the connection.