工程(一)Lego_Loam安装调试及运行

一、LeGO _LOAM安装

# 下载gtsam

cd ~
git clone https://bitbucket.org/gtborg/gtsam.git

#编译

cd ~/gtsam
mkdir build
cd build
cmake ..
make check   #可选的,运行单元测试,我没执行这个命令,因为在TX2上编译太慢了,太慢了,太慢了
make install

#下载编译Lego_loam

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
git clone https://github.com/RobustFieldAutonomyLab/LeGO-LOAM.git
cd ..
catkin_make -j1

 当第一次编译代码时,需要在“catkin_make”后面添加“-j1”以生成一些消息类型。将来的编译不需要“-j1”。

编译时出现错误,找不到Cmake文件,则需要在路径中添加相应的环境变量

catkin_make编译错误_weixin_30485291的博客-CSDN博客

Ubuntu下三种方法设置环境变量 - cv_gordon - 博客园

二、运行

运行lego_loam程序

roslaunch lego_loam run.launch

运行数据包

一定要加--clock时间,这样才能生成完整的全局地图

rosbag play 3-1.bag --clock

#转存为PCD文件

在代码建图过程中保存数据

rosbag record -o out /laser_cloud_surround

转化为pcd文件

rosrun pcl_ros bag_to_pcd input.bag /laser_cloud_surround pcd

查看pcd文件

pcl_viewer xxxxxx.pcd

三、LeGO _LOAM调试

utility文件修改

//1、激光雷达选型
// VLP-16
extern const int N_SCAN = 16;
extern const int Horizon_SCAN = 1800;
extern const float ang_res_x = 0.2;
extern const float ang_res_y = 2.0;
extern const float ang_bottom = 15.0+0.1;
extern const int groundScanInd = 7;


//pandar-40
extern const int N_SCAN =40;
extern const int Horizon_SCAN = 1800;
extern const float ang_res_x = 0.2;
extern const float ang_res_y = 0.33;
extern const float ang_bottom = 3.0+0.1;
extern const int groundScanInd = 10;

//VLP-64
extern const int N_SCAN = 64;
extern const int Horizon_SCAN = 1800;
extern const float ang_res_x = 0.2;
extern const float ang_res_y = 0.427;
extern const float ang_bottom = 24.9;
extern const int groundScanInd = 20;

// 2、特征点提取分割
extern const int edgeFeatureNum = 6;
extern const int surfFeatureNum = 10;
extern const int sectionsTotal = 2;
extern const float edgeThreshold = 0.1;
extern const float surfThreshold = 0.1;
extern const float nearestFeatureSearchSqDist = 25;

//3、输入点云类型定义
struct EIGEN_ALIGN16 PointXYZRGBI
{
    PCL_ADD_POINT4D; // This adds the members x,y,z which can also be accessed using the point (which is float[4])
    PCL_ADD_RGB;
    float intensity;     //intensity
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

POINT_CLOUD_REGISTER_POINT_STRUCT(PointXYZRGBI,
                                  (float,x,x)
                                  (float,y,y)
                                  (float,z,z)
                                  (uint8_t,rgb,rgb)
                                  (float,intensity,intensity)
)
typedef PointXYZRGBI  PointType;

4. Ubuntu20.04遇到的问题

1、编译错误在CMakelists.txt中添加

set( CMAKE_CXX_STANDARD 14)

2、20.04的openCV自带的是opencv4,所以需要将utility.h中的#include <opencv/cv.h>

#include <opencv2/opencv.hpp>

3、编译不报错,能够正常运行,但不显示地图和轨迹,只看到坐标系移动

原因:ubuntu20.04的rostopic格式更加严格,之前版本/rostopic和rostopic发出消息均是/rostopic。ubuntu20.04/rostopic发出消息是//rostopic。

在mapOptmization.cpp文件中将以下代码中的/camera_init更改为camera_init,去除/

    void publishKeyPosesAndFrames(){

        if (pubKeyPoses.getNumSubscribers() != 0){
            sensor_msgs::PointCloud2 cloudMsgTemp;
            pcl::toROSMsg(*cloudKeyPoses3D, cloudMsgTemp);
            cloudMsgTemp.header.stamp = ros::Time().fromSec(timeLaserOdometry);
            cloudMsgTemp.header.frame_id = "/camera_init";
            pubKeyPoses.publish(cloudMsgTemp);
        }

        if (pubRecentKeyFrames.getNumSubscribers() != 0){
            sensor_msgs::PointCloud2 cloudMsgTemp;
            pcl::toROSMsg(*laserCloudSurfFromMapDS, cloudMsgTemp);
            cloudMsgTemp.header.stamp = ros::Time().fromSec(timeLaserOdometry);
            cloudMsgTemp.header.frame_id = "/camera_init";
            pubRecentKeyFrames.publish(cloudMsgTemp);
        }

        if (pubRegisteredCloud.getNumSubscribers() != 0){
            pcl::PointCloud<PointType>::Ptr cloudOut(new pcl::PointCloud<PointType>());
            PointTypePose thisPose6D = trans2PointTypePose(transformTobeMapped);
            *cloudOut += *transformPointCloud(laserCloudCornerLastDS,  &thisPose6D);
            *cloudOut += *transformPointCloud(laserCloudSurfTotalLast, &thisPose6D);
            
            sensor_msgs::PointCloud2 cloudMsgTemp;
            pcl::toROSMsg(*cloudOut, cloudMsgTemp);
            cloudMsgTemp.header.stamp = ros::Time().fromSec(timeLaserOdometry);
            cloudMsgTemp.header.frame_id = "/camera_init";
            pubRegisteredCloud.publish(cloudMsgTemp);
        } 
    }

  • 2
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

桦树无泪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值