-
Notifications
You must be signed in to change notification settings - Fork 478
Adding API to copy all parameters from one node to another #2304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fujitatomoya
merged 16 commits into
ros2:rolling
from
open-navigation:copy_all_params_api
Oct 5, 2023
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
89488b9
adding API to copy all parameters from one node to another
SteveMacenski b258b8f
adding API docs portion on rclcpp/rclcpp.hpp
SteveMacenski 8614994
adding override option to copy_all_parameters() + review comments
SteveMacenski dd0453e
updating for requested changes: test structure update and using node …
SteveMacenski 4adc36d
adding requested updates from Tomoya
SteveMacenski f33f9a4
adding unit tests for negative cases
SteveMacenski 2e2f84e
rename to copy_all_paramter_values
SteveMacenski 0aa6f31
fix the depth to relative in list_parameters (#2300)
leeminju531 44fffbd
Decouple rosout publisher init from node init. (#2174)
fujitatomoya f3ba9b4
Documentation for list_parameters (#2315)
CursedRock17 ec3a3f4
Removing Old Connext Tests (#2313)
CursedRock17 71c691e
Update SignalHandler get_global_signal_handler to avoid complex types…
tfoote d0be8ad
Add locking to protect the TimeSource::NodeState::node_base_ (#2320)
clalancette e284387
Add missing header required by the rclcpp::NodeOptions type (#2324)
nachovizzo 12018db
Changelog.
clalancette 7dd2d62
23.1.0
clalancette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2023 Open Navigation LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef RCLCPP__COPY_ALL_PARAMETERS_HPP_ | ||
| #define RCLCPP__COPY_ALL_PARAMETERS_HPP_ | ||
|
|
||
| #include <vector> | ||
| #include <string> | ||
| #include "rcl_interfaces/srv/list_parameters.hpp" | ||
| #include "rclcpp/parameter.hpp" | ||
SteveMacenski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace rclcpp | ||
| { | ||
|
|
||
| /** | ||
| * @brief A method to copy all parameters from one node (parent) to another (child). | ||
| * May throw parameter exceptions in error conditions | ||
SteveMacenski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param parent Node to copy parameters from | ||
| * @param child Node to copy parameters to | ||
| */ | ||
SteveMacenski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| template<typename NodeT1, typename NodeT2> | ||
| void copy_all_parameters(const NodeT1 & parent, const NodeT2 & child) | ||
SteveMacenski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| using Parameters = std::vector<rclcpp::Parameter>; | ||
| std::vector<std::string> param_names = parent->list_parameters({}, 0).names; | ||
| Parameters params = parent->get_parameters(param_names); | ||
| for (Parameters::const_iterator iter = params.begin(); iter != params.end(); ++iter) { | ||
| if (!child->has_parameter(iter->get_name())) { | ||
wjwwood marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| child->declare_parameter(iter->get_name(), iter->get_parameter_value()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } // namespace rclcpp | ||
|
|
||
| #endif // RCLCPP__COPY_ALL_PARAMETERS_HPP_ | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright 2023 Open Navigation LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include "rclcpp/copy_all_parameters.hpp" | ||
| #include "rclcpp/rclcpp.hpp" | ||
|
|
||
| class RclCppFixture | ||
| { | ||
| public: | ||
| RclCppFixture() {rclcpp::init(0, nullptr);} | ||
| ~RclCppFixture() {rclcpp::shutdown();} | ||
| }; | ||
| RclCppFixture g_rclcppfixture; | ||
SteveMacenski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| TEST(TestParamCopying, TestParamCopying) | ||
| { | ||
| auto node1 = std::make_shared<rclcpp::Node>("test_node1"); | ||
| auto node2 = std::make_shared<rclcpp::Node>("test_node2"); | ||
|
|
||
| // Tests for (1) multiple types, (2) recursion, (3) overriding values | ||
| node1->declare_parameter("Foo1", rclcpp::ParameterValue(std::string(("bar1")))); | ||
| node1->declare_parameter("Foo2", rclcpp::ParameterValue(0.123)); | ||
| node1->declare_parameter("Foo", rclcpp::ParameterValue(std::string(("bar")))); | ||
| node1->declare_parameter("Foo.bar", rclcpp::ParameterValue(std::string(("steve")))); | ||
| node2->declare_parameter("Foo", rclcpp::ParameterValue(std::string(("barz2")))); | ||
|
|
||
| // Show Node2 is empty of Node1's parameters, but contains its own | ||
| EXPECT_FALSE(node2->has_parameter("Foo1")); | ||
| EXPECT_FALSE(node2->has_parameter("Foo2")); | ||
| EXPECT_FALSE(node2->has_parameter("Foo.bar")); | ||
| EXPECT_TRUE(node2->has_parameter("Foo")); | ||
| EXPECT_EQ(node2->get_parameter("Foo").as_string(), std::string("barz2")); | ||
|
|
||
| rclcpp::copy_all_parameters(node1, node2); | ||
|
|
||
| // Test new parameters exist, of expected value, and original param is not overridden | ||
| EXPECT_TRUE(node2->has_parameter("Foo1")); | ||
| EXPECT_EQ(node2->get_parameter("Foo1").as_string(), std::string("bar1")); | ||
| EXPECT_TRUE(node2->has_parameter("Foo2")); | ||
| EXPECT_EQ(node2->get_parameter("Foo2").as_double(), 0.123); | ||
| EXPECT_TRUE(node2->has_parameter("Foo.bar")); | ||
| EXPECT_EQ(node2->get_parameter("Foo.bar").as_string(), std::string("steve")); | ||
| EXPECT_TRUE(node2->has_parameter("Foo")); | ||
| EXPECT_EQ(node2->get_parameter("Foo").as_string(), std::string("barz2")); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.