Main Content

latestmsgs

Received messages from MAVLink subscriber

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.

Examples

collapse all

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 structures.

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..

Version History

Introduced in R2019a