add parameter helpers (redo of #233) - #237
Merged
Merged
Conversation
| { | ||
| std::vector<std::string> names; | ||
| names.push_back(parameter_name); | ||
| auto vars = get_parameters(names); |
Member
There was a problem hiding this comment.
In what case is vars.size() > 1 valid? Should that also be checked for?
Also, it seems as if these two functions could be de-duplicated a little bit, though that might just end up being more complicated. I could, however, imagine:
template<typename T>
T
get_parameter_impl(const std::string & parameter_name, std::function<T()> parameter_not_found_handler)
{
std::vector<std::string> names;
names.push_back(parameter_name);
auto vars = get_parameters(names);
if ((vars.size() == 0) || (vars[0].get_type() == rclcpp::parameter::PARAMETER_NOT_SET)) {
return parameter_not_found_handler();
} else {
return static_cast<T>(vars[0].get_value<T>());
}
}
template<typename T>
T
get_parameter(const std::string & parameter_name, const T & default_value)
{
return get_parameter_impl(parameter_name, [&default_value]() { return default_value; });
}
template<typename T>
T
get_parameter(const std::string & parameter_name)
{
return get_parameter_impl(parameter_name, []() { throw std::runtime_error("Parameter not set"); });
}
Member
Author
There was a problem hiding this comment.
Great suggestion, thanks! Done, with minor tweaks, in a1b4e15.
Member
|
Other than a comment, the code changes lgtm. |
Member
Author
|
Tests are in ros2/system_tests#155. |
Member
Author
|
New CI, this time with the tests from ros2/system_tests#155 included: |
Karsten1987
pushed a commit
that referenced
this pull request
Dec 7, 2016
nnmm
pushed a commit
to ApexAI/rclcpp
that referenced
this pull request
Jul 9, 2022
* Implement a basic YAML based parameter parser for ros2 nodes * Add README file * Fix the issues after moving from rcutils_yaml_param_parser to rcl_yaml_param_parser - rename folders from rcutils_yaml_param_parser to rcl_yaml_param_parser - rename project, header guards and include statements from rcutils_yaml_param_parser to rcl_yaml_param_parser - move type declaration in separat file and namespace new structures - Fix the code review comments from Mikael * Few minor changes - Changed "params" string to "ros__parameters" - Add -Wall, -Wextra and -Wpedantic falgs - Fix the compile warning with the new flags * Fix the changes made in the design of C structure - Remove the node_namespaces entry in rcl_params_t - Change the type of num_nodes and num_params to size_t * depend on libyaml_vendor (ros2#236) * Fix cmake setting standard(C and C++) and add byte_array in C struct * Remove C11 so that it defaults to C99 * [rcl_yaml_param_parser] fix export symbols (ros2#237) * add visibility macros * remove unused macro * Support for multi level node and parameter name spaces * Additional fixes and cleanups - Support for string namespace seperator - Provide parameter structure init function API - name cleanups * off by 1 * Call yaml_parser_delete() * fclose(yaml_file) * free() allocated paths * Call yaml_event_delete() * completely deallcoate string array * Few cleanup changes - Add install command into CMakelists.txt - Replace one of the zero_allocate with reallocate - Pass allocator state - Fix int32_t -> rcl_ret_t return value * Don't include unistd.h * Use size_t for array indices * Just pass the allocator in the init function
DensoADAS
pushed a commit
to DensoADAS/rclcpp
that referenced
this pull request
Aug 5, 2022
Signed-off-by: Zachary Michaels <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a replacement for #233, with the same diff (because I once again went into the weeds while attempting to rebase; I'll get the hang of that eventually).