This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

latestmsgs

Received messages from MAVLink subscriber

Syntax

msgs = latestmsgs(sub,count)

Description

example

msgs = latestmsgs(sub,count) returns the latest received messages for the mavlinksub object. The messages are in a structure array in reverse-chronological order with the most recent being first. If count is larger than the number of stored messages, the structure array contains only the number of stored messages.

Note

This function requires you to install the UAV Library for Robotics System Toolbox™. To install add-ons, use roboticsAddons and select the desired add-on.

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")
mavlink = 
  mavlinkio with properties:

        Dialect: [1x1 mavlinkdialect]
    LocalClient: [1x1 struct]

connect(mavlink,"UDP")
ans = 
"Connection1"

Get the client information.

client = mavlinkclient(mavlink,1,1);

Subscribe to the "HEARTBEAT" topic.

heartbeat = mavlinksub(mavlink,client,'HEARTBEAT');

Get the latest message. You must wait for a message to be received. Currently, no heartbeat message has been received on the mavlink object.

latestmsgs(heartbeat,1)
ans = 

  1x0 empty struct array with fields:

    MsgID
    SystemID
    ComponentID
    Payload
    Seq

Disconnect from client.

disconnect(mavlink)

Input Arguments

collapse all

MAVLink subscriber, specified as a mavlinksub object.

Number of messages, specified as a positive integer. If count is larger than the number of stored messages, the structure array is padded with empty structs.

Output Arguments

collapse all

Recently received messages, returned as a structure array. Each structure has the fields:

  • MsgID

  • SystemID

  • ComponentID

  • Payload

The Payload is a structure defined by the message definition for the MAVLink dialect.

If count is larger than the number of stored messages, the structure array contains only the number of stored messages..

Introduced in R2019a