Main Content

rosparam

Access ROS parameter server values

Since R2019b

Description

list = rosparam("list") returns the list of all ROS parameter names from the ROS master.

Simplified form: rosparam list

list = rosparam("list",namespace) returns the list of all parameter names under the specified ROS namespace.

Simplified form: rosparam list namespace

example

pvalOut = rosparam("get",pname) retrieves the value of the specified parameter.

Simplified form: rosparam get pname

pvalOut = rosparam("get",namespace) retrieves the values of all parameters under the specified namespace as a structure.

Simplified form: rosparam get namespace

rosparam("set",pname,pval) sets a value for a specified parameter name. If the parameter name does not exist, the function adds a new parameter in the parameter tree.

Simplified form: rosparam set pname pval

See Limitations for limitations on pval.

rosparam("delete",pname) deletes a parameter from the parameter tree. If the parameter does not exist, the function displays an error.

Simplified form: rosparam delete pname

rosparam("delete",namespace) deletes all parameters under the given namespace from the parameter tree.

Simplified form: rosparam delete namespace

example

ptree = rosparam creates a parameter tree object, ptree. After ptree is created, the connection to the parameter server remains persistent until the object is deleted or the ROS master becomes unavailable.

A ROS parameter tree communicates with the ROS parameter server. The ROS parameter server can store strings, integers, doubles, Booleans and cell arrays. The parameters are accessible by every node in the ROS network. Use the parameters to store static data such as configuration parameters. Use the get, set, has, search, and del functions to manipulate and view parameter values.

The following ROS data types are supported as values of parameters. For each ROS data type, the corresponding MATLAB® data type is also listed.

  • 32-bit integer — int32

  • Boolean — logical

  • double — double

  • string — character vector (char)

  • list — cell array (cell)

  • dictionary — structure (struct)

Examples

collapse all

Connect to a ROS network to set and get ROS parameter values on the ROS parameter tree. You can get lists of parameters in their given namespaces as well. This example uses the simplified form that mimics the ROS command-line interface.

Connect to a ROS network.

rosinit
Launching ROS Core...
.Done in 1.5789 seconds.
Initializing ROS master on http://172.29.210.94:50055.
Initializing global node /matlab_global_node_94934 with NodeURI http://dcc912069glnxa64:41073/ and MasterURI http://localhost:50055.

Set parameter values.

rosparam set /string_param 'param_value'
rosparam set /double_param 1.2

To set a list parameter, use the functional form.

rosparam('set', '/list_param', {int32(5), 124.1, -20, 'some_string'});

Get the list of parameters using the command-line form.

rosparam list
/double_param
/list_param  
/string_param

List parameters in a specific namespace.

rosparam list /double
/double_param

Get the value of a specific parameter.

rosparam get /list_param
{5, 124.1, -20, some_string}

Delete a parameter. List the parameters to verify it was deleted.

rosparam delete /double_param
rosparam list
/list_param  
/string_param

Shut down the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_94934 with NodeURI http://dcc912069glnxa64:41073/ and MasterURI http://localhost:50055.
Shutting down ROS master on http://172.29.210.94:50055.

Connect to the ROS network. ROS parameters should already be available on the ROS master.

rosinit('192.168.17.128')
Initializing global node /matlab_global_node_91663 with NodeURI http://192.168.17.1:52951/

Create a ParameterTree object using rosparam.

ptree = rosparam;

List the available parameters on the ROS master.

ptree.AvailableParameters
ans = 33×1 cell array
    {'/bumper2pointcloud/pointcloud_radius'         }
    {'/camera/imager_rate'                          }
    {'/camera/rgb/image_raw/compressed/format'      }
    {'/camera/rgb/image_raw/compressed/jpeg_quality'}
    {'/camera/rgb/image_raw/compressed/png_level'   }
    {'/cmd_vel_mux/yaml_cfg_file'                   }
    {'/depthimage_to_laserscan/output_frame_id'     }
    {'/depthimage_to_laserscan/range_max'           }
    {'/depthimage_to_laserscan/range_min'           }
    {'/depthimage_to_laserscan/scan_height'         }
    {'/depthimage_to_laserscan/scan_time'           }
    {'/gazebo/auto_disable_bodies'                  }
    {'/gazebo/cfm'                                  }
    {'/gazebo/contact_max_correcting_vel'           }
    {'/gazebo/contact_surface_layer'                }
    {'/gazebo/erp'                                  }
    {'/gazebo/gravity_x'                            }
    {'/gazebo/gravity_y'                            }
    {'/gazebo/gravity_z'                            }
    {'/gazebo/max_contacts'                         }
    {'/gazebo/max_update_rate'                      }
    {'/gazebo/sor_pgs_iters'                        }
    {'/gazebo/sor_pgs_precon_iters'                 }
    {'/gazebo/sor_pgs_rms_error_tol'                }
    {'/gazebo/sor_pgs_w'                            }
    {'/gazebo/time_step'                            }
    {'/robot_description'                           }
    {'/robot_state_publisher/publish_frequency'     }
    {'/rosdistro'                                   }
    {'/roslaunch/uris/host_192_168_17_128__34863'   }
    {'/rosversion'                                  }
    {'/run_id'                                      }
    {'/use_sim_time'                                }

Shut down the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_91663 with NodeURI http://192.168.17.1:52951/

Use structures to specify a dictionary of ROS parameters under a specific namespace.

Connect to a ROS network.

rosinit
Launching ROS Core...
Done in 0.55082 seconds.
Initializing ROS master on http://172.29.194.91:52656.
Initializing global node /matlab_global_node_70463 with NodeURI http://dcc365816glnxa64:39751/ and MasterURI http://localhost:52656.

Create a dictionary of parameter values. This dictionary contains the information relevant to an image. Display the structure to verify values.

image = imread('peppers.png');

pval.ImageWidth = size(image,1);
pval.ImageHeight = size(image,2);
pval.ImageTitle = 'peppers.png';
disp(pval)
     ImageWidth: 384
    ImageHeight: 512
     ImageTitle: 'peppers.png'

Set the dictionary of values using the desired namespace.

rosparam('set','ImageParam',pval)

Get the parameters using the namespace. Verify the parameter values.

pval2 = rosparam('get','ImageParam')
pval2 = struct with fields:
    ImageHeight: 512
     ImageTitle: 'peppers.png'
     ImageWidth: 384

Shut down ROS network.

rosshutdown
Shutting down global node /matlab_global_node_70463 with NodeURI http://dcc365816glnxa64:39751/ and MasterURI http://localhost:52656.
Shutting down ROS master on http://172.29.194.91:52656.

Input Arguments

collapse all

ROS parameter namespace, specified as a string scalar or character vector. All parameter names starting with this string are listed when calling rosparam("list",namespace).

ROS parameter name, specified as a string scalar or character vector.

ROS parameter value or dictionary of values, specified as a supported data type.

The following ROS data types are supported as values of parameters. For each ROS data type, the corresponding MATLAB data type is also listed:

  • 32-bit integers — int32

  • Booleans — logical

  • doubles — double

  • strings — string scalar, string, or character vector, char

  • lists — cell array

  • dictionaries — structure

Output Arguments

collapse all

Parameter list, returned as a cell array of character vectors. This is a list of all parameters available on the ROS master.

Parameter tree, returned as a ParameterTree object handle. Use this object to reference parameter information, for example, ptree.AvailableFrames.

ROS parameter value, specified as a supported MATLAB data type. When specifying the namespace input argument, pvalOut is returned as a structure of parameter value under the given namespace.

The following ROS data types are supported as values of parameters. For each ROS data type, the corresponding MATLAB data type is also listed.

ROS Data TypeMATLAB Data Type
32-bit integerint32
Booleanlogical
doubledouble
stringcharacter vector (char)
listcell array (cell)
dictionarystructure (struct)

Limitations

  • Unsupported Data Types: Base64-encoded binary data and iso8601 data from ROS are not supported.

  • Simplified Commands: When using the simplified command rosparam set pname pval, the parameter value is interpreted as:

    • logical — If pval is "true" or "false"

    • int32 — If pval is an integer, for example, 5

    • double — If pval is a fractional number, for example, 1.256

    • character vector — If pval is any other value

Extended Capabilities

Version History

Introduced in R2019b

See Also

Functions

Objects