Main Content

parameterMicroservice

R2026b

MAVLink Parameter microservice

Since R2026b

    Description

    The parameterMicroservice represents the MAVLink Parameter microservice. This object uses MAVLink parameter protocol messages to read parameters from, and write parameters to a remote MAVLink client. Use the object functions to read and write parameters, or to configure timeout and retry behavior for parameter operations.

    Creation

    To create a parameterMicroservice object, use the mavlinkmicroservice function and specify the microservice type as "parameter":

    parameter = mavlinkmicroservice(mavlinkio,"parameter")

    Properties

    expand all

    Parameter operations timeout, represented as a positive scalar. This property determines the maximum time, in seconds, that the parameterMicroservice object waits for required MAVLink messages, such as acknowledgments or parameter values, before retrying a parameter get or set operation. This property is read-only. To set this property, use the setTimeout function.

    Parameter operations retry count, specified as a nonnegative integer. This property determines the number of retry attempts for parameter get or set operations that do not complete within the timeout period. This property is read-only. To set this property, use the setRetry function.

    Object Functions

    setWrite parameter value to remote MAVLink client
    getRead parameter value from remote MAVLink client
    setTimeoutSet microservice timeout value
    setRetrySet microservice retry count

    Examples

    collapse all

    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          

    Version History

    Introduced in R2026b