Saving Parameters in a YAML File
To save the configuration parameters involved in the deterministic scheduling system in YAML format, prepare the following YAML files:
- File 1: YAML file for storing parameters. The YAML file name and storage path can be customized. This section uses param.yaml as an example.
- File 2: used to specify the path and related attributes of file 1. The name and storage path of the YAML file can be customized. This section uses yaml_path.yaml as an example.
- File 3: used to configure the path and variables of file 2. The name and storage path of the YAML file can be customized. This section uses cfgmgr_env.yaml as an example.
You need to set the CFGMGR_ENV_PATH environment variable to specify a path so that the configuration management system can read the CFGMGR_ENV_PATH environment variable to identify the storage location of the YAML file and then identify the storage location of the YAML file that saves parameters.
param.yaml Configuration Example
This file is used to store system configuration parameters. The format complies with the general YAML file specifications, that is, the key-value pair format. Both the key and value can be modified. The following is a configuration example:
param1: a: 12 b: true c: "node" param2: 234
When parsing the YAML file, the configuration management module needs to obtain parameter values through the CfgMgr::Get interface. The principle is to obtain the corresponding value based on the specified key value (the content before the colon is the key value). The following is a parsing example. For details about the namespace definition, see yaml_path.yaml Configuration Example.
/namespace/param1/a: 12 /namespace/param1/b: true /namespace/param1/c: "node" /namespace/param2: 234
If the parameters saved in the YAML file are in array format, use hyphens (-) to distinguish each group of parameters. The following is a configuration example:
module:
-
key1: aaa
key2: bbb
-
key1: ccc
key2: ddd
When the configuration management module parses the YAML file, underscores (_) and sequence numbers (from top to bottom, the array sequence number starts from 0) need to be added to the key value. The parsing example is as follows:
/namespace/module_0/key1: aaa /namespace/module_0/key2: bbb /namespace/module_1/key1: ccc /namespace/module_1/key2: ddd
yaml_path.yaml Configuration Example
This file is used to specify the path for storing the param.yaml parameter file and related attribute information. The following is a configuration example:
yaml_path:
- path: /etc/param.yaml
namespace: /demo
group: global
version: 1.0
- path: /etc/cfg/robot_sensor_config/${robot_type}/${robot_id}/pnc_configs/parking_params.yaml
namespace: /pnc
group: global
version: 1.0
- path: ${parameters_path}/robot_sensor_config/${robot_type}/${robot_id}/pnc_configs
namespace: /pnc
group: global
version: 1.0
These parameters are fixed and cannot be modified. The meanings of these parameters are as follows:
- yaml_path: indicates the function of the YAML file. It is used to specify the path for storing the parameter file and related attribute information.
- path: indicates the path or directory for storing the param.yaml parameter file.
- If a directory is specified, all YAML files in the directory are loaded by default.
- If the value of path contains variables, add ${variable} to identify the variables and define the variables in the cfgmgr_env.yaml file. For details, see cfgmgr_env.yaml Configuration Example.
- namespace: indicates the name domain of the path parameter. This parameter can be left blank.
- group: indicates the parameter group to which the path parameter belongs. The group corresponds to the virtual resource file. You can configure the read and write permissions of each process by group. This parameter is reserved and does not need to be configured. The default value is global, indicating that all processes have the read and write permissions.
- version: indicates the version of the path parameter. This parameter is reserved and does not need to be configured.
cfgmgr_env.yaml Configuration Example
This file is used to configure the storage path and related variables of yaml_path.yaml. A configuration example is as follows:
cfgmgr_env: # Fixed field, which cannot be changed.
yaml_path: # Fixed field, which cannot be changed.
- /etc/yaml/pnc_yaml_path.yaml
- /etc/yaml/fusion_yaml_path.yaml
# The following is an example of variable configuration. You can add, delete, and modify variables as required.
robot_factory: xxxxx
robot_type: vw_magotan_1.1
robot_sensor: xxx
robot_id: LFV3A23C5J3010804
scenario: map
You can modify the parameters in the cfgmgr_env section. After the modification, you need to reload the YAML file through the CfgMgr::Reload interface.
Key parameters are described as follows:
- cfgmgr_env: fixed parameter name, which cannot be changed.
- yaml_path: path of the yaml_path.yaml file of each module. You must configure at least one path and can configure multiple paths. The CfgMgr determines the YAML files to be loaded based on the xxx_yaml_path.yaml file.
- Variable (for example, robot model): The value is a key-value pair. Both the key and value can be modified. Variables can be used as a part of the YAML file path to load different YAML files for different robots.