Skip to content

Commit 1150367

Browse files
kaspermeck-armalanmengg
authored andcommitted
docs(parameters): add DevOps Dojo: ROS Node Config documentation (autowarefoundation#367)
Signed-off-by: kaspermeck-arm <kasper.mecklenburg@arm.com> Change-Id: I8b2fee98c497037d3293e70747bb162b9a640895 Signed-off-by: guiping meng <alan.meng@autocore.ai>
1 parent eb92202 commit 1150367

File tree

1 file changed

+161
-24
lines changed

1 file changed

+161
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,173 @@
11
# Parameters
22

3-
The ROS packages in Autoware have ROS parameters. You need to customize the parameters depending on your applications.
4-
It is recommended not to set default values when declaring ROS parameters to avoid unintended behaviors due to accidental use of default values.
5-
Instead, set parameters from configuration files named `*.param.yaml`.
3+
Autoware ROS nodes have declared parameters which values are provided during the node start up in the form of a parameter file. All the expected parameters with corresponding values should exist in the parameter file. Depending on the application, the parameter values might need to be modified.
64

7-
For understanding ROS 2 parameters, also check out the official documentation [Understanding parameters](https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Parameters/Understanding-ROS2-Parameters.html).
5+
Find more information on parameters from the official ROS documentation:
86

9-
## Parameter files
7+
- [Understanding ROS 2 Parameters](https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Parameters/Understanding-ROS2-Parameters.html)
8+
- [About ROS 2 Parameters](https://docs.ros.org/en/humble/Concepts/About-ROS-2-Parameters.html)
109

11-
Autoware has the following two types of parameter files for ROS packages:
10+
## Workflow
1211

13-
- **Node parameter file**
14-
- Node parameter files store the default parameters provided for each package in Autoware.
15-
- For example, [the parameter of `behavior_path_planner`](https://github.com/autowarefoundation/autoware.universe/tree/245242cee866de2d113e89c562353c5fc17f1f98/planning/behavior_path_planner/config)
16-
- All nodes in Autoware must have a parameter file if one or more parameters that can be customized by the user are defined.
17-
- For `FOO_package`, the parameter is expected to be stored in `FOO_package/config`.
18-
- The launch file for individual packages must load node parameter by default:
12+
A ROS package which uses the [declare_parameter(...)](https://docs.ros.org/en/ros2_packages/humble/api/rclcpp/generated/classrclcpp_1_1Node.html#_CPPv4N6rclcpp4Node17declare_parameterERKNSt6stringERKN6rclcpp14ParameterValueERKN14rcl_interfaces3msg19ParameterDescriptorEb) function should:
1913

20-
```xml
21-
<launch>
22-
<arg name="foo_node_param_path" default="$(find-pkg-share FOO_package)/config/foo_node.param.yaml" />
14+
- use the [declare_parameter(...)](https://docs.ros.org/en/ros2_packages/humble/api/rclcpp/generated/classrclcpp_1_1Node.html#_CPPv4N6rclcpp4Node17declare_parameterERKNSt6stringERKN6rclcpp14ParameterValueERKN14rcl_interfaces3msg19ParameterDescriptorEb) with out a default value
15+
- create a parameter file
16+
- create a schema file
2317

24-
<node pkg="FOO_package" exec="foo_node">
25-
...
26-
<param from="$(var foo_node_param_path)" />
27-
</node>
28-
</launch>
18+
The rationale behind this workflow is to have a verified single source of truth to pass to the ROS node and to be used in the web documentation. The approach reduces the risk of using invalid parameter values and makes maintenance of documentation easier. This is achieved by:
19+
20+
- [declare_parameter(...)](https://docs.ros.org/en/ros2_packages/humble/api/rclcpp/generated/classrclcpp_1_1Node.html#_CPPv4N6rclcpp4Node17declare_parameterERKNSt6stringERKN6rclcpp14ParameterValueERKN14rcl_interfaces3msg19ParameterDescriptorEb) throws an exception if an expected parameter is missing in the parameter file
21+
- the schema validates the parameter file in the CI and renders a parameter table, as depicted in the graphics below
22+
23+
```mermaid
24+
flowchart TD
25+
NodeSchema[Schema file: *.schema.json]
26+
ParameterFile[Parameter file: *.param.yaml]
27+
WebDocumentation[Web documentation table]
28+
29+
NodeSchema -->|Validation| ParameterFile
30+
NodeSchema -->|Generate| WebDocumentation
31+
```
32+
33+
Note: a parameter value can still be modified and bypass the validation, as there is no validation during runtime.
34+
35+
## Declare Parameter Function
36+
37+
It is the [declare_parameter(...)](https://docs.ros.org/en/ros2_packages/humble/api/rclcpp/generated/classrclcpp_1_1Node.html#_CPPv4N6rclcpp4Node17declare_parameterERKNSt6stringERKN6rclcpp14ParameterValueERKN14rcl_interfaces3msg19ParameterDescriptorEb) function which sets the parameter values during a node startup.
38+
39+
```cpp
40+
declare_parameter<INSERT_TYPE>("INSERT_PARAMETER_1_NAME"),
41+
declare_parameter<INSERT_TYPE>("INSERT_PARAMETER_N_NAME")
42+
```
43+
44+
As there is no _default_value_ provided, the function throws an exception if a parameter were to be missing in the provided `*.param.yaml` file. Use a type from the _C++ Type_ column in the table below for the [declare_parameter(...)](https://docs.ros.org/en/ros2_packages/humble/api/rclcpp/generated/classrclcpp_1_1Node.html#_CPPv4N6rclcpp4Node17declare_parameterERKNSt6stringERKN6rclcpp14ParameterValueERKN14rcl_interfaces3msg19ParameterDescriptorEb) function, replacing _INSERT_TYPE_.
45+
46+
| ParameterType Enum | C++ Type |
47+
| ------------------------- | -------------------------- |
48+
| `PARAMETER_BOOL` | `bool` |
49+
| `PARAMETER_INTEGER` | `int64_t` |
50+
| `PARAMETER_DOUBLE` | `double` |
51+
| `PARAMETER_STRING` | `std::string` |
52+
| `PARAMETER_BYTE_ARRAY` | `std::vector<uint8_t>` |
53+
| `PARAMETER_BOOL_ARRAY` | `std::vector<bool>` |
54+
| `PARAMETER_INTEGER_ARRAY` | `std::vector<int64_t>` |
55+
| `PARAMETER_DOUBLE_ARRAY` | `std::vector<double>` |
56+
| `PARAMETER_STRING_ARRAY` | `std::vector<std::string>` |
57+
58+
The table has been derived from [Parameter Type](https://github.com/ros2/rcl_interfaces/blob/humble/rcl_interfaces/msg/ParameterType.msg) and [Parameter Value](https://github.com/ros2/rcl_interfaces/blob/humble/rcl_interfaces/msg/ParameterValue.msg).
59+
60+
See example: _Lidar Apollo Segmentation TVM Nodes_ [declare function](https://github.com/autowarefoundation/autoware.universe/blob/f85c90b56ed4c7d6b52e787570e590cff786b28b/perception/lidar_apollo_segmentation_tvm_nodes/src/lidar_apollo_segmentation_tvm_node.cpp#L38)
61+
62+
## Parameter File
63+
64+
The parameter file is minimal as there is no need to provide the user with additional information, e.g., description or type. This is because the associated schema file provides the additional information. Use the template below as a starting point for a ROS node.
65+
66+
```yaml
67+
/**:
68+
ros__parameters:
69+
INSERT_PARAMETER_1_NAME: INSERT_PARAMETER_1_VALUE
70+
INSERT_PARAMETER_N_NAME: INSERT_PARAMETER_N_VALUE
2971
```
3072
31-
- **Launch parameter file**
32-
- Launch parameter files store the customized parameters for user's vehicle.
33-
- For example, [the customized parameter of `behavior_path_planner` stored under `autoware_launch`](https://github.com/autowarefoundation/autoware_launch/tree/5fa613b9d80bf4f0db77efde03a43f7ede6bac86/autoware_launch/config)
73+
The parameter file path is `INSERT_PATH_TO_PACKAGE/config/` and parameter file name is `INSERT_NODE_NAME.param.yaml`. To adapt the template to the ROS node, replace each `INSERT_PARAMETER_..._NAME` and `INSERT_PARAMETER_..._VALUE` for all parameters. Each [declare_parameter(...)](https://docs.ros.org/en/ros2_packages/humble/api/rclcpp/generated/classrclcpp_1_1Node.html#_CPPv4N6rclcpp4Node17declare_parameterERKNSt6stringERKN6rclcpp14ParameterValueERKN14rcl_interfaces3msg19ParameterDescriptorEb) takes one parameter as input.
74+
75+
See example: _Lidar Apollo Segmentation TVM Nodes_ [parameter file](https://github.com/autowarefoundation/autoware.universe/blob/main/perception/lidar_apollo_segmentation_tvm_nodes/config/lidar_apollo_segmentation_tvm_nodes.param.yaml)
76+
77+
Note: `/**` is used instead of the explicit node namespace, this allows the parameter file to be passed to a ROS node which has been [remapped](https://design.ros2.org/articles/static_remapping.html).
78+
79+
## Launch parameter file
80+
81+
- Launch parameter files store the customized parameters for user's vehicle.
82+
- For example, [the customized parameter of `behavior_path_planner` stored under `autoware_launch`](https://github.com/autowarefoundation/autoware_launch/tree/5fa613b9d80bf4f0db77efde03a43f7ede6bac86/autoware_launch/config)
3483
- Launch parameter files are stored under `autoware_launch`.
3584

36-
All the parameter files should have the `.param.yaml` suffix so that the auto-format can be applied properly.
85+
## JSON Schema
86+
87+
[JSON Schema](https://json-schema.org/understanding-json-schema/index.html) is used the validate the parameter file(s) ensuring that it has the correct structure and content. Using JSON Schema for this purpose is considered best practice for cloud-native development. The schema template below shall be used as a starting point when defining the schema for a ROS node.
88+
89+
```json
90+
{
91+
"$schema": "http://json-schema.org/draft-07/schema#",
92+
"title": "INSERT_TITLE",
93+
"type": "object",
94+
"definitions": {
95+
"INSERT_ROS_NODE_NAME": {
96+
"type": "object",
97+
"properties": {
98+
"INSERT_PARAMETER_1_NAME": {
99+
"type": "INSERT_TYPE",
100+
"description": "INSERT_DESCRIPTION",
101+
"default": "INSERT_DEFAULT",
102+
"INSERT_BOUND_CONDITION(S)": "INSERT_BOUND_VALUE(S)"
103+
},
104+
"INSERT_PARAMETER_N_NAME": {
105+
"type": "INSERT_TYPE",
106+
"description": "INSERT_DESCRIPTION",
107+
"default": "INSERT_DEFAULT",
108+
"INSERT_BOUND_CONDITION(S)": "INSERT_BOUND_VALUE(S)"
109+
}
110+
},
111+
"required": ["INSERT_PARAMETER_1_NAME", "INSERT_PARAMETER_N_NAME"]
112+
}
113+
},
114+
"properties": {
115+
"/**": {
116+
"type": "object",
117+
"properties": {
118+
"ros__parameters": {
119+
"$ref": "#/definitions/INSERT_ROS_NODE_NAME"
120+
}
121+
},
122+
"required": ["ros__parameters"]
123+
}
124+
},
125+
"required": ["/**"]
126+
}
127+
```
128+
129+
The schema file path is `INSERT_PATH_TO_PACKAGE/schema/` and the schema file name is `INSERT_NODE_NAME.schema.json`. To adapt the template to the ROS node, replace each `INSERT_...` and add all parameters `1..N`.
130+
131+
See example: _Lidar Apollo Segmentation TVM Nodes_ [schema](https://github.com/autowarefoundation/autoware.universe/blob/main/perception/lidar_apollo_segmentation_tvm_nodes/schema/lidar_apollo_segmentation_tvm_nodes.schema.json)
132+
133+
### Attributes
134+
135+
Parameters have several attributes, some are required and some optional. The optional attributes are highly encouraged when applicable, as they provide useful information about a parameter and can ensure the value of the parameter is within its bounds.
136+
137+
#### Required
138+
139+
- name
140+
- type
141+
- see [JSON Schema types](http://json-schema.org/understanding-json-schema/reference/type.html)
142+
- description
143+
144+
#### Optional
145+
146+
- default
147+
- a tested and verified value, see [JSON Schema default](https://json-schema.org/understanding-json-schema/reference/generic.html)
148+
- bound(s)
149+
- type dependent, e.g., [integer](https://json-schema.org/understanding-json-schema/reference/numeric.html#integer), [range](https://json-schema.org/understanding-json-schema/reference/numeric.html#range) and [size](https://json-schema.org/understanding-json-schema/reference/object.html#size)
150+
151+
## Tips and Tricks
152+
153+
Using well established standards enables the use of conventional tooling. Below is an example of how to link a schema to the parameter file(s) using VS Code. This enables a developer with convenient features such as auto-complete and parameter bound validation.
154+
155+
In the root directory of where the project is hosted, create a `.vscode` folder with two files; `extensions.json` containing
156+
157+
```json
158+
{
159+
"recommendations": ["redhat.vscode-yaml"]
160+
}
161+
```
162+
163+
and `settings.json` containing
164+
165+
```json
166+
{
167+
"yaml.schemas": {
168+
"./INSERT_PATH_TO_PACKAGE/schema/INSERT_NODE_NAME.schema.json": "**/INSERT_NODE_NAME/config/*.param.yaml"
169+
}
170+
}
171+
```
172+
173+
The RedHat YAML extension enables validation of YAML files using JSON Schema and the `"yaml.schemas"` setting associates the `*.schema.json` file with all `*.param.yaml` files in the `config/` folder.

0 commit comments

Comments
 (0)