Question
Hello, I'm searching if there is a way for interact and send commands to my quadcopter with MATLAB, instead of a Ground Control Station. I tried with MATMAV but seems not working. I also tried with MAVLink Support and also this seems not working for send command to my quadcopter. This is my code: dialect = mavlinkdialect('common.xml'); mavlink = mavlinkio(dialect); connect(mavlink, 'UDP', 'LocalPort', 14550); %% client = mavlinkclient(mavlink, 1, 1) % specify client (1 client = 1 drone) connectionList = listConnections(mavlink) clientsList = listClients(mavlink) topicsList = listTopics(mavlink) %% message_num = 400; cmdMsg = createcmd(dialect, 'int', message_num) cmdMsg num2enum(dialect,"MAV_CMD", message_num) %% sendudpmsg(mavlink, cmdMsg, '0.0.0.0', 14550) There are other approaches to send commands to quadcopter through MATLAB?
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 20, 2026
First the mavlink message needs to be refined:
For arm UAV:
cmd = dialect.createcmd("LONG", "MAV_CMD_COMPONENT_ARM_DISARM");
cmd.Payload.target_component(:) = 1;
cmd.Payload.target_system(:) = 1;
cmd.Payload.param1(:) = 1;
For disarm UAV
cmd = dialect.createcmd("LONG", "MAV_CMD_COMPONENT_ARM_DISARM");
cmd.Payload.target_component(:) = 1;
cmd.Payload.target_system(:) = 1;
cmd.Payload.param1(:) = 0;
Also since you are emulating a ground control station in MATLAB, you will need to keep sending out heartbeat from MATLAB to help the UAV find it:
heartbeat = createmsg(dialect,"HEARTBEAT");
heartbeat.Payload.type(:) = enum2num(obj.Dialect,'MAV_TYPE', 'MAV_TYPE_GCS');
heartbeat.Payload.autopilot(:) = enum2num(obj.Dialect,'MAV_AUTOPILOT', 'MAV_AUTOPILOT_INVALID');
heartbeat.Payload.system_status(:) = enum2num(obj.Dialect,'MAV_STATE',"MAV_STATE_STANDBY");
heartbeatTimer = timer;
heartbeatTimer.ExecutionMode = 'fixedRate';
heartbeatTimer.TimerFcn = @(~,~)sendmsg(obj.IO,heartbeat);
start(heartbeatTimer);
If UAV is also broadcasting its heartbeat, your listClient call should show UAV client as well, then you can send message to the uav client:
sendmsg(mavlink, client);
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related mavlink Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →