CfgMgr::Param

Description

Obtains parameters by parameter name or namespace. If parameters fail to be obtained, the default parameters are used.

Prototype

uint32_t CfgMgr::Param(const std::string &kParam, T &value, const T &defaultValue, const std::string &srv = "")

Function Security Level

ASIL-D

Parameters

Parameter

Input/Output

Description

kParam

Input

Key, which is a parameter name or namespace, for example, /ros/use_sim_time or /ros. Starting with a slash (/) is not mandatory.

defaultValue

Input

Default value, which is used when parameters fail to be obtained.

srv

Input

Parameter group, which corresponds to a resource file. If it is not specified, parameters are obtained from the parameter groups on which you have the permission by default, which reduces the efficiency.

value

Output

Used to receive the value of a parameter. You can specify the parameter type. For details about the supported types, see "Usage".

Returns

The return value is of the uint32_t type, indicating whether parameters are successfully obtained. If the operation is successful, CFGMGR_SUCCESS is returned. If the operation fails, an error code is returned.

Usage

  • The value type can be std::string, double, float, int, bool, std::vector<std::string>, std::vector<double>, std::vector<float>, std::vector<int>, std::vector<bool>, std::map<std::string, std::string>, std::map<std::string, double>, std::map<std::string, float>, std::map<std::string, int>, and std::map<std::string, bool>.
  • When a parameter is obtained based on the namespace, the value type must be map. If parameter types in this namespace are different, the value type must be std::map<std::string, std::string>, indicating a key-value pair.

Precautions

  • The key must be less than 128 bytes, and a single value must be less than 256 bytes.
  • After obtaining parameters, you are advised to determine their validity based on the service logic.
  • For parameters of the map type, the original data of input parameters is not cleared during the Get operation. Instead, the data is modified or added.
  • If a parameter fails to be obtained or is invalid, determine whether to report the fault or perform other operations.
  • The interface may return a failure message for several reasons, including the absence of permissions and parameters, parameter loading failure, and data transmission failure (management plane).