Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Use rclcpp::NodeOptions during node construction #73

Merged
merged 8 commits into from Jan 17, 2020

Conversation

mm318
Copy link
Member

@mm318 mm318 commented Jan 15, 2020

In order to support composeable nodes, the configurations for the node need to come from the rclcpp::NodeOptions as opposed to from C++ parameters in code.

@mm318
Copy link
Member Author

mm318 commented Jan 15, 2020

Still need to fix some minor unit test failures.

Copy link
Member

@thomas-moulard thomas-moulard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM - a few nits.

Why do we need to rename the topic? I think we can remove kTestTopic and use the real topic, no?

@@ -104,7 +122,7 @@ std::string PeriodicMeasurementNode::GetStatusString() const
std::stringstream ss;
ss << "name=" << get_name() <<
", measurement_period=" << std::to_string(measurement_period_.count()) << "ms" <<
", publishing_topic=" << publishing_topic_ <<
", publishing_topic=" << ((publisher_ == nullptr) ? "" : publisher_->get_topic_name()) <<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .hpp still has publishing_topic_. Why tie displaying the topic to the node state?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If displaying the topic doesn't depend on the node state, then when the user does topic name remapping, the output is technically wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be simplified to publisher_ ? publisher_->get_topic_name() : ""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* The period used to publish measurement data
*/
const std::chrono::milliseconds publish_period_;
std::chrono::milliseconds publish_period_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value is coming from the parameters and stored here. Is your idea that the parameters values should be read at Start() and not stored, so that each Stop()->Start() cycle might have updated/different parameter values?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is the wrong line. I meant for line 107 (std::string publishing_topic_;). Mainly because there is a change with the status string that does not used publishing_topic_.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I removed the publishing_topic_ member variable.

@@ -130,8 +142,17 @@ constexpr std::chrono::milliseconds PeriodicMeasurementTestFixure::kDontPublishD

TEST_F(PeriodicMeasurementTestFixure, Sanity) {
ASSERT_NE(test_periodic_measurer_, nullptr);

ASSERT_EQ("name=test_periodic_node, measurement_period=50ms,"
" publishing_topic=, publish_period=500ms, started=false,"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty publishing_topic isn't indicative of what was actually set. I'm not a fan of this change. If we want to tie it to publisher state then I would only display when started.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, changed this test to call Start() on the measurement node beforehand.

@dabonnie
Copy link
Contributor

Why do we need to rename the topic? I think we can remove kTestTopic and use the real topic, no?

I agree with this, since it seems redundant to test the ROS2 parameter code.

@mm318
Copy link
Member Author

mm318 commented Jan 16, 2020

Why do we need to rename the topic? I think we can remove kTestTopic and use the real topic, no?

I have removed the remapping of the publishing topic to kTestTopic.

@@ -68,7 +75,8 @@ bool PeriodicMeasurementNode::SetupStart()
measurement_period_, [this]() {this->PerformPeriodicMeasurement();});

if (publisher_ == nullptr) {
publisher_ = create_publisher<MetricsMessage>(publishing_topic_, 10 /*history_depth*/);
publisher_ = create_publisher<MetricsMessage>(collector_node_constants::kStatisticsTopicName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you're doing now. Why aren't we keeping the member? This PR is actually removing functionality where we could pull the publishing topic out of NodeOptions. The work required seems minimal and I don't see why we can't do it, as a read only parameter, here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is actually removing functionality where we could pull the publishing topic out of NodeOptions.

I was going to do that, too, but this is what @thomas-moulard suggested under on the same rationale as the node name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took @thomas-moulard 's comment to mean we don't need to set and test a custom topic name in test. I'm going to follow up with him as we've discussed allowing a user to configure the topic name.

Copy link
Member Author

@mm318 mm318 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed in the team chatroom. Topic name will be configured via remapping (--ros-args --remap system_metrics:=custom_topic_name).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--ros-args --remap

Got it, found this explanation: https://index.ros.org/doc/ros2/Tutorials/Node-arguments/#example

Copy link
Contributor

@piraka9011 piraka9011 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM

@@ -25,10 +26,11 @@ namespace collector_node_constants
constexpr const char kStatisticsTopicName[] = "system_metrics";

constexpr const char kCollectPeriodParam[] = "measurement_period";
constexpr const int64_t kDefaultCollectPeriodInMs = 1000; // 1 second
constexpr const std::chrono::milliseconds kDefaultCollectPeriod{1000}; // 1 second

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this still in milliseconds when the delay is now 1 second?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to get the count() in milliseconds at some point.

@dabonnie dabonnie merged commit f7e368c into master Jan 17, 2020
@dabonnie dabonnie deleted the miaofei/use-node-options branch January 17, 2020 00:11
@dabonnie
Copy link
Contributor

Build successful but codecov still broken. FYI @ros2/aws-oncall

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants