ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You should declare them instead, as described here:

https://index.ros.org/doc/ros2/Releases/Release-Dashing-Diademata/#declaring-a-parameter-with-a-parameterdescriptor

Your example would be like this:

class MyNode : public rclcpp::Node
{
public:
  MyNode(
    const std::string & name = "my_name",
    const std::string & namespace_ = "",
    const rclcpp::NodeOptions & options = rclcpp::NodeOptions)
  : rclcpp::Node(name, namespace_, options)
  {
    int64_t actual_value = this->declare_parameter("my_param", 42);
    // actual_value may be 42 or another value if overridden by the YAML file passed on the command-line
  }
}

The "initial parameter values" in the NodeOptions are most similar to having values in a YAML file, they're overrides, not declarations, e.g. you could override the default value programmatically like this:

auto my_node = std::make_shared<MyNode>("my_name", "", rclcpp::NodeOptions().append_initial_parameter("my_param", 1337));