Helper class for ParamLoader and DynparamMgr.
More...
#include <param_provider.h>
|
| | ParamProvider (const std::shared_ptr< rclcpp::Node > &node, const bool use_rosparam=true) |
| | Main constructor.
|
| |
| bool | addYamlFile (const std::string &filepath) |
| | Add a YAML file to be parsed and used for loading parameters.
|
| |
| void | copyYamls (const ParamProvider ¶m_provider) |
| | Copy parsed YAMLs from another ParamProvider.
|
| |
| template<typename T > |
| bool | getParam (const std::string ¶m_name, T &value_out) const |
| | Gets the value of a parameter.
|
| |
| template<typename T > |
| get_result_t | getParamResult (const std::string ¶m_name, T &value_out, const get_options_t< T > &opts={}) const |
| | Gets the value of a parameter and returns an explicit result state.
|
| |
| template<typename T > |
| bool | getParam (const resolved_name_t &resolved_name, T &value_out, const get_options_t< T > &opts={}) const |
| | Gets the value of a parameter.
|
| |
| template<typename T > |
| get_result_t | getParamResult (const resolved_name_t &resolved_name, T &value_out, const get_options_t< T > &opts={}) const |
| | Gets the value of a parameter and returns an explicit result state.
|
| |
| template<typename T > |
| bool | setParam (const std::string ¶m_name, const T &value) const |
| | Sets the value of a parameter to ROS.
|
| |
| template<typename T > |
| bool | setParam (const resolved_name_t &resolved_name, const T &value, const set_options_t< T > &opts={}) const |
| | Sets the value of a parameter to ROS.
|
| |
| template<typename T > |
| bool | declareParam (const std::string ¶m_name) const |
| | Defines a parameter.
|
| |
| template<typename T > |
| bool | declareParam (const std::string ¶m_name, const T &default_value) const |
| | Defines a parameter with a default value.
|
| |
| template<typename T > |
| bool | declareParam (const resolved_name_t &resolved_name, const declare_options_t< T > &opts={}) const |
| | Defines a parameter with various options.
|
| |
| void | setPrefix (const std::string &prefix) |
| | Sets a prefix that will be applied to parameter names before subnode namespaces.
|
| |
| std::string | getPrefix () const |
| | Returns the current parameter name prefix.
|
| |
| resolved_name_t | resolveName (const std::string ¶m_name) const |
| | Returns the parameter name with prefixes and subnode namespaces.
|
| |
Helper class for ParamLoader and DynparamMgr.
This class abstracts away loading of parameters from ROS parameter server and directly from YAML files ("static" parameters). The user can specify a number of YAML files that will be parsed and when a parameter value is requested, these are checked first before attempting to load the parameter from the ROS server (which can be slow). The YAML files are searched in FIFO order and when a matching name is found in a file, its value is returned.
◆ get_result_t
Explicit result state for parameter loading.
| Enumerator |
|---|
| LOADED | Parameter value loaded from YAML/ROS.
|
| DEFAULT | Parameter value resolved using provided default value.
|
| FAILED | Parameter value could not be resolved.
|
◆ ParamProvider()
| mrs_lib::ParamProvider::ParamProvider |
( |
const std::shared_ptr< rclcpp::Node > & |
node, |
|
|
const bool |
use_rosparam = true |
|
) |
| |
Main constructor.
- Parameters
-
| nh | The parameters will be loaded from rosparam using this node handle. |
| use_rosparam | If true, parameters that weren't found in the YAML files will be attempted to be loaded from ROS. |
◆ addYamlFile()
| bool mrs_lib::ParamProvider::addYamlFile |
( |
const std::string & |
filepath | ) |
|
Add a YAML file to be parsed and used for loading parameters.
The first file added will be the first file searched for a parameter when using getParam().
- Parameters
-
| filepath | Path to the YAML file. |
◆ copyYamls()
| void mrs_lib::ParamProvider::copyYamls |
( |
const ParamProvider & |
param_provider | ) |
|
◆ declareParam() [1/3]
Defines a parameter with various options.
This method declares the parameter in ROS with the behavior controlled by the options allowing to set a default value, valid value range (for numerical types), declare the parameter as reconfigurable, etc.
- Parameters
-
| param_name | Name of the parameter to be loaded. |
| opts | Options regarding declaring the parameter (see the declare_options_t<T> documentation). |
- Returns
- true iff the parameter was successfully declared.
◆ declareParam() [2/3]
template<typename T >
| bool mrs_lib::ParamProvider::declareParam |
( |
const std::string & |
param_name | ) |
const |
Defines a parameter.
This method only declares the parameter in ROS.
- Parameters
-
| param_name | Name of the parameter to be loaded. |
- Returns
- true iff the parameter was successfully declared.
◆ declareParam() [3/3]
template<typename T >
| bool mrs_lib::ParamProvider::declareParam |
( |
const std::string & |
param_name, |
|
|
const T & |
default_value |
|
) |
| const |
Defines a parameter with a default value.
This method declares the parameter in ROS and sets the default value if there is no value in ROS.
- Parameters
-
| param_name | Name of the parameter to be loaded. |
| default_value | The default value to be set if there is no value of the parameter. |
- Returns
- true iff the parameter was successfully declared.
◆ getParam() [1/2]
Gets the value of a parameter.
Firstly, the parameter is attempted to be loaded from the YAML files added by the addYamlFile() method in the same order that they were added. If the parameter is not found in any YAML file, and the use_rosparam flag of the constructor is true, the ParamProvider will declare it in ROS and attempt to load it from ROS.
- Parameters
-
| param_name | Name of the parameter to be loaded. Namespaces should be separated with a forward slash '/'. |
| value_out | Output argument that will hold the value of the loaded parameter, if successfull. Not modified otherwise. |
| opts | Options regarding getting and declaring the parameter (see the get_options_t<T> documentation). |
- Returns
- true iff the parameter was successfully loaded.
◆ getParam() [2/2]
template<typename T >
| bool mrs_lib::ParamProvider::getParam |
( |
const std::string & |
param_name, |
|
|
T & |
value_out |
|
) |
| const |
Gets the value of a parameter.
Firstly, the parameter is attempted to be loaded from the YAML files added by the addYamlFile() method in the same order that they were added. If the parameter is not found in any YAML file, and the use_rosparam flag of the constructor is true, the ParamProvider will declare it in ROS and attempt to load it from ROS.
- Parameters
-
| param_name | Name of the parameter to be loaded. Namespaces should be separated with a forward slash '/'. |
| value_out | Output argument that will hold the value of the loaded parameter, if successfull. Not modified otherwise. |
- Returns
- true iff the parameter was successfully loaded.
◆ getParamResult() [1/2]
Gets the value of a parameter and returns an explicit result state.
Firstly, the parameter is attempted to be loaded from the YAML files added by the addYamlFile() method in the same order that they were added. If the parameter is not found in any YAML file, and the use_rosparam flag of the constructor is true, the ParamProvider will declare it in ROS and attempt to load it from ROS.
- Parameters
-
| resolved_name | Resolved parameter name. |
| value_out | Output argument that will hold the value of the loaded parameter, if successfull. Not modified otherwise. |
| opts | Options regarding getting and declaring the parameter (see the get_options_t<T> documentation). |
- Returns
- Explicit loading result state.
◆ getParamResult() [2/2]
Gets the value of a parameter and returns an explicit result state.
Firstly, the parameter is attempted to be loaded from the YAML files added by the addYamlFile() method in the same order that they were added. If the parameter is not found in any YAML file, and the use_rosparam flag of the constructor is true, the ParamProvider will declare it in ROS and attempt to load it from ROS.
- Parameters
-
| param_name | Name of the parameter to be loaded. Namespaces should be separated with a forward slash '/'. |
| value_out | Output argument that will hold the value of the loaded parameter, if successfull. Not modified otherwise. |
| opts | Options regarding getting and declaring the parameter (see the get_options_t<T> documentation). |
- Returns
- Explicit loading result state.
◆ getPrefix()
| std::string mrs_lib::ParamProvider::getPrefix |
( |
| ) |
const |
Returns the current parameter name prefix.
- Returns
- The current prefix to be applied to all parameter names.
◆ resolveName()
Returns the parameter name with prefixes and subnode namespaces.
- Parameters
-
| param_name | Name of the parameter. |
- Returns
- name of the parameter with the appropriate prefixes and subnode namespaces applied.
◆ setParam() [1/2]
template<typename T >
| bool mrs_lib::ParamProvider::setParam |
( |
const resolved_name_t & |
resolved_name, |
|
|
const T & |
value, |
|
|
const set_options_t< T > & |
opts = {} |
|
) |
| const |
Sets the value of a parameter to ROS.
This method sets the parameter to ROS with the behavior controlled by the options allowing to set a default value, valid value range (for numerical types), declare the parameter as reconfigurable, etc.
- Parameters
-
| param_name | Name of the parameter to be set. Namespaces should be separated with a forward slash '/'. |
| value | The desired value of the parameter. |
| opts | Options regarding setting and declaring the parameter (see the set_options_t<T> documentation). |
- Returns
- true iff the parameter was successfully set.
◆ setParam() [2/2]
template<typename T >
| bool mrs_lib::ParamProvider::setParam |
( |
const std::string & |
param_name, |
|
|
const T & |
value |
|
) |
| const |
Sets the value of a parameter to ROS.
This method sets the parameter to ROS with the desired value.
- Parameters
-
| param_name | Name of the parameter to be set. Namespaces should be separated with a forward slash '/'. |
| value | The desired value of the parameter. |
- Returns
- true iff the parameter was successfully set.
◆ setPrefix()
| void mrs_lib::ParamProvider::setPrefix |
( |
const std::string & |
prefix | ) |
|
Sets a prefix that will be applied to parameter names before subnode namespaces.
The prefix will be applied as-is, so if you need to separate it from the parameter name e.g. using a forward slash '/', you must include it in the prefix.
- Parameters
-
| prefix | The prefix to be applied to all parameter names. |
The documentation for this class was generated from the following files: