Skip to content

Commit cbd3730

Browse files
committed
extend tilde (~) substitution with node namespace to full prefix
1 parent 24f9e9b commit cbd3730

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

controller_interface/include/controller_interface/helpers.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ inline std::string resolve_tf_prefix(const std::string & prefix, const std::stri
108108
return std::string{};
109109
}
110110

111-
std::string nprefix = prefix == "~" ? node_ns : prefix;
111+
std::string nprefix = prefix;
112+
std::size_t pos = nprefix.find("~");
113+
if (pos != std::string::npos)
114+
{
115+
nprefix.replace(pos, 1, node_ns);
116+
}
112117

113118
// ensure trailing '/'
114119
if (nprefix.back() != '/')

controller_interface/test/test_controller_tf_prefix.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ TEST_F(TestControllerTFPrefix, EmptyPrefixReturnsEmpty)
2222
EXPECT_EQ(controller_interface::resolve_tf_prefix("", "/ns"), "");
2323
}
2424

25-
TEST_F(TestControllerTFPrefix, TildePrefixUsesNamespace)
26-
{
27-
EXPECT_EQ(controller_interface::resolve_tf_prefix("~", "/ns"), "ns/");
28-
EXPECT_EQ(controller_interface::resolve_tf_prefix("~", "/ns/"), "ns/");
29-
}
30-
3125
TEST_F(TestControllerTFPrefix, ExplicitPrefixUsed)
3226
{
3327
EXPECT_EQ(controller_interface::resolve_tf_prefix("robot", "/ns"), "robot/");
@@ -40,3 +34,11 @@ TEST_F(TestControllerTFPrefix, NormalizePrefixSlashes)
4034
EXPECT_EQ(controller_interface::resolve_tf_prefix("/robot3/", "/ns"), "robot3/");
4135
EXPECT_EQ(controller_interface::resolve_tf_prefix("/", "/ns"), "");
4236
}
37+
38+
TEST_F(TestControllerTFPrefix, TildePrefixResolvesToNamespace)
39+
{
40+
EXPECT_EQ(controller_interface::resolve_tf_prefix("~", "/ns"), "ns/");
41+
EXPECT_EQ(controller_interface::resolve_tf_prefix("~/", "/ns"), "ns/");
42+
EXPECT_EQ(controller_interface::resolve_tf_prefix("~/robot", "/ns"), "ns/robot/");
43+
EXPECT_EQ(controller_interface::resolve_tf_prefix("/~/robot/", "ns"), "ns/robot/");
44+
}

0 commit comments

Comments
 (0)