Initialize params via yaml from command line#488
Conversation
2cb890e to
f067f5f
Compare
|
Optimistically moving to in review |
wjwwood
left a comment
There was a problem hiding this comment.
Looks fine in general, but there are a few things that need to be addressed, like memory leaking.
| throw std::runtime_error("Need valid node handle in NodeParameters"); | ||
| } | ||
| const rcl_node_options_t * options = rcl_node_get_options(node); | ||
| if (NULL == options) { |
There was a problem hiding this comment.
I'd recommend using nullptr in C++.
| auto get_yaml_paths = [&yaml_paths, &options](const rcl_arguments_t * args) { | ||
| int num_yaml_files = rcl_arguments_get_param_files_count(args); | ||
| if (num_yaml_files > 0) { | ||
| char ** param_files; |
| combined_name = node_namespace + node_name; | ||
| } else { | ||
| combined_name = node_namespace + '/' + node_name; | ||
| } |
There was a problem hiding this comment.
Should probably be a function for this in rcl, I wouldn't do it now, but an issue would be nice.
|
|
||
| std::map<std::string, rclcpp::Parameter> parameters; | ||
|
|
||
| // TODO(sloretz) rcl too parse yaml when circular dependency is solved |
| throw std::runtime_error("Failed to parse parameters " + yaml_path); | ||
| } | ||
|
|
||
| rclcpp::ParameterMap initial_map = rclcpp::parameter_map_from(yaml_params); |
There was a problem hiding this comment.
Does this fini the yaml_params? If not then it needs to be, if so then... eew lol
There was a problem hiding this comment.
It does not. Added call to ...fini() in d765738
| for (const std::string & yaml_path : yaml_paths) { | ||
| rcl_params_t * yaml_params = rcl_yaml_node_struct_init(options->allocator); | ||
| if (NULL == yaml_params) { | ||
| throw std::runtime_error("Failed to initialize yaml params struct"); |
There was a problem hiding this comment.
Should be able to narrow this down to a better exception, like std::bad_alloc. Looking at them now, the yaml parsing API in yaml leaves something to be desired in terms of error reporting and namespacing.
There was a problem hiding this comment.
Changed this exception to bad_alloc in ef427a7
|
CI as of ef427a7 |
wjwwood
left a comment
There was a problem hiding this comment.
lgtm, with one suggestion on how to make it even better.
| rclcpp::exceptions::throw_from_rcl_error(ret); | ||
| } | ||
| for (int i = 0; i < num_yaml_files; ++i) { | ||
| yaml_paths.emplace_back(param_files[i]); |
There was a problem hiding this comment.
What happens if this throws? Maybe a "scope exit" kind of thing to clean up the whole param_files all at once would be better.
| combined_name = node_namespace + node_name; | ||
| } else { | ||
| combined_name = node_namespace + '/' + node_name; | ||
| } |
|
It looks like ros2/rmw_fastrtps#205 is the cause of the test failure on the OSX build. I'll re-write the test to avoid destroying clients as a workaround. |
|
|
||
| std::map<std::string, rclcpp::Parameter> parameters; | ||
|
|
||
| // TODO(sloretz) use rcl to parse yaml when circular dependency is solved |
There was a problem hiding this comment.
@sloretz do you happen to remember the context around this todo? I came across it today and was confused since it seems like yaml parsing is done in rcl already, so it must be referring to something else.
There was a problem hiding this comment.
since it seems like yaml parsing is done in rcl already
This is actually done in rcl_yaml_param_parser and not rcl.
That package is currently depending on rcl to be able to use rcl types, so rcl cannot depenc on rcl_yaml_param_parser to avoid circular dependency.
ros2/rcl#252
There was a problem hiding this comment.
oh I see! Thanks, I thought from the rcl_ prefix that they were in rcl, but of course that's not the case 😄 I'll reference that ticket in the todo.
Signed-off-by: Erik Boasson <eb@ilities.com>
…ros2#488) * Remove exception throw in dtor Update logging errors to avoid duplication Signed-off-by: Devin Bonnie <dbbonnie@amazon.com> * Cleanup reset logic Add reset documentation Signed-off-by: Devin Bonnie <dbbonnie@amazon.com> * Fix cpplint error Signed-off-by: Devin Bonnie <dbbonnie@amazon.com> * Fix docstring Signed-off-by: Devin Bonnie <dbbonnie@amazon.com>
Blocks #477
Requires #485
Requires #486
Requires ros2/rcl#253
This initializes the parameters on a node from yaml files. Since there are multiple sources of initial values passed to a node (multiple yaml files on the command line, multiple yaml files on node specific CLI arugments, explicit
initial_valuespassed to constructor) this PR merges all the sources such that constructorinitial_valuesoverwrites constructorargumentswhich overwrites global command line arguments. Within CLI arguments Yaml files specified later overwrite ones specified earlier.i.e. this works
The only commit is 2cb890e. This PR needs to be rebased when #485 and #486 are merged. Also this PR needs tests.