Cartographer源码阅读2D-前端Node稀疏化-MotionFilter
在trajectory_builder_2d.cc的LocalTrajectoryBuilder2D::AddAccumulatedRangeData函数中,执行稀疏化任务,即,在AddAccumulatedRangeData函数中调用InsertIntoSubmap函数,在InsertIntoSubmap函数内调用(motion_filter_.IsSimilar(time, pose_estimate)函数,进行稀疏化,如果被判断和上一帧的时间及位姿变化较小,则认为该帧不是Node,不放入后端。
MotionFilter类
class MotionFilter {
public:
explicit MotionFilter(const proto::MotionFilterOptions& options);
bool IsSimilar(common::Time time, const transform::Rigid3d& pose);
private:
const proto::MotionFilterOptions options_;
int num_total_ = 0;
int num_different_ = 0;
common::Time last_time_;
transform::Rigid3d last_pose_;
};
bool MotionFilter::IsSimilar(const common::Time time,
const transform::Rigid3d& pose) {
LOG_IF_EVERY_N(INFO, num_total_ >= 500, 500)
<< "Motion filter reduced the number of nodes to "
<< 100. * num_different_ / num_total_ << "%.";
++num_total_;
if (num_total_ > 20 &&
time - last_time_ <= common::FromSeconds(options_.max_time_seconds()) &&
(pose.translation() - last_pose_.translation()).norm() <=
options_.max_distance_meters() &&
transform::GetAngle(pose.inverse() * last_pose_) <=
options_.max_angle_radians()) {
return true;
}
last_time_ = time;
last_pose_ = pose;
++num_different_;
return false;
}
参考链接: https://blog.csdn.net/yeluohanchan/article/details/108855989.
|