主要内容

missionMicroservice

R2026b

MAVLink mission microservice object

Since R2026b

    Description

    The missionMicroservice represents the MAVLink Mission microservice. This object uses MAVLink mission protocol messages to download missions from, and upload missions to a remote MAVLink client. Use the object functions to download and upload missions, or to configure timeout and retry behavior for mission operations.

    Note

    The missionMicroservice object requires PX4 version 1.5.1 or later. If you use ArduPilot, the object requires ArduPilot Copter 3.4 or later, or ArduPilot Plane 3.5 or later.

    Creation

    To create a missionMicroservice object, use the mavlinkmicroservice function and specify the microservice type as "mission":

    mission = mavlinkmicroservice(mavlinkio,"mission").

    Properties

    expand all

    Maximum time, in seconds, that the missionMicroservice object waits for required MAVLink messages before retrying a mission upload or download operation, specified as a positive scalar. Required messages include acknowledgments and mission items. To change this value, use the setTimeout function.

    Number of retry attempts for mission upload or download operations that do not complete in the timeout period, specified as a nonnegative integer. To change this value, use the setRetry function.

    Object Functions

    uploadUpload mission to remote MAVLink client
    downloadDownload mission from remote MAVLink client
    setTimeoutSet microservice timeout value
    setRetrySet microservice retry count

    Examples

    collapse all

    Upload a mission to a Pixhawk® 4 board running PX4® firmware by using the mission microservice.

    Create a mavlinkdialect object using the common.xml file.

    dialect = mavlinkdialect("common.xml");

    Create a local MAVLink client by using the mavlinkio object.

    gcs = mavlinkio(dialect);

    Store the remote MAVLink client information by using the mavlinkclient object. This Pixhawk board has a system ID of 1 and a component ID of 1.

    uav = mavlinkclient(gcs,1,1);

    Connect the local MAVLink client to the same serial port as the Pixhawk board by using the connect function. This Pixhawk board uses the COM5 port.

    connect(gcs,"Serial",SerialPort="COM5");

    Create a heartbeat microservice object.

    heartbeat = mavlinkmicroservice(gcs,"heartbeat");

    Start sending the HEARTBEAT messages to the Pixhawk board by using the start function.

    start(heartbeat,uav,"Serial",SerialPort="COM5")

    If the Pixhawk board replies with HEARTBEAT messages, a connection is established.

    Verify that the connection has been established by using the listClients function.

    listClients(gcs)
    ans = 2×4 table
        SystemID    ComponentID       ComponentType             AutopilotType     
        ________    ___________    ____________________    _______________________
    
          255            1            "MAV_TYPE_GCS"        "MAV_AUTOPILOT_INVALID"
           1             1         "MAV_TYPE_QUADROTOR"       "MAV_AUTOPILOT_PX4"

    Create a mission microservice object.

    mission = mavlinkmicroservice(gcs,"mission");

    Upload the mission SampleMission.plan to the Pixhawk board by using the upload function. The function returns the upload status and acknowledgement message.

    [status,ack] = upload(mission,uav,"SampleMission.plan")
    status = true
    ack = 
      struct with fields:
    
           target_system : 255
        target_component : 1
                    type : 0
            mission_type : 0
         

    Download a mission from a Pixhawk 4 board running PX4 firmware by using the mission microservice.

    Create a mavlinkdialect object using the common.xml file.

    dialect = mavlinkdialect("common.xml");

    Create a local MAVLink client by using the mavlinkio object.

    gcs = mavlinkio(dialect);

    Store the remote MAVLink client information by using the mavlinkclient object. This Pixhawk board has a system ID of 1 and a component ID of 1.

    uav = mavlinkclient(gcs,1,1);

    Connect the local MAVLink client to the same serial port as the Pixhawk board by using the connect function. This Pixhawk board uses the COM5 port.

    connect(gcs,"Serial",SerialPort="COM5");

    Create a heartbeat microservice object.

    heartbeat = mavlinkmicroservice(gcs,"heartbeat");

    Start sending the HEARTBEAT messages to the Pixhawk board by using the start function.

    start(heartbeat,uav,"Serial",SerialPort="COM5")

    If the Pixhawk board replies with HEARTBEAT messages, a connection is established.

    Verify that the connection has been established by using the listClients function.

    listClients(gcs)
    ans = 2×4 table
        SystemID    ComponentID       ComponentType             AutopilotType     
        ________    ___________    ____________________    _______________________
    
          255            1            "MAV_TYPE_GCS"        "MAV_AUTOPILOT_INVALID"
           1             1         "MAV_TYPE_QUADROTOR"       "MAV_AUTOPILOT_PX4"

    Create a mission microservice object.

    mission = mavlinkmicroservice(gcs,"mission");

    Download the mission stored in the Pixhawk board by using the download function. This mission contains four waypoints.

    [status,missionData] = download(mission,uav)
    status = true
    missionData = 4×15 table
      param1  param2  param3  param4      x           y      z   seq  command  target_system  target_component  frame  current  autocontinue  mission_type
      ______  ______  ______  ______  _________  __________  __  ___  _______  _____________  ________________  _____  _______  ____________  ____________
        0       0       0       NaN   422315437  -717016359  10   0      16         255              1            6      0           1             0      
        0       0       0       NaN   422327909  -716999085  10   1      16         255              1            6      0           1             0      
        0       0       0       NaN   422324334  -716981812  10   2      16         255              1            6      0           1             0      
        0       0       0       NaN   422309320  -716974302  10   3      16         255              1            6      0           1             0      

    Version History

    Introduced in R2026b