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

Commit

Permalink
remove clear_measurements_on_publish
Browse files Browse the repository at this point in the history
  • Loading branch information
mm318 committed Dec 11, 2019
1 parent 9391954 commit eec0dec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ PeriodicMeasurementNode::PeriodicMeasurementNode(
const std::string & name,
const std::chrono::milliseconds measurement_period,
const std::string & publishing_topic,
const std::chrono::milliseconds publish_period,
const bool clear_measurements_on_publish)
const std::chrono::milliseconds publish_period)
: Node(name),
measurement_period_(measurement_period),
publishing_topic_(publishing_topic),
measurement_timer_(nullptr),
publish_timer_(nullptr),
publish_period_(publish_period),
clear_measurements_on_publish_(clear_measurements_on_publish)
publish_period_(publish_period)
{
if (publish_period_ <= std::chrono::milliseconds(0)) {
throw std::invalid_argument("publish period cannot be negative");
Expand All @@ -62,10 +60,8 @@ bool PeriodicMeasurementNode::setupStart()
publish_timer_ = this->create_wall_timer(
publish_period_, [this]() {
this->publishStatisticMessage();
if (this->clear_measurements_on_publish_) {
this->clearCurrentMeasurements();
this->window_start_ = this->now();
}
this->clearCurrentMeasurements();
this->window_start_ = this->now();
});

window_start_ = now();
Expand Down Expand Up @@ -95,7 +91,6 @@ std::string PeriodicMeasurementNode::getStatusString() const
", measurement_period=" << std::to_string(measurement_period_.count()) << "ms" <<
", publishing_topic=" << publishing_topic_ <<
", publish_period=" << std::to_string(publish_period_.count()) + "ms" <<
", clear_measurements_on_publish_=" << clear_measurements_on_publish_ <<
", " << Collector::getStatusString();
return ss.str();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class PeriodicMeasurementNode : public system_metrics_collector::Collector,
const std::string & name,
const std::chrono::milliseconds measurement_period,
const std::string & topic, // todo @dbbonnie think about a default topic
const std::chrono::milliseconds publish_period,
const bool clear_measurements_on_publish = true);
const std::chrono::milliseconds publish_period);

virtual ~PeriodicMeasurementNode() = default;

Expand Down Expand Up @@ -118,10 +117,6 @@ class PeriodicMeasurementNode : public system_metrics_collector::Collector,
* The period used to publish measurement data
*/
const std::chrono::milliseconds publish_period_;
/**
* If true, then measurements are cleared after publishing data
*/
const bool clear_measurements_on_publish_;

rclcpp::TimerBase::SharedPtr measurement_timer_;
rclcpp::TimerBase::SharedPtr publish_timer_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ class TestPeriodicMeasurementNode : public ::system_metrics_collector::PeriodicM
const std::string & name,
const std::chrono::milliseconds measurement_period,
const std::string & publishing_topic,
const std::chrono::milliseconds publish_period,
const bool clear_measurements_on_publish)
: PeriodicMeasurementNode(name, measurement_period, publishing_topic, publish_period,
clear_measurements_on_publish)
{}
const std::chrono::milliseconds publish_period)
: PeriodicMeasurementNode(name, measurement_period, publishing_topic, publish_period) {}
virtual ~TestPeriodicMeasurementNode() = default;

int getNumPublished() const
Expand Down Expand Up @@ -99,7 +96,7 @@ class PeriodicMeasurementTestFixure : public ::testing::Test
rclcpp::init(0, nullptr);

test_periodic_measurer = std::make_shared<TestPeriodicMeasurementNode>(TEST_NODE_NAME,
test_constants::MEASURE_PERIOD, TEST_TOPIC, test_constants::PUBLISH_PERIOD, false);
test_constants::MEASURE_PERIOD, TEST_TOPIC, INFREQUENT_PUBLISH_PERIOD);

ASSERT_FALSE(test_periodic_measurer->isStarted());

Expand All @@ -120,14 +117,17 @@ class PeriodicMeasurementTestFixure : public ::testing::Test
}

protected:
static constexpr std::chrono::milliseconds INFREQUENT_PUBLISH_PERIOD = 2 *
test_constants::TEST_DURATION;
std::shared_ptr<TestPeriodicMeasurementNode> test_periodic_measurer;
};

constexpr std::chrono::milliseconds PeriodicMeasurementTestFixure::INFREQUENT_PUBLISH_PERIOD;

TEST_F(PeriodicMeasurementTestFixure, sanity) {
ASSERT_NE(test_periodic_measurer, nullptr);
ASSERT_EQ("name=test_periodic_node, measurement_period=50ms,"
" publishing_topic=test_topic, publish_period=80ms,"
" clear_measurements_on_publish_=0, started=false,"
" publishing_topic=test_topic, publish_period=500ms, started=false,"
" avg=nan, min=nan, max=nan, std_dev=nan, count=0",
test_periodic_measurer->getStatusString());
}
Expand Down Expand Up @@ -163,8 +163,7 @@ TEST_F(PeriodicMeasurementTestFixure, test_start_and_stop) {

int times_published = test_periodic_measurer->getNumPublished();
ASSERT_EQ(
test_constants::TEST_DURATION.count() / test_constants::PUBLISH_PERIOD.count(),
times_published);
test_constants::TEST_DURATION.count() / INFREQUENT_PUBLISH_PERIOD.count(), times_published);
}

int main(int argc, char ** argv)
Expand Down

0 comments on commit eec0dec

Please sign in to comment.