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

Setting parameter from YAML files

asked 2020-03-31 21:33:15 -0600

fiji3119 gravatar image

updated 2020-04-01 03:41:36 -0600

gvdhoorn gravatar image


I am trying to understand setting params via .yaml file. I tried running this but I get:

terminate called after throwing an instance of 'std::runtime_error'
  what():  Failed to parse parameters from file 'demo_params.yaml': Error opening YAML file, at /tmp/binarydeb/ros-dashing-rcl-yaml-param-parser-0.7.8/src/parser.c:1387

Where should demo_params.yaml be placed? The content of this file is same as in example. ROS: dashing

Thanks, nkumar

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-04-01 08:44:09 -0600

fiji3119 gravatar image

updated 2020-04-13 17:26:02 -0600

My apologies - I did not give full file path. Works now.

OK, I still find that the parameter from yaml file does not override default value in the node: Here is my example, in demo_params.yaml (see this), I would like some_int: 42 to override the default value of 30 in my code. Here is my code snippet:

TestNode::TestNode(const rclcpp::NodeOptions& options) : Node("test", options)
        this->declare_parameter("some_int", 30);
       std::vector<rclcpp::parameter> params = this->get_parameters({"some_int", "a_string"});
       for (auto i : params) {
              if (i.get_name() == "some_int")
                     RCLCPP_INFO(get_logger(), "%s", i.as_int());

This prints 30 not 42!. What am I doint wrong here? Also, changing options.automatically_declare_parameters_from_overrides(true or false) makes no difference.

Thanks, nkumar

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-03-31 21:33:15 -0600

Seen: 900 times

Last updated: Apr 13 '20