-
Notifications
You must be signed in to change notification settings - Fork 115
TF prefix helper added #533
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
14ddfc3
1e39750
ea74c8f
b2fe32b
a192ad8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||
| // Copyright (c) 2025, ros2_control developers | ||||||
| // All rights reserved. | ||||||
| // | ||||||
| // Software License Agreement (BSD License 2.0) | ||||||
| // | ||||||
| // Redistribution and use in source and binary forms, with or without | ||||||
| // modification, are permitted provided that the following conditions | ||||||
| // are met: | ||||||
| // | ||||||
| // * Redistributions of source code must retain the above copyright | ||||||
| // notice, this list of conditions and the following disclaimer. | ||||||
| // * Redistributions in binary form must reproduce the above | ||||||
| // copyright notice, this list of conditions and the following | ||||||
| // disclaimer in the documentation and/or other materials provided | ||||||
| // with the distribution. | ||||||
| // * Neither the name of the Willow Garage nor the names of its | ||||||
| // contributors may be used to endorse or promote products derived | ||||||
| // from this software without specific prior written permission. | ||||||
| // | ||||||
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||||
| // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||||
| // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||||||
| // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||||||
| // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||||
| // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||||||
| // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||||||
| // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||||||
| // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||||
| // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||||||
| // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||||
| // POSSIBILITY OF SUCH DAMAGE. | ||||||
|
|
||||||
| #ifndef CONTROL_TOOLBOX__TF_UTILS_HPP_ | ||||||
| #define CONTROL_TOOLBOX__TF_UTILS_HPP_ | ||||||
|
|
||||||
| #include <string> | ||||||
|
|
||||||
| #include <rclcpp/rclcpp.hpp> | ||||||
|
|
||||||
| namespace control_toolbox | ||||||
| { | ||||||
| /** | ||||||
| * @brief Apply a TF prefix to a given frame. | ||||||
| * @param tf_prefix_enabled Whether to apply the TF prefix | ||||||
| * @param prefix TF prefix | ||||||
| * @param frame Frame name | ||||||
| * @param node_ns Node namespace to use as prefix if prefix is empty | ||||||
| * @return The prefixed frame name if prefix is not empty, otherwise the original frame name | ||||||
| */ | ||||||
| inline std::string apply_tf_prefix( | ||||||
| bool tf_prefix_enabled, std::string prefix, const std::string & node_ns, | ||||||
|
||||||
| bool tf_prefix_enabled, std::string prefix, const std::string & node_ns, | |
| bool tf_prefix_enabled, const std::string & prefix, const std::string & node_ns, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I'm unsure if it is better removing tf_prefix_enabled as an argument, but just use a pattern like tf_prefix_enabled ? apply_tf_prefix(...) : frame; on the calling site? something like apply_tf_prefix(false) feels a bit strange for me. what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes better sense to remove that. I'll do so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question about the slash normalization design. With the latest version of helper utilized in the controllers(diff, omni, mecanum), their tests succeeds. Currently, it only removes the leading and add one trailing slash to tf prefix. But what about cases when user put multiple slashes or leading slash in the namespace?
I got the test cases for these, is this expected behaviour?
EXPECT_EQ(control_toolbox::apply_tf_prefix("robot2//", "/ns", "odom"), "robot2//odom");
EXPECT_EQ(control_toolbox::apply_tf_prefix("robot", "/ns", "/odom"), "robot//odom");I can also make it ensure there is only one in between:
EXPECT_EQ(control_toolbox::apply_tf_prefix("robot2//", "/ns", "odom"), "robot2/odom");
EXPECT_EQ(control_toolbox::apply_tf_prefix("robot", "/ns", "/odom"), "robot/odom");
EXPECT_EQ(control_toolbox::apply_tf_prefix("robot/", "/ns", "/odom"), "robot/odom");So, shall i change the design or leave as it is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use the current behavior, so basically just copy it in this common helper file. Using something with double-slash does not make a lot of sense, but would be valid I guess. I suggest that we change that in a follow-up PR, and only on rolling.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright (c) 2025, ros2_control developers | ||
| // All rights reserved. | ||
| // | ||
| // Software License Agreement (BSD License 2.0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| // | ||
| // Redistribution and use in source and binary forms, with or without | ||
| // modification, are permitted provided that the following conditions | ||
| // are met: | ||
| // | ||
| // * Redistributions of source code must retain the above copyright | ||
| // notice, this list of conditions and the following disclaimer. | ||
| // * Redistributions in binary form must reproduce the above | ||
| // copyright notice, this list of conditions and the following | ||
| // disclaimer in the documentation and/or other materials provided | ||
| // with the distribution. | ||
| // * Neither the name of the Willow Garage nor the names of its | ||
| // contributors may be used to endorse or promote products derived | ||
| // from this software without specific prior written permission. | ||
| // | ||
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| // POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include "control_toolbox/tf_utils.hpp" | ||
|
|
||
| TEST(ApplyTFPrefixTest, DisabledPrefix) | ||
| { | ||
| EXPECT_EQ(control_toolbox::apply_tf_prefix(false, "", "/ns", "base_link"), "base_link"); | ||
| } | ||
|
|
||
| TEST(ApplyTFPrefixTest, EmptyExplicitUsesNamespace) | ||
| { | ||
| EXPECT_EQ(control_toolbox::apply_tf_prefix(true, "", "/my_ns", "odom"), "my_ns/odom"); | ||
| } | ||
|
|
||
| TEST(ApplyTFPrefixTest, ExplicitPrefixUsed) | ||
| { | ||
| EXPECT_EQ(control_toolbox::apply_tf_prefix(true, "robot1", "/ns", "base"), "robot1/base"); | ||
| } | ||
|
|
||
| TEST(ApplyTFPrefixTest, LeadingSlashRemoved) | ||
| { | ||
| EXPECT_EQ(control_toolbox::apply_tf_prefix(true, "/robot2", "/ns", "link"), "robot2/link"); | ||
| } | ||
|
|
||
| TEST(ApplyTFPrefixTest, TrailingSlashAdded) | ||
| { | ||
| EXPECT_EQ(control_toolbox::apply_tf_prefix(true, "robot3", "/ns", "odom"), "robot3/odom"); | ||
| } | ||
|
|
||
| TEST(ApplyTFPrefixTest, BothSlashesNormalized) | ||
| { | ||
| EXPECT_EQ( | ||
| control_toolbox::apply_tf_prefix(true, "/robot4/", "/ns", "base_link"), "robot4/base_link"); | ||
| } | ||
|
|
||
| TEST(ApplyTFPrefixTest, NodeNamespaceWithSlash) | ||
| { | ||
| EXPECT_EQ(control_toolbox::apply_tf_prefix(true, "", "/robot_ns/", "odom"), "robot_ns/odom"); | ||
| } | ||
|
|
||
| int main(int argc, char ** argv) | ||
| { | ||
| testing::InitGoogleTest(&argc, argv); | ||
| return RUN_ALL_TESTS(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that diff_drive_controller has the Apache-2 license, why have you chosen BSD here?