connect

Connect to MAVLink clients through UDP port

Description

example

connectionName = connect(mavlink,"UDP") connects to the mavlinkio client through a UDP port.

connectionName = connect(___,Name,Value) additionally specifies arguments using name-value pairs.

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Examples

collapse all

NOTE: This example requires you to install the UAV Library for Robotics System Toolbox®. Call roboticsAddons to open the Add-ons Explorer and install the library.

Connect to a MAVLink client.

mavlink = mavlinkio("common.xml");
connect(mavlink,"UDP");

Create the object for storing the client information. Specify the system and component ID.

client = mavlinkclient(mavlink,1,1)
client = 
  mavlinkclient with properties:

         SystemID: 1
      ComponentID: 1
    ComponentType: "Unknown"
    AutopilotType: "Unknown"

Disconnect from client.

disconnect(mavlink)

This example shows how to connect to MAVLink clients, inspect the list of topics, connections, and clients, and send messages through UDP ports using the MAVLink communication protocol.

NOTE: This example requires you to install the UAV Library for Robotics System Toolbox®. Call roboticsAddons to open the Add-ons Explorer and install the library.

Connect to a MAVLink client using the "common.xml" dialect. This local client communicates with any other clients through a UDP port.

dialect = mavlinkdialect("common.xml");
mavlink = mavlinkio(dialect);
connect(mavlink,"UDP")
ans = 
"Connection1"

You can list all the active clients, connections, and topics for the MAVLink connection. Currently, there is only one client connection and no topics have received messages.

listClients(mavlink)
ans=1×4 table
    SystemID    ComponentID    ComponentType          AutopilotType     
    ________    ___________    ______________    _______________________

      255            1         "MAV_TYPE_GCS"    "MAV_AUTOPILOT_INVALID"

listConnections(mavlink)
ans=1×2 table
    ConnectionName      ConnectionInfo   
    ______________    ___________________

    "Connection1"     "UDP@0.0.0.0:57500"

listTopics(mavlink)
ans =

  0x5 empty table

Create a subscriber for receiving messages on the client. This subscriber listens for the "HEARTBEAT" message topic with ID equal to 0.

sub = mavlinksub(mavlink,0);

Create a "HEARTBEAT" message using the mavlinkdialect object. Specify payload information and send the message over the MAVLink client.

msg = createmsg(dialect,"HEARTBEAT");
msg.Payload.type(:) = enum2num(dialect,'MAV_TYPE','MAV_TYPE_QUADROTOR');
sendmsg(mavlink,msg)

Disconnect from the client.

disconnect(mavlink)

Input Arguments

collapse all

MAVLink client connection, specified as a mavlinkio object.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'LocalPort',12345

Identifying connection name, specified as the comma-separated pair consisting of 'ConnectionName' and a string scalar. The default connection name is "Connection#".

Data Types: string

Local port for UDP connection, specified as a numeric scalar. A value of 0 binds to a random open port.

Data Types: double

Output Arguments

collapse all

Identifying connection name, specified as a string scalar. The default connection name is "Connection#", where # is an integer starting at 1 and increases with each new connection created.

Data Types: string

Introduced in R2019a