forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(mpf::predictor) resampling interval control in out of resamp…
…ler (autowarefoundation#20) * resampling interval management should be done out of resample() Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp> * resampler class throw exeption rather than optional Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp> * split files for resampling_history Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp> * split files for experimental/suspention_adaptor Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp> --------- Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp>
- Loading branch information
Showing
7 changed files
with
260 additions
and
235 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...filter/include/modularized_particle_filter/prediction/experimental/suspension_adaptor.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2023 TIER IV, 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. | ||
|
||
#pragma once | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp> | ||
#include <sensor_msgs/msg/image.hpp> | ||
|
||
#include <optional> | ||
|
||
namespace pcdless::modularized_particle_filter | ||
{ | ||
struct SwapModeAdaptor | ||
{ | ||
using Image = sensor_msgs::msg::Image; | ||
using PoseCovStamped = geometry_msgs::msg::PoseWithCovarianceStamped; | ||
|
||
SwapModeAdaptor(rclcpp::Node * node) : logger_(rclcpp::get_logger("swap_adaptor")) | ||
{ | ||
auto on_ekf_pose = [this](const PoseCovStamped & pose) -> void { init_pose_opt_ = pose; }; | ||
auto on_image = [this](const Image & msg) -> void { | ||
stamp_opt_ = rclcpp::Time(msg.header.stamp); | ||
}; | ||
|
||
sub_image_ = node->create_subscription<Image>("image", 1, on_image); | ||
sub_pose_ = node->create_subscription<PoseCovStamped>("pose_cov", 1, on_ekf_pose); | ||
clock_ = node->get_clock(); | ||
|
||
state_is_active = false; | ||
state_is_activating = false; | ||
} | ||
|
||
std::optional<rclcpp::Time> stamp_opt_{std::nullopt}; | ||
std::optional<PoseCovStamped> init_pose_opt_{std::nullopt}; | ||
rclcpp::Subscription<PoseCovStamped>::SharedPtr sub_pose_; | ||
rclcpp::Subscription<Image>::SharedPtr sub_image_; | ||
rclcpp::Clock::SharedPtr clock_; | ||
rclcpp::Logger logger_; | ||
|
||
bool state_is_active; | ||
bool state_is_activating; | ||
|
||
PoseCovStamped init_pose() { return init_pose_opt_.value(); } | ||
|
||
bool should_call_initialize() | ||
{ | ||
if (state_is_activating && init_pose_opt_.has_value()) { | ||
if (!state_is_active) { | ||
state_is_active = true; | ||
state_is_activating = false; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool should_keep_update() | ||
{ | ||
if (!stamp_opt_.has_value()) { | ||
RCLCPP_INFO_STREAM_THROTTLE(logger_, *clock_, 1000, "yabloc should stop"); | ||
state_is_active = false; | ||
return false; | ||
} | ||
|
||
const double dt = (clock_->now() - stamp_opt_.value()).seconds(); | ||
if (dt > 3) { | ||
RCLCPP_INFO_STREAM_THROTTLE(logger_, *clock_, 1000, "yabloc should stop"); | ||
state_is_active = false; | ||
return false; | ||
} else { | ||
RCLCPP_INFO_STREAM_THROTTLE(logger_, *clock_, 1000, "yabloc should keep estimation"); | ||
state_is_activating = true; | ||
return true; | ||
} | ||
} | ||
}; | ||
|
||
} // namespace pcdless::modularized_particle_filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...zed_particle_filter/include/modularized_particle_filter/prediction/resampling_history.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2023 TIER IV, 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 MODULARIZED_PARTICLE_FILTER__PREDICTION__RESAMPLING_HISTORY_HPP_ | ||
#define MODULARIZED_PARTICLE_FILTER__PREDICTION__RESAMPLING_HISTORY_HPP_ | ||
|
||
#include <algorithm> | ||
#include <numeric> | ||
#include <vector> | ||
|
||
namespace pcdless::modularized_particle_filter | ||
{ | ||
class ResamplingHistory | ||
{ | ||
public: | ||
ResamplingHistory(int max_history_num, int number_of_particles) | ||
: max_history_num_(max_history_num), number_of_particles_(number_of_particles) | ||
{ | ||
resampling_history_.resize(max_history_num); | ||
|
||
for (auto & generation : resampling_history_) { | ||
generation.resize(number_of_particles); | ||
std::iota(generation.begin(), generation.end(), 0); | ||
} | ||
} | ||
|
||
bool check_history_validity() const | ||
{ | ||
for (auto & generation : resampling_history_) { | ||
bool result = std::any_of(generation.begin(), generation.end(), [this](int x) { | ||
return x < 0 || x >= number_of_particles_; | ||
}); | ||
|
||
if (result) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
std::vector<int> & operator[](int generation_id) | ||
{ | ||
return resampling_history_.at(generation_id % max_history_num_); | ||
} | ||
|
||
const std::vector<int> & operator[](int generation_id) const | ||
{ | ||
return resampling_history_.at(generation_id % max_history_num_); | ||
} | ||
|
||
private: | ||
// Number of updates to keep resampling history. | ||
// Resampling records prior to this will not be kept. | ||
const int max_history_num_; | ||
const int number_of_particles_; | ||
std::vector<std::vector<int>> resampling_history_; | ||
}; | ||
|
||
} // namespace pcdless::modularized_particle_filter | ||
|
||
#endif // MODULARIZED_PARTICLE_FILTER__PREDICTION__RESAMPLING_HISTORY_HPP_ |
Oops, something went wrong.