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

Added publish period attribute as a parameter #71

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ PeriodicMeasurementNode::PeriodicMeasurementNode(
throw std::invalid_argument{"publishing_topic cannot be empty"};
}

if (publish_period <= std::chrono::milliseconds{0}) {
int publish_period_param = 0;
rcl_interfaces::msg::ParameterDescriptor descriptor;
descriptor.read_only = true;
declare_parameter("publish_period", publish_period_.count(), descriptor);
Copy link

Choose a reason for hiding this comment

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

Nit: It might be useful to extract "publish_period" into a constant

if (get_parameter("publish_period", publish_period_param)) {
publish_period_ = std::chrono::milliseconds(publish_period_param);

Choose a reason for hiding this comment

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

Suggested change
publish_period_ = std::chrono::milliseconds(publish_period_param);
publish_period_ = std::chrono::milliseconds{publish_period_param};

}

if (publish_period_ <= std::chrono::milliseconds{0}) {
throw std::invalid_argument{"publish_period cannot be negative"};
}

if (publish_period <= measurement_period) {
if (publish_period_ <= measurement_period) {
throw std::invalid_argument{
"publish_period cannot be less than or equal to the measurement_period"};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class PeriodicMeasurementNode : public system_metrics_collector::Collector,
/**
* The period used to publish measurement data
*/
const std::chrono::milliseconds publish_period_;
std::chrono::milliseconds publish_period_;

rclcpp::TimerBase::SharedPtr measurement_timer_;
rclcpp::TimerBase::SharedPtr publish_timer_;
Expand Down