ubuntu 自动驾驶 LOAM系列——FLOAM配置、安装、问题解决及VLP16测试效果及关键记录 - 3,3&gt

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力2026 👁️ 161 次阅读

LOAM系列——FLOAM配置、安装、问题解决及VLP16测试效果及关键记录

安装依赖安装KITTI sequence 07VLP16 bag测试问题解决问题1

关键记录FLOAM主要特点雅可比矩阵推导相关知识注:

关键代码

安装依赖

Ubuntu and ROSCeres SolverPCLTrajectory visualization sudo apt-get install ros-melodic-hector-trajectory-server

安装

cd ~/test_ws/src

git clone https://github.com/wh200720041/floam.git

cd ..

catkin_make -DCATKIN_WHITELIST_PACKAGES="floam"

KITTI sequence 07

source ~/test_ws/devel/setup.bash

roslaunch floam floam.launch #launch文件中包含bag的运行

如若想同时生成地图,则运行下面命令

roslaunch floam floam_mapping.launch

其中 floam.launch文件内容如下:

其中 floam_mapping.launch内容如下:

VLP16 bag测试

source ~/test_ws/devel/setup.bash

roslaunch floam floam_velodyne.launch

cd ~/test_bag

rosbag play indoor_2021-03-30-15-27-23.bag

或者

roslaunch floam floam_velodyne_with_bag.launch

其中 floam_velodyne.launch 内容如下:

其中 loam_velodyne_with_bag.launch 内容如下:

测试视频链接

floam

问题解决

问题1

问题: floam_laser_mapping_node节点,可能会出现运行一段时间就报错,崩溃了

关键记录

FLOAM主要特点

整体和ALOAM类似,只是使用残差函数的雅可比使用的是解析式求导 代码:https://github.com/wh200720041/floam

雅可比矩阵推导相关知识

注:

这里用的推导方式与上面的稍微有些不同,使用的是如下形式,图1,

这里需要多一步转换,如图2

关键代码

//定义

class EdgeAnalyticCostFunction : public ceres::SizedCostFunction<1, 7>{

public:

EdgeAnalyticCostFunction(Eigen::Vector3d curr_point_, Eigen::Vector3d last_point_a_, Eigen::Vector3d last_point_b_);

virtual ~EdgeAnalyticCostFunction() {}

virtual bool Evaluate(double const *const *parameters, double *residuals, double **jacobians) const;

Eigen::Vector3d curr_point;

Eigen::Vector3d last_point_a;

Eigen::Vector3d last_point_b;

};

//实现

EdgeAnalyticCostFunction::EdgeAnalyticCostFunction(Eigen::Vector3d curr_point_, Eigen::Vector3d last_point_a_, Eigen::Vector3d last_point_b_)

: curr_point(curr_point_), last_point_a(last_point_a_), last_point_b(last_point_b_){

}

bool EdgeAnalyticCostFunction::Evaluate(double const *const *parameters, double *residuals, double **jacobians) const

{

Eigen::Mapq_last_curr(parameters[0]);

Eigen::Mapt_last_curr(parameters[0] + 4);

Eigen::Vector3d lp;

lp = q_last_curr * curr_point + t_last_curr;

Eigen::Vector3d nu = (lp - last_point_a).cross(lp - last_point_b);

Eigen::Vector3d de = last_point_a - last_point_b;

double de_norm = de.norm();

residuals[0] = nu.norm()/de_norm;

if(jacobians != NULL)

{

if(jacobians[0] != NULL)

{

Eigen::Matrix3d skew_lp = skew(lp);

Eigen::Matrixdp_by_se3;

dp_by_se3.block<3,3>(0,0) = -skew_lp;

(dp_by_se3.block<3,3>(0, 3)).setIdentity();

Eigen::Map> J_se3(jacobians[0]);J_se3.setZero();

Eigen::Matrix3d skew_de = skew(de);

J_se3.block<1,6>(0,0) = - nu.transpose() / nu.norm() * skew_de * dp_by_se3/de_norm; //关于这里最前面的“-”号问题,是因为 nu = (lp - last_point_a).cross(lp - last_point_b);,推导的时候是(lp - last_point_b)叉乘 (lp - last_point_a)

}

}

return true;

}

//定义

class SurfNormAnalyticCostFunction : public ceres::SizedCostFunction<1, 7>{

public:

SurfNormAnalyticCostFunction(Eigen::Vector3d curr_point_, Eigen::Vector3d plane_unit_norm_, double negative_OA_dot_norm_);

virtual ~SurfNormAnalyticCostFunction() {}

virtual bool Evaluate(double const *const *parameters, double *residuals, double **jacobians) const;

Eigen::Vector3d curr_point;

Eigen::Vector3d plane_unit_norm;

double negative_OA_dot_norm;

};

//实现

SurfNormAnalyticCostFunction::SurfNormAnalyticCostFunction(Eigen::Vector3d curr_point_, Eigen::Vector3d plane_unit_norm_, double negative_OA_dot_norm_)

: curr_point(curr_point_), plane_unit_norm(plane_unit_norm_), negative_OA_dot_norm(negative_OA_dot_norm_){

}

bool SurfNormAnalyticCostFunction::Evaluate(double const *const *parameters, double *residuals, double **jacobians) const

{

Eigen::Mapq_w_curr(parameters[0]);

Eigen::Mapt_w_curr(parameters[0] + 4);

Eigen::Vector3d point_w = q_w_curr * curr_point + t_w_curr;

residuals[0] = plane_unit_norm.dot(point_w) + negative_OA_dot_norm;

if(jacobians != NULL)

{

if(jacobians[0] != NULL)

{

Eigen::Matrix3d skew_point_w = skew(point_w);

Eigen::Matrixdp_by_se3;

dp_by_se3.block<3,3>(0,0) = -skew_point_w;

(dp_by_se3.block<3,3>(0, 3)).setIdentity();

Eigen::Map> J_se3(jacobians[0]);J_se3.setZero();

J_se3.block<1,6>(0,0) = plane_unit_norm.transpose() * dp_by_se3;

}

}

return true;

}

//定义

class PoseSE3Parameterization : public ceres::LocalParameterization {

public:

PoseSE3Parameterization() {}

virtual ~PoseSE3Parameterization() {}

virtual bool Plus(const double* x, const double* delta, double* x_plus_delta) const;

virtual bool ComputeJacobian(const double* x, double* jacobian) const;

virtual int GlobalSize() const { return 7; }

virtual int LocalSize() const { return 6; }

};

//实现

bool PoseSE3Parameterization::Plus(const double *x, const double *delta, double *x_plus_delta) const

{

Eigen::Maptrans(x + 4);

Eigen::Quaterniond delta_q;

Eigen::Vector3d delta_t;

getTransformFromSe3(Eigen::Map>(delta), delta_q, delta_t);

Eigen::Mapquater(x);

Eigen::Mapquater_plus(x_plus_delta);

Eigen::Maptrans_plus(x_plus_delta + 4); 拼多多帮助力入口

quater_plus = delta_q * quater;

trans_plus = delta_q * trans + delta_t;

return true;

}

bool PoseSE3Parameterization::ComputeJacobian(const double *x, double *jacobian) const

{

Eigen::Map> j(jacobian);(j.topRows(6)).setIdentity();

(j.bottomRows(1)).setZero();

return true;

}

......

double parameters[7] = {0, 0, 0, 1, 0, 0, 0};

......

ceres::LossFunction *loss_function = new ceres::HuberLoss(0.1);

ceres::Problem::Options problem_options;

ceres::Problem problem(problem_options);

problem.AddParameterBlock(parameters, 7, new PoseSE3Parameterization());

......

ceres::CostFunction *cost_function = new EdgeAnalyticCostFunction(curr_point, point_a, point_b);

problem.AddResidualBlock(cost_function, loss_function, parameters);

ceres::CostFunction *cost_function = new SurfNormAnalyticCostFunction(curr_point, norm, negative_OA_dot_norm);

problem.AddResidualBlock(cost_function, loss_function, parameters);

......

ceres::Solver::Options options;

options.linear_solver_type = ceres::DENSE_QR;

options.max_num_iterations = 4;

options.minimizer_progress_to_stdout = false;

options.check_gradients = false;

options.gradient_check_relative_precision = 1e-4;

ceres::Solver::Summary summary;

ceres::Solve(options, &problem, &summary);

注:以下内容需要深入理解 Eigen::Map> J_se3(jacobians[0]); J_se3.setZero(); Eigen::Matrix3d skew_de = skew(de); J_se3.block<1,6>(0,0) = - nu.transpose() / nu.norm() * skew_de * dp_by_se3/de_norm; Eigen::Map> J_se3(jacobians[0]); J_se3.setZero(); J_se3.block<1,6>(0,0) = plane_unit_norm.transpose() * dp_by_se3;参考阅读,ubuntu

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧