Main Content


Create object to access parameters from ROS 2 nodes

Since R2022b


Create a ros2param object and use its object functions to interact with the parameters associated with any node on the ROS 2 network. You can get, set, list and search for parameters of the specified ROS 2 node.




paramObj = ros2param(nodeName) returns a ros2param object paramObj which you can use to interact with the parameters associated with the specified ROS 2 node, nodeName.

paramObj = ros2param(nodeName,DomainID=ID) specifies a Domain identification of the ROS 2 network to connect to using name-value argument DomainID.

Input Arguments

expand all

The name of the node on the ROS 2 network.


In ROS 1, node names are unique and this is being enforced by shutting down existing nodes when a new node with the same name is started. In ROS 2, the uniqueness of node names is not enforced. When creating a new node, use ros2 function to list existing nodes.

Object Functions

getGet value of parameter in associated ROS 2 node
setSet value of parameter in associated ROS 2 node
listList all parameters in associated ROS 2 node
hasCheck if parameter exists in ROS 2 node
searchSearch for parameter names in ROS 2 node


collapse all

Create a ROS 2 node with parameters.

nodeParams.my_double = 2.0;
nodeParams.my_namespace.my_int = int64(1);
nodeParams.my_double_array = [1.1 2.2 3.3];
nodeParams.my_string = "Keyparams";
mainNode = ros2node("mainNode",Parameters=nodeParams);

Create a ros2param object to interact with the parameters of the ROS 2 node, /node1.

paramObj = ros2param("mainNode");

Use the set function to change the value of the parameter my_string.


Use the get function to obtain the new value of my_string.

stringVal = get(paramObj,"my_string")
stringVal = 

Use the has function to check if the parameter my_char exists in the ROS 2 node, /node1.

flag = has(paramObj,"my_char")
flag = logical

Use the search function to search for names of all the parameters that contain the string "my_d". Obtain the values of the matching parameters.

[pNames,pVals] = search(paramObj,"my_d")
pNames = 2x1 cell
    {'my_double'      }

pVals=2×1 cell array
    {[                   2]}
    {[1.1000 2.2000 3.3000]}

Use the list function to list the names of all parameters in the ROS 2 node.

pList = list(paramObj)
pList = 9x1 cell
    {'my_double'                                            }
    {'my_double_array'                                      }
    {'my_namespace.my_int'                                  }
    {'my_string'                                            }
    {'qos_overrides./parameter_events.publisher.depth'      }
    {'qos_overrides./parameter_events.publisher.durability' }
    {'qos_overrides./parameter_events.publisher.history'    }
    {'use_sim_time'                                         }

Version History

Introduced in R2022b

See Also

| |