Implementing ROS 2 parameters in C++
We are going to implement ROS 2 parameters in the publisher code we have already worked with. Here is the objective of the updated code.
The new node we are going to create will have two parameters: a string and an integer. The value will be published using the custom message topic we have already created. So, if we set these parameters outside the node during the runtime, those values will be taken for publishing. After publishing the new value, the parameter will be set to default values. You can find the source code in Chapter03
| master_ros2_pkg
| src
| publisher_node_params.cpp
.
Let’s check out this code and see how we can declare the parameters in a C++ node.
Declaring ROS 2 parameters
This is how we declare new parameters in a C++ node. The declare_parameters
function is used to declare a new parameter. Here is an example usage of this function:
this->declare_parameter<std::string>("custom_string...