send
R2026bDescription
[
sends the MAVLink command message status,ack] = send(command,mavlinkclient,commandMsg)commandMsg to the remote MAVLink client
mavlinkclient. The function returns the command send status and the
acknowledgment message returned by the remote MAVLink client.
Examples
Send a waypoint command to a Pixhawk® 4 board running PX4® firmware by using the command 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 the waypoint command message structure by using the createcmd function.
cmdMsg = createcmd(dialect,"INT","MAV_CMD_NAV_WAYPOINT")
cmdMsg =
struct with fields:
MsgID: 75
Payload: [1×1 struct]
Specify these parameters of the waypoint command message:
Acceptance radius — 2 meters
Latitude — 42.2831 degrees
Longitude — –71.3468 degrees
Altitude — 50 meters
For more information on the waypoint command parameters, see the MAV_CMD_NAV_WAYPOINT section of the MAVLink documentation.
cmdMsg.Payload.param2(:) = 2.0; cmdMsg.Payload.param5(:) = 42.2831; cmdMsg.Payload.param6(:) = -71.3468; cmdMsg.Payload.param7(:) = 50.0;
Create a command microservice object.
command = mavlinkmicroservice(gcs,"command");Send the command message to the Pixhawk board by using the send function. The function returns the status and the acknowledgement message sent by the Pixhawk board.
[status,ack] = send(command,uav,cmdMsg)
status = true
ack =
struct with fields:
command: 16
result: 0
progress: 255
result_param2: 0
target_system: 1
target_component: 1
Input Arguments
Command microservice, specified as a commandMicroservice object.
Remote MAVLink client information, specified as a mavlinkclient object.
MAVLink command message to send, specified as a structure with these fields:
MsgID— Message identifier, specified as75forCOMMAND_INTcommands, or76forCOMMAND_LONGcommands.Payload— Structure with fields corresponding to the specific command definition.
Tip
Create the command message using the createcmd
object function of the MAVLink dialect object.
Data Types: struct
Output Arguments
Command send status, returned as a 1 or 0 of
data type logical. The value is 1
(true) when the local MAVLink client receives the acknowledgement
message without exceeding the maximum time and number of retries.
Data Types: logical
Command acknowledgement message, returned as a structure with these fields:
command— Command identifier, returned as an integer corresponding to a value in theMAV_CMDenum.result— Command result, returned as an integer corresponding to a value in theMAV_RESULTenum.progress— Progress percentage when the result isMAV_RESULT_IN_PROGRESS. Values range from 0 to 100, or 255 if the progress is unknown.result_param2— Additional result information.target_system— Remote MAVLink system ID, returned as an integer in the range[1, 255].target_component— Remote MAVLink component ID, returned as an integer in the range[0, 255].
Tip
To view the available MAV_CMD enum values, use the enuminfo
function. For example, to find the values of the MAV_CMD enum:
info = enuminfo(dialect,"MAV_CMD");
info.Entries{:}dialect is the MAVLink dialect object
that you specify when you create the local MAVLink client.Version History
Introduced in R2026b
See Also
heartbeatMicroservice | parameterMicroservice | missionMicroservice | ftpMicroservice
External Websites
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)