CeresScanMatcher 匹配的使用步骤与实例解析

本文详细介绍了CeresScanMatcher的使用步骤,包括声明CostFunctor、创建AutoDiffCostFunction、添加地图、平移和旋转残差,以及优化位姿估计的过程。重点讲解了OccupiedSpaceCostFunction2D、TranslationDeltaCostFunctor2D和RotationDeltaCostFunctor2D在匹配中的应用。

一、使用步骤

第一步 声明CostFunctor

class MyScalarCostFunctor {
   
   
	MyScalarCostFunctor(double k): k_(k) {
   
   }
	template <typename T>
	bool operator()(const T* const x , const T* const y, T* e) const {
   
   
		// (k - x^T * y)^2, 平 方 由 ceres自 动 添 加
		e[0] = k_ - x[0] * y[0] - x[1] * y[1];
		return true;
	}
	private:
		double k_;
};

第二步 调用AutoDiffCostFunction函数

在这里插入图片描述
第三步 添加残差块

ceres::Problem problem;
problem.AddResidualBlock(cost_function);

第四步 进行求解

ceres::Solver::Summary summary;
ceres::Solve(ceres_solver_options_, &problem, summary);
std::cout << summary.BriefReport() << std::endl; // summary.FullReport()

二、cere 使用实例

/**
 * @brief 基于Ceres的扫描匹配
 * 
 * @param[in] target_translation 预测出来的先验位置, 只有xy
 * @param[in] initial_pose_estimate (校正后的)先验位姿, 有xy与theta
 * @param[in] point_cloud 用于匹配的点云 点云的原点位于local坐标系原点
 * @param[in] grid 用于匹配的栅格地图
 * @param[out] pose_estimate 优化之后的位姿
 * @param[out] summary 
 */
 void CeresScanMatcher2D::Match(const Eigen::Vector2d& target_translation,
                               const transform::Rigid2d& initial_pose_estimate,
                               const sensor::PointCloud& point_cloud,
                               const Grid2D& grid,
                               transform::Rigid2d* const pose_estimate,
                               ceres::Solver::Summary* const summary) const 
{
   
   
  double ceres_pose_estimate[3] = {
   
   initial_pose_estimate.translation().x(),
                                   initial_pose_estimate.translation().y(),
                                   initial_pose_estimate.rotation().angle()};
  ceres::Problem problem;
  CHECK_GT(options_.occupied_space_weight(), 0.);
  // 地图部分的残差
  problem.AddResidualBlock(
      OccupiedSpaceCostFunction2D::CreateAutoDiffCostFunction(
          options_.occupied_space_weight() /
              std::sqrt(static_cast<double>(point_cloud.size())),
          point_cloud, grid),
      nullptr /* loss function */, ceres_pose_estimate);
  CHECK_GT(options_.translation_weight(), 0.);
  // 平移的残差
  problem.AddResidualBlock(
      TranslationDeltaCostFunctor2D::CreateAutoDiffCostFunction(
          options_.translation_weight(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值