set
R2026bDescription
Examples
Tune the maximum yaw rate parameter of a Pixhawk® 4 board running PX4® firmware by using the parameter 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. If the remote MAVLink system replies with HEARTBEAT messages, a connection is established.
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 a parameter microservice object.
parameter = mavlinkmicroservice(gcs,"parameter");Obtain the current value of all parameters by using the get
function.
[status,param] = get(parameter,uav)
status = true
param = 10×5 table
param_value param_count param_index param_id param_type
___________ ___________ ___________ ______________ ____________________
0 942 12 SYS_AUTOSTART 6
1 942 22 COM_ARM_WO_GPS 6
300 942 50 COM_RC_LOSS_T 9
15.5 942 88 BAT_LOW_THR 9
12.0 942 105 MPC_VEL_MAX_UP 9
5.0 942 106 MPC_VEL_MAX_DN 9
2.5 942 315 NAV_ACC_RAD 9
200 942 412 MC_YAWRATE_MAX 9
0.5 942 413 MC_PITCHRATE_P 9
0.1 942 418 MC_ROLLRATE_I 9
Obtain the current value of the MC_YAWRATE_MAX parameter. The
output shows that the current maximum yaw rate of the Pixhawk board is 200 degrees per second.
[status,param] = get(parameter,uav,"MC_YAWRATE_MAX")status = true
param = 1×5 table
param_value param_count param_index param_id param_type
___________ ___________ ___________ ______________ ____________________
200 942 412 MC_YAWRATE_MAX 9 Specify a new maximum yaw rate parameter value of 150 degrees per second by using the set function. The function returns the updated parameter value to verify the success of the parameter set operation.
[status,param] = set(parameter,uav,"MC_YAWRATE_MAX",150)status = true
param = 1×5 table
param_value param_count param_index param_id param_type
___________ ___________ ___________ ______________ ____________________
150 942 412 MC_YAWRATE_MAX 9 Input Arguments
Parameter microservice, specified as a parameterMicroservice object.
Remote MAVLink client information, specified as a mavlinkclient object.
Parameter identifier, specified as a string scalar.
Example:
"MAX_YAW_RATE"
Data Types: string
Value to write to the parameter, specified as a numeric scalar.
Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32
Output Arguments
Parameter set status, returned as a 1 or 0 of data type logical.
The value is true when the remote MAVLink client acknowledges the parameter change
without exceeding the inter‑packet timeout and retry settings of the parameter microservice object.
The value is false when the acknowledgment is not received within
the timeout and the request does not complete after the allowed number
of retries.
Data Types: logical
Parameter information, returned as a table containing the updated parameter value and metadata as confirmed by the remote MAVLink client. The table contains these columns:
param_value— Value of parameter, returned as a numeric scalar.param_count— Total number of parameters, returned as a positive integer.param_index— Index of parameter in the parameter list, returned as a nonnegative integer.param_id— Parameter identifier, returned as a string scalar.param_type— Parameter type, returned as one of the values listed in theMAV_PARAM_TYPEenum as an integer.
Data Types: struct
Version History
Introduced in R2026b
See Also
get | heartbeatMicroservice | commandMicroservice | 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)