Contenido principal

get

R2026b

Read parameter value from remote MAVLink client

Since R2026b

    Description

    [status,params] = get(parameter,mavlinkclient) reads all parameter values from the remote MAVLink client mavlinkclient. The function returns the status of the parameter get operation status and the parameter information params.

    [status,params] = get(parameter,mavlinkclient,paramID) reads the value of the specified parameter paramID.

    example

    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          

    Input Arguments

    collapse all

    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

    Output Arguments

    collapse all

    Parameter request status, returned as a 1 or 0 of data type logical. The value is true when every required parameter message is received without exceeding the inter‑packet timeout and retry settings of the parameter microservice object. The value is false when the period between consecutive parameter messages exceeds the timeout and the request does not complete after the allowed number of retries.

    Data Types: logical

    Parameter information, returned as a table in which each row corresponds to one parameter sent 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 the MAV_PARAM_TYPE enum as an integer.

    Tip

    To view the available MAV_PARAM_TYPE enum values, use the enuminfo function:

    info = enuminfo(dialect,"MAV_PARAM_TYPE");
    info.Entries{:}
    where dialect is the MAVLink dialect object that you specify when you create the local MAVLink client.

    Data Types: struct

    Version History

    Introduced in R2026b