Allow FixedRatioSampler to drop all data. (#817)

This is useful to disable loop closure by setting
constraint_builder.sampling_ratio = 0.
master
Wolfgang Hess 2018-01-12 18:54:41 +01:00 committed by Wally B. Feed
parent 1de696d45f
commit 19ff047a79
2 changed files with 9 additions and 2 deletions

View File

@ -22,7 +22,8 @@ namespace cartographer {
namespace common { namespace common {
FixedRatioSampler::FixedRatioSampler(const double ratio) : ratio_(ratio) { 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.); CHECK_LE(ratio, 1.);
} }

View File

@ -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) { TEST(FixedRatioSamplerTest, NonSensicalRatio) {
EXPECT_DEATH(FixedRatioSampler(0.), "ratio");
EXPECT_DEATH(FixedRatioSampler(2.), "ratio"); EXPECT_DEATH(FixedRatioSampler(2.), "ratio");
EXPECT_DEATH(FixedRatioSampler(-0.1), "ratio"); EXPECT_DEATH(FixedRatioSampler(-0.1), "ratio");
} }