Skip to content
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

Fix SerializedPublisher not being able to read it's parameters #311

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fuse_core/include/fuse_core/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
17 changes: 17 additions & 0 deletions fuse_core/src/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions fuse_core/test/test_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
18 changes: 14 additions & 4 deletions fuse_publishers/src/serialized_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down