The heartbeat protocol is used to advertise the existence of a system on the MAVLink network, along with its system and component id, vehicle type, flight stack, component type, and flight mode.
The heartbeat allows other components to:
- discover systems that are connected to the network and infer when they have disconnected. A system is considered to be connected to the network if its HEARTBEAT message is regularly received, and disconnected if a number of expected messages are not received.
- handle other messages from the system appropriately, based on system type and other properties (e.g. layout a GCS interface based on vehicle type).
- route messages to systems on different interfaces.
|HEARTBEAT||Broadcast that a system is present and responding, along with its type and other properties.|
|MAV_TYPE||Type of the system (quadrotor, helicopter, etc.). Components use the same type as their associated system.|
|MAV_AUTOPILOT||Autopilot type / class.|
|MAV_MODE_FLAG||System mode bitmap.|
|MAV_STATE||System status flag.|
Components must regularly broadcast their
HEARTBEAT and monitor for heartbeats from other components/systems.
The rate at which the
HEARTBEAT message must be broadcast, and how many messages may be "missed" before a system is considered to have timed out/disconnected from the network, depends on the channel (it is not defined by MAVLink). On RF telemetry links, components typically publish their heartbeat at 1 Hz and consider another system to have disconnected if four or five messages are not received.
A system may choose not to broadcast information if it does not detect another system, and it will continue to send messages to a system while it is receiving heartbeats. Therefore it is important that systems:
- broadcast a heartbeat even when not commanding the remote system.
- do not broadcast a heartbeat when they are in a faulted state (i.e. do not publish a heartbeat from a separate thread that is unaware of the state of the rest of the component).
HEARTBEAT is also used by GCS (or Developer API) to determine if can connect to a vehicle in order to collect telemetry and send missions/commands.
For example, QGroundControl will only connect to a vehicle system (i.e. not another GCS, gimbal, or onboard controller), and also checks that it has a non-zero system ID before displaying the vehicle connected message. QGC also uses the specific type of vehicle and other heartbeat information to control layout of the GUI.
The specific code for connecting to QGroundControl can be found in MultiVehicleManager.cc (see