diff --git a/beluga/include/beluga/algorithm/resampling_rate_policies/selective_resampling_policy.hpp b/beluga/include/beluga/algorithm/resampling_rate_policies/selective_resampling_policy.hpp index da7c1db3b..fe6ece536 100644 --- a/beluga/include/beluga/algorithm/resampling_rate_policies/selective_resampling_policy.hpp +++ b/beluga/include/beluga/algorithm/resampling_rate_policies/selective_resampling_policy.hpp @@ -17,6 +17,9 @@ #include +#include +#include + #include namespace beluga { @@ -27,9 +30,11 @@ struct SelectiveResamplingPolicy : public Mixin { template explicit SelectiveResamplingPolicy(Args&&... rest) : Mixin(std::forward(rest)...) {} - [[nodiscard]] bool romp_do_resampling() const { - // TODO(unknown): missing implementation - return true; + [[nodiscard]] bool srp_do_resampling() const { + const auto n_eff = + ranges::accumulate(this->self().weights() | ranges::views::transform([](const auto w) { return w * w; }), 0.); + const auto n = static_cast(std::size(this->self().weights())); + return n_eff < n / 2.; } }; diff --git a/beluga/include/beluga/motion/differential_drive_model.hpp b/beluga/include/beluga/motion/differential_drive_model.hpp index 6310432e2..a5fc5bd4e 100644 --- a/beluga/include/beluga/motion/differential_drive_model.hpp +++ b/beluga/include/beluga/motion/differential_drive_model.hpp @@ -146,7 +146,6 @@ class DifferentialDriveModel : public Mixin { last_pose_ = pose; // TODO(unknown): this logic should not be in the differential drive model, since it's shared by other models. - // notify observers about the pose update this->self().romp_update_motion(pose); } diff --git a/beluga/include/beluga/runtime_dispatch/runtime_dispatch.hpp b/beluga/include/beluga/runtime_dispatch/runtime_dispatch.hpp index 15e806871..878d9f31c 100644 --- a/beluga/include/beluga/runtime_dispatch/runtime_dispatch.hpp +++ b/beluga/include/beluga/runtime_dispatch/runtime_dispatch.hpp @@ -42,7 +42,7 @@ struct RuntimeDispatch : public Mixin { voters_.push_back([this] { return this->self().romp_do_resampling(); }); // resample-on-move policy if (configuration_.selective_resampling) { - voters_.push_back([this] { return this->self().srp_do_resample(); }); // selective resampling policy + voters_.push_back([this] { return this->self().srp_do_resampling(); }); // selective resampling policy } } diff --git a/beluga/test/beluga/CMakeLists.txt b/beluga/test/beluga/CMakeLists.txt index 489e7acfb..a65bdc6db 100644 --- a/beluga/test/beluga/CMakeLists.txt +++ b/beluga/test/beluga/CMakeLists.txt @@ -10,6 +10,7 @@ ament_add_gmock(test_beluga random/test_multivariate_normal_distribution.cpp resampling_rate_policies/test_resample_interval_policy.cpp resampling_rate_policies/test_resample_on_motion_policy.cpp + resampling_rate_policies/test_selective_resampling_policy.cpp runtime_dispatch/test_runtime_dispatch.cpp sensor/test_likelihood_field_model.cpp test_tuple_vector.cpp diff --git a/beluga/test/beluga/motion/test_differential_drive_model.cpp b/beluga/test/beluga/motion/test_differential_drive_model.cpp index 3c47649e9..e0e98e55a 100644 --- a/beluga/test/beluga/motion/test_differential_drive_model.cpp +++ b/beluga/test/beluga/motion/test_differential_drive_model.cpp @@ -34,13 +34,15 @@ class MockMixin : public ciabatta::mixin, Mixin> { public: using ciabatta::mixin, Mixin>::mixin; - void romp_update_motion([[maybe_unused]] const Sophus::SE2d& current_pose) {} + MOCK_METHOD(void, romp_update_motion, (const Sophus::SE2d&)); }; class DifferentialDriveModelTest : public ::testing::Test { protected: MockMixin mixin_{ beluga::DifferentialDriveModelParam{0.0, 0.0, 0.0, 0.0}}; // No variance + + void SetUp() override { EXPECT_CALL(mixin_, romp_update_motion(::testing::_)).WillRepeatedly(::testing::Return()); } }; TEST_F(DifferentialDriveModelTest, NoUpdate) { diff --git a/beluga/test/beluga/resampling_rate_policies/test_resample_interval_policy.cpp b/beluga/test/beluga/resampling_rate_policies/test_resample_interval_policy.cpp index 08fa91acd..d5ae5fde3 100644 --- a/beluga/test/beluga/resampling_rate_policies/test_resample_interval_policy.cpp +++ b/beluga/test/beluga/resampling_rate_policies/test_resample_interval_policy.cpp @@ -14,8 +14,6 @@ #include -#include - #include #include diff --git a/beluga/test/beluga/resampling_rate_policies/test_selective_resampling_policy.cpp b/beluga/test/beluga/resampling_rate_policies/test_selective_resampling_policy.cpp new file mode 100644 index 000000000..80a0399d7 --- /dev/null +++ b/beluga/test/beluga/resampling_rate_policies/test_selective_resampling_policy.cpp @@ -0,0 +1,75 @@ +// Copyright 2023 Ekumen, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +#include + +#include +#include +#include + +#include + +namespace beluga { + +namespace { + +template