Programmatically load parameters from YAML file in rclcpp node

asked 2020-04-18 01:40:35 -0600

vmanchal gravatar image

updated 2020-04-18 06:52:13 -0600

I am trying to load the parameters from a yaml file. This is what I am doing-

int main([[maybe_unused]]int argc, [[maybe_unused]]char **argv){

rclcpp::init(0, nullptr);
rclcpp::NodeOptions options = rclcpp::NodeOptions()
    .allow_undeclared_parameters(true)
    .automatically_declare_parameters_from_overrides(true)
    .arguments({"--ros-args", "--params-file", "/examples/test.yaml"});

const rcl_node_options_t * rcl_options = options.get_rcl_node_options();
std::cout << (rcl_options != nullptr) << std::endl;
std::cout << (0 == rcl_arguments_get_count_unparsed(&rcl_options->arguments)) << std::endl;
std::cout << (0 == rcl_arguments_get_count_unparsed_ros(&rcl_options->arguments)) << std::endl;

rclcpp::Node node("param_name", options);

auto po = options.parameter_overrides();
std::cout << po.size() << std::endl;

auto node_params =
    node.get_node_parameters_interface()->get_parameter_overrides();

for (auto& x : node_params){
    std::cout << x.first << std::endl;
}
}

options.parameter_overrides() and node.get_node_parameters_interface()->get_parameter_overrides() are both empty. How can I load parameters at run-time in the node, by doing something similar to what I did?

edit retag flag offensive close merge delete