Contenido principal

stop

R2026b

Stop sending HEARTBEAT messages

Since R2026b

    Description

    stop(heartbeat,mavlinkclient) stops sending HEARTBEAT messages from the heartbeat microservice heartbeat to the remote MAVLink client mavlinkclient.

    example

    Examples

    collapse all

    Connect a local MAVLink client to a serial port and establish communication with a Pixhawk® 4 board running PX4® firmware by exchanging heartbeat messages.

    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 code stores information for a Pixhawk board with a system ID of 1 and a component ID of 1.

    uav = mavlinkclient(gcs,1,1)
    uav = 
      mavlinkclient with properties:
    
             SystemID: 1
          ComponentID: 1
        ComponentType: "Unknown"
        AutopilotType: "Unknown"

    Connect the local MAVLink client to the same serial port as the Pixhawk board by using the connect function. In this code, the Pixhawk board uses the "COM5" port.

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

    Create a heartbeat microservice object.

    heartbeat = mavlinkmicroservice(gcs,"heartbeat");

    Start sending 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, the local MAVLink client establishes a connection to it.

    Verify that a connection has been established by using the listClients function. Note that the heartbeat messages include the ComponentType and AutopilotType information of the Pixhawk board.

    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"

    Verify that the ComponentType and AutopilotType properties of the mavlinkclient object have been automatically updated to match the heartbeat message values.

    uav
    uav = 
      mavlinkclient with properties:
    
             SystemID: 1
          ComponentID: 1
        ComponentType: "MAV_TYPE_QUADROTOR"
        AutopilotType: "MAV_AUTOPILOT_PX4"

    To stop the connection, first stop the heartbeat message stream.

    stop(heartbeat,uav)

    Then, disconnect the local MAVLink client from the serial port.

    disconnect(gcs)

    Input Arguments

    collapse all

    Heartbeat microservice, specified as a heartbeatMicroservice object.

    Remote MAVLink client information, specified as a mavlinkclient object. This argument specifies the MAVLink client to which to stop sending HEARTBEAT messages from the heartbeat microservice heartbeat.

    Version History

    Introduced in R2026b