diff --git a/fuse_core/include/fuse_core/parameter.hpp b/fuse_core/include/fuse_core/parameter.hpp index 507def3d5..bab6bcecf 100644 --- a/fuse_core/include/fuse_core/parameter.hpp +++ b/fuse_core/include/fuse_core/parameter.hpp @@ -49,6 +49,9 @@ namespace fuse_core { +// Helper function to get a namespace string with a '.' suffix, but only if not empty +std::string joinParameterName(const std::string & left, const std::string & right); + // NOTE(CH3): Some of these basically mimic the behavior from rclcpp's node.hpp, but for interfaces /** diff --git a/fuse_core/src/parameter.cpp b/fuse_core/src/parameter.cpp index aa272c50c..a2d01a2d7 100644 --- a/fuse_core/src/parameter.cpp +++ b/fuse_core/src/parameter.cpp @@ -83,4 +83,21 @@ detail::list_parameter_override_prefixes( } return output_names; } + +std::string joinParameterName(const std::string & left, const std::string & right) +{ + if (left.empty()) { + return right; + } + if (right.empty()) { + return left; + } + if ('.' != left.back() && '.' != right.front() ) { + return left + '.' + right; + } + if ('.' == left.back() && '.' == right.front()) { + return left + right.substr(1); + } + return left + right; +} } // namespace fuse_core diff --git a/fuse_core/test/test_parameter.cpp b/fuse_core/test/test_parameter.cpp index cce8db2c9..bc334ede5 100644 --- a/fuse_core/test/test_parameter.cpp +++ b/fuse_core/test/test_parameter.cpp @@ -95,3 +95,13 @@ TEST(parameter, list_parameter_override_prefixes) EXPECT_NE(matches.end(), matches.find("baz")); } } + +TEST(parameter, joinParameterName) +{ + EXPECT_EQ("foo.bar", fuse_core::joinParameterName("foo", "bar")); + EXPECT_EQ("foo.bar", fuse_core::joinParameterName("foo.", "bar")); + EXPECT_EQ("foo.bar", fuse_core::joinParameterName("foo", ".bar")); + EXPECT_EQ("foo.bar", fuse_core::joinParameterName("foo.", ".bar")); + EXPECT_EQ("foo", fuse_core::joinParameterName("foo", "")); + EXPECT_EQ("bar", fuse_core::joinParameterName("", "bar")); +} diff --git a/fuse_publishers/src/serialized_publisher.cpp b/fuse_publishers/src/serialized_publisher.cpp index 174c5adb6..153bb9eb2 100644 --- a/fuse_publishers/src/serialized_publisher.cpp +++ b/fuse_publishers/src/serialized_publisher.cpp @@ -69,17 +69,27 @@ void SerializedPublisher::initialize( void SerializedPublisher::onInit() { // Configure the publisher - frame_id_ = fuse_core::getParam(interfaces_, "frame_id", frame_id_); + frame_id_ = fuse_core::getParam( + interfaces_, + fuse_core::joinParameterName(name_, "frame_id"), frame_id_); bool latch = false; - latch = fuse_core::getParam(interfaces_, "latch", latch); + latch = fuse_core::getParam( + interfaces_, + fuse_core::joinParameterName(name_, "latch"), latch); rclcpp::Duration graph_throttle_period{0, 0}; - fuse_core::getPositiveParam(interfaces_, "graph_throttle_period", graph_throttle_period, false); + fuse_core::getPositiveParam( + interfaces_, + fuse_core::joinParameterName(name_, "graph_throttle_period"), + graph_throttle_period, false); bool graph_throttle_use_wall_time{false}; graph_throttle_use_wall_time = - fuse_core::getParam(interfaces_, "graph_throttle_use_wall_time", graph_throttle_use_wall_time); + fuse_core::getParam( + interfaces_, + fuse_core::joinParameterName(name_, "graph_throttle_use_wall_time"), + graph_throttle_use_wall_time); graph_publisher_throttled_callback_.setThrottlePeriod(graph_throttle_period);