matlab-connect-mavlink

Establish MAVLink UDP connections between MATLAB and PX4 or ArduPilot autopilots.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-connect-mavlink
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: matlab-connect-mavlink
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/robotics-and-autonomous-systems/matlab-connect-mavlink
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-connect-mavlink

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Connecting MATLAB to a PX4 or ArduPilot flight controller over MAVLink involves a strict protocol sequence that is easy to get wrong: dialect creation, UDP transport setup, heartbeat construction, and client discovery must happen in the correct order, and common mistakes like wrong payload field access or incorrect port usage cause silent failures.

Core Features & Use Cases

  • Correct Connection Sequence: Encodes the exact workflow for creating a MAVLink dialect, configuring the mavlinkio interface with GCS identity, and connecting over UDP with name-value arguments.
  • Heartbeat Management: Covers both auto-discovery (autopilot already broadcasting) and manual initiation (sending heartbeats to a known SITL endpoint) with timer-based 1 Hz heartbeat patterns.
  • Payload and Message Gotchas: Documents critical rules such as accessing fields via msg.Payload.fieldname(:) to preserve wire types and passing the dialect (not the io object) to createmsg.
  • Use Case: You are building a MATLAB ground control station and need to connect to a PX4 SITL instance, exchange heartbeats, discover the autopilot client, and send an arm command.

Quick Start

Connect MATLAB to my PX4 SITL autopilot over MAVLink UDP and set up the GCS heartbeat.

Frequently Asked Questions about matlab-connect-mavlink

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I connect MATLAB to a PX4 autopilot over MAVLink?

Create a dialect with mavlinkdialect("common.xml", 2), build the interface with mavlinkio using SystemID 255 and ComponentID 1, then call connect(mavlink, "UDP", LocalPort=14550). Send a 1 Hz heartbeat and poll listClients until the autopilot appears.

How do I set up a MAVLink heartbeat in MATLAB?

Build a HEARTBEAT message with createmsg(dialect, "HEARTBEAT"), set Payload fields like type to MAV_TYPE_GCS, then use a timer with fixedRate execution at 1 Hz calling sendudpmsg or sendmsg. Always stop and delete the timer before disconnecting.

Why is my MAVLink connection to PX4 SITL not working?

Common causes include using port 14550 as the remote port (it is the GCS local port), calling sendmsg before the client is discovered, or skipping the heartbeat. Use sendudpmsg with the autopilot's actual listening port for pre-discovery communication.

Why does my MAVLink message produce corrupted packets in MATLAB?

Assigning payload fields without (:) indexing replaces the wire type with double, silently corrupting packets. Always write msg.Payload.field(:) = value, and access fields under .Payload rather than at the top level of the message struct.

Which MAVLink dialect should I use for PX4 versus ArduPilot?

Use "common.xml" for both PX4 and ArduPilot since it covers all standard messages. Choose "ardupilotmega.xml" only when you need ArduPilot-specific extension messages, and specify protocol version 2.

When should I not use this MAVLink connection workflow?

Skip it when reading parameters or uploading missions over an existing connection, when working with Simulink MAVLink blocks, or when parsing .ulg log files offline with ulogreader. It targets initial connection setup only.