template <typename LocalTrajectoryBuilder, typename PoseGraph> classGlobalTrajectoryBuilder :public mapping::TrajectoryBuilderInterface { public: // Passing a 'nullptr' for 'local_trajectory_builder' is acceptable, but no // 'TimedPointCloudData' may be added in that case.
/** * @brief 完整的slam, 连接起了前端与后端 * * @param[in] local_trajectory_builder 2d or 3d local slam 前端 * @param[in] trajectory_id 轨迹id * @param[in] pose_graph 2d or 3d pose_graph 后端 * @param[in] local_slam_result_callback 前端的回调函数 * @param[in] pose_graph_odometry_motion_filter 里程计的滤波器 */ GlobalTrajectoryBuilder( std::unique_ptr<LocalTrajectoryBuilder> local_trajectory_builder, constint trajectory_id, PoseGraph* const pose_graph, const LocalSlamResultCallback& local_slam_result_callback, const absl::optional<MotionFilter>& pose_graph_odometry_motion_filter) : trajectory_id_(trajectory_id), pose_graph_(pose_graph), local_trajectory_builder_(std::move(local_trajectory_builder)), local_slam_result_callback_(local_slam_result_callback), pose_graph_odometry_motion_filter_(pose_graph_odometry_motion_filter) {} ~GlobalTrajectoryBuilder() override {}
// 加入到后端之前, 先做一个距离的计算, 只有时间,移动距离,角度 变换量大于阈值才加入到后端中 voidAddSensorData(const std::string& sensor_id, const sensor::OdometryData& odometry_data)override{ CHECK(odometry_data.pose.IsValid()) << odometry_data.pose; if (local_trajectory_builder_) { local_trajectory_builder_->AddOdometryData(odometry_data); } // TODO(MichaelGrupp): Instead of having an optional filter on this level, // odometry could be marginalized between nodes in the pose graph. // Related issue: cartographer-project/cartographer/#1768 if (pose_graph_odometry_motion_filter_.has_value() && pose_graph_odometry_motion_filter_.value().IsSimilar( odometry_data.time, odometry_data.pose)) { return; } pose_graph_->AddOdometryData(trajectory_id_, odometry_data); }