From 19ff047a791d1abe27b044c716cd34b77ed17ab7 Mon Sep 17 00:00:00 2001 From: Wolfgang Hess Date: Fri, 12 Jan 2018 18:54:41 +0100 Subject: [PATCH] Allow FixedRatioSampler to drop all data. (#817) This is useful to disable loop closure by setting constraint_builder.sampling_ratio = 0. --- cartographer/common/fixed_ratio_sampler.cc | 3 ++- cartographer/common/fixed_ratio_sampler_test.cc | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cartographer/common/fixed_ratio_sampler.cc b/cartographer/common/fixed_ratio_sampler.cc index ec164e0..690854d 100644 --- a/cartographer/common/fixed_ratio_sampler.cc +++ b/cartographer/common/fixed_ratio_sampler.cc @@ -22,7 +22,8 @@ namespace cartographer { namespace common { FixedRatioSampler::FixedRatioSampler(const double ratio) : ratio_(ratio) { - CHECK_GT(ratio, 0.); + CHECK_GE(ratio, 0.); + LOG_IF(WARNING, ratio == 0.) << "FixedRatioSampler is dropping all data."; CHECK_LE(ratio, 1.); } diff --git a/cartographer/common/fixed_ratio_sampler_test.cc b/cartographer/common/fixed_ratio_sampler_test.cc index fdcfdc5..ccd716f 100644 --- a/cartographer/common/fixed_ratio_sampler_test.cc +++ b/cartographer/common/fixed_ratio_sampler_test.cc @@ -29,8 +29,14 @@ TEST(FixedRatioSamplerTest, AlwaysTrue) { } } +TEST(FixedRatioSamplerTest, AlwaysFalse) { + FixedRatioSampler fixed_ratio_sampler(0.); + for (int i = 0; i < 100; ++i) { + EXPECT_FALSE(fixed_ratio_sampler.Pulse()); + } +} + TEST(FixedRatioSamplerTest, NonSensicalRatio) { - EXPECT_DEATH(FixedRatioSampler(0.), "ratio"); EXPECT_DEATH(FixedRatioSampler(2.), "ratio"); EXPECT_DEATH(FixedRatioSampler(-0.1), "ratio"); }