Skip to content

Commit

Permalink
Refactor with latest iteration of design based on Ivan's proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
glpuga committed Mar 4, 2023
1 parent 4eab9b4 commit 1840182
Show file tree
Hide file tree
Showing 22 changed files with 552 additions and 424 deletions.
21 changes: 21 additions & 0 deletions beluga/docs/doxygen_cites.bib
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ @book{thrun2005probabilistic
year={2005},
publisher={MIT Press}
}

@ARTICLE{grisetti2007selectiveresampling,
author={Grisetti, Giorgio and Stachniss, Cyrill and Burgard, Wolfram},
journal={IEEE Transactions on Robotics},
title={Improved Techniques for Grid Mapping With Rao-Blackwellized Particle Filters},
year={2007},
volume={23},
number={1},
pages={34-46},
doi={10.1109/TRO.2006.889486}
}

@ARTICLE{tiacheng2015resamplingmethods,
author={Li, Tiancheng and Bolic, Miodrag and Djuric, Petar M.},
journal={IEEE Signal Processing Magazine},
title={Resampling Methods for Particle Filtering: Classification, implementation, and strategies},
year={2015},
volume={32},
number={3},
pages={70-86},
doi={10.1109/MSP.2014.2330626}}
41 changes: 21 additions & 20 deletions beluga/include/beluga/algorithm/particle_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
#include <range/v3/algorithm/transform.hpp>
#include <range/v3/view/const.hpp>

#include <beluga/algorithm/resampling_policies/resample_interval_policy.hpp>
#include <beluga/algorithm/resampling_policies/resample_on_motion_policy.hpp>
#include <beluga/algorithm/resampling_policies/resampling_policy_poller.hpp>
#include <beluga/algorithm/resampling_policies/selective_resampling_policy.hpp>
#include <beluga/algorithm/sampling.hpp>
#include <beluga/resampling_policies/resample_interval_policy.hpp>
#include <beluga/resampling_policies/resample_on_motion_policy.hpp>
#include <beluga/resampling_policies/resampling_policies_poller.hpp>
#include <beluga/resampling_policies/selective_resampling_policy.hpp>
#include <beluga/tuple_vector.hpp>
#include <beluga/type_traits.hpp>

Expand Down Expand Up @@ -90,6 +90,7 @@
* The following is satisfied:
* - `p.particles()` is valid and returns a view to a container that satisfies the
* \ref ParticleContainerPage "ParticleContainer" requirements.
* - `p.weights()` is valid and returns a view to a container to the weights of the particles.
* - `p.sample()` updates the particle filter particles based on the last motion update.
* - `p.importance_sample()` updates the particle filter particles weight.
* - `p.resample()` updates the particle filter, generating new particles from the old ones
Expand Down Expand Up @@ -294,10 +295,11 @@ struct MCL : public ciabatta::mixin<
ciabatta::curry<BaselineGeneration>::template mixin,
ciabatta::curry<NaiveGeneration>::template mixin,
ciabatta::curry<FixedResampling>::template mixin,
ciabatta::curry<ResampleOnMotionPolicy>::template mixin,
ciabatta::curry<ResampleIntervalPolicy>::template mixin,
ciabatta::curry<SelectiveResamplingPolicy>::template mixin,
ciabatta::curry<ResamplingPolicyPoller>::template mixin,
ciabatta::curry<
ResamplingPoliciesPoller,
ResampleOnMotionPolicy,
ResampleIntervalPolicy,
SelectiveResamplingPolicy>::template mixin,
MotionModel,
SensorModel> {
using ciabatta::mixin<
Expand All @@ -306,10 +308,9 @@ struct MCL : public ciabatta::mixin<
ciabatta::curry<BaselineGeneration>::template mixin,
ciabatta::curry<NaiveGeneration>::template mixin,
ciabatta::curry<FixedResampling>::template mixin,
ciabatta::curry<ResampleOnMotionPolicy>::template mixin,
ciabatta::curry<ResampleIntervalPolicy>::template mixin,
ciabatta::curry<SelectiveResamplingPolicy>::template mixin,
ciabatta::curry<ResamplingPolicyPoller>::template mixin,
ciabatta::
curry<ResamplingPoliciesPoller, ResampleOnMotionPolicy, ResampleIntervalPolicy, SelectiveResamplingPolicy>::
mixin,
MotionModel,
SensorModel>::mixin;
};
Expand Down Expand Up @@ -338,10 +339,11 @@ struct AMCL : public ciabatta::mixin<
ciabatta::curry<BaselineGeneration>::template mixin,
ciabatta::curry<AdaptiveGeneration>::template mixin,
ciabatta::curry<KldResampling>::template mixin,
ciabatta::curry<ResampleOnMotionPolicy>::template mixin,
ciabatta::curry<ResampleIntervalPolicy>::template mixin,
ciabatta::curry<SelectiveResamplingPolicy>::template mixin,
ciabatta::curry<ResamplingPolicyPoller>::template mixin,
ciabatta::curry<
ResamplingPoliciesPoller,
ResampleOnMotionPolicy,
ResampleIntervalPolicy,
SelectiveResamplingPolicy>::template mixin,
MotionModel,
SensorModel> {
using ciabatta::mixin<
Expand All @@ -350,10 +352,9 @@ struct AMCL : public ciabatta::mixin<
ciabatta::curry<BaselineGeneration>::template mixin,
ciabatta::curry<AdaptiveGeneration>::template mixin,
ciabatta::curry<KldResampling>::template mixin,
ciabatta::curry<ResampleOnMotionPolicy>::template mixin,
ciabatta::curry<ResampleIntervalPolicy>::template mixin,
ciabatta::curry<SelectiveResamplingPolicy>::template mixin,
ciabatta::curry<ResamplingPolicyPoller>::template mixin,
ciabatta::
curry<ResamplingPoliciesPoller, ResampleOnMotionPolicy, ResampleIntervalPolicy, SelectiveResamplingPolicy>::
template mixin,
MotionModel,
SensorModel>::mixin;
};
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions beluga/include/beluga/beluga.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <beluga/algorithm.hpp>
#include <beluga/motion.hpp>
#include <beluga/resampling_policies.hpp>
#include <beluga/sensor.hpp>
#include <beluga/tuple_vector.hpp>
#include <beluga/type_traits.hpp>
Expand Down
46 changes: 46 additions & 0 deletions beluga/include/beluga/resampling_policies.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2022 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.

#ifndef BELUGA_RESAMPLING_POLICIES_HPP
#define BELUGA_RESAMPLING_POLICIES_HPP

#include <beluga/resampling_policies/resample_interval_policy.hpp>
#include <beluga/resampling_policies/resample_on_motion_policy.hpp>
#include <beluga/resampling_policies/resampling_policies_poller.hpp>
#include <beluga/resampling_policies/selective_resampling_policy.hpp>

/**
* \file
* \brief Includes all resampling policy related headers.
*/

/**
* \page ResamplePolicyPage beluga named requirements: ResamplePolicy
* Requirements for a resampling policy to be used a beluga `ParticleFilter`.
*
* \section ResamplePolicyRequirements Requirements
* A type `T` satisfies the `ResamplePolicy` requirements if the following is satisfied.
*
* Given:
* - An instance `p` of `T`.
* - An instance `c` of `C`, where is a particle filter that meets the requirements listed in the policy.
*
* Then:
* - `p.do_resampling(c)` will return true if resampling must be done according to the policy, false otherwise. This
* function is called in cascade when multiple policies are installed in the filter, and a given filters do_resampling()
* function may not be called if a previously queried policy has already voted "false" (short-circuit evaluation of
* policies).
* */

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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.

#ifndef BELUGA_RESAMPLING_POLICIES_RESAMPLE_INTERVAL_POLICY_HPP
#define BELUGA_RESAMPLING_POLICIES_RESAMPLE_INTERVAL_POLICY_HPP

#include <optional>

#include <beluga/type_traits/resampling_policy_traits.hpp>

namespace beluga {

/// Parameters used to construct a ResampleIntervalPolicy instance.
struct ResampleIntervalPolicyParam {
/// Interval of calls to do_resampling() out of which only the last iteration will do resampling.
std::size_t resample_interval_count{1};
};

/// Implementation of the Resample Interval algorithm for resampling.
/**
* ResampleIntervalPolicy is an implementation of the \ref ResamplePolicyPage "ResamplePolicy" named requirements.
* */
struct ResampleIntervalPolicy {
public:
/// Parameter type that the constructor uses to configure the policy
using param_type = ResampleIntervalPolicyParam;

/// @brief Constructor
/// @param configuration Policy configuration data.
explicit ResampleIntervalPolicy(const param_type& configuration) : configuration_{configuration} {}

/// Vote whether resampling must be done according to this policy./
/**
* \tparam Concrete Type representing the concrete implementation of the filter.
*/
template <typename Concrete>
[[nodiscard]] bool do_resampling([[maybe_unused]] Concrete& filter) {
filter_update_counter_ = (filter_update_counter_ + 1) % configuration_.resample_interval_count;
return (filter_update_counter_ == 0);
}

private:
param_type configuration_; //< Policy configuration
std::size_t filter_update_counter_{0}; //< Current cycle phase
};

/// Specialization for a ResampleIntervalPolicy, see also \ref resampling_policy_traits.hpp.
template <>
struct resampling_policy_traits<ResampleIntervalPolicy> {
/// configuration struct type associated to the policy
using config_type = ResampleIntervalPolicyParam;
};

} // namespace beluga

#endif
Loading

0 comments on commit 1840182

Please sign in to comment.