【激光SLAM】Lego_loam使用教程

安装

https://github.com/RobustFieldAutonomyLab/LeGO-LOAM

 

运行

roslaunch lego_loam run.launch 

 

录制bag

rosbag record -o out /laser_cloud_surround

注意:out是bag文件名称,/laser_cloud_surround是录制的话题,lego_loam包含许多话题,其中/laser_cloud_surround是记录着整个地图.

 

bag转pcd文件

rosrun pcl_ros bag_to_pcd  out.bag /laser_cloud_surround  ./pcd

注意:会运行完后会生成一个pcd文件夹,文件夹中可能包含许多的pcd,选取最后的pcd文件,假设最后的pcd文件是last.pcd.

 

在RVIZ中显示点云图

创建cpp文件

    #include<ros/ros.h>  
    #include<pcl/point_cloud.h>  
    #include<pcl_conversions/pcl_conversions.h>  
    #include<sensor_msgs/PointCloud2.h>  
    #include <pcl/common/transforms.h>
    #include<pcl/io/pcd_io.h>
      
    int main (int argc, char **argv)  
    {  
      ros::init (argc, argv, "orbslam");  
      ros::NodeHandle nh;  
      ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("/orbslam2_with_kinect2/output", 10);  
      
      pcl::PointCloud<pcl::PointXYZ> cloud1,cloud2;  
      sensor_msgs::PointCloud2 output;  
      pcl::io::loadPCDFile ("/home/xavier/test_ws/last.pcd", cloud1);

      Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();


      //绕x轴旋转一个theta角
      transform_2.rotate(Eigen::AngleAxisf(1.570795, Eigen::Vector3f::UnitX()));

      //执行变换
      //pcl::PointCloud<pcl::PointXYZ>::Ptr pPointCloudOut(new pcl::PointCloud<pcl::PointXYZ>());
      pcl::transformPointCloud(cloud1, cloud2, transform_2);


      pcl::toROSMsg(cloud2,output);// 转换成ROS下的数据类型 最终通过topic发布
	
      output.header.stamp=ros::Time::now();
      output.header.frame_id  ="/camera_rgb_frame";
	
      ros::Rate loop_rate(1);  
      while (ros::ok())  
      {  
        pcl_pub.publish(output);  
        ros::spinOnce();  
        loop_rate.sleep();  
      }  
      return 0;  
    }  

创建launch

<launch>
  <node pkg="octomap_server" type="octomap_server_node" name="octomap_server">

    <!-- resolution in meters per pixel -->
    <param name="resolution" value="0.1" />

    <!-- name of the fixed frame, needs to be "/map" for SLAM -->
    <param name="frame_id" type="string" value="/camera_rgb_frame" />

    <!-- max range / depth resolution of the kinect in meter -->
    <param name="sensor_model/max_range" value="50.0" />
    <param name="latch" value="true" />

    <!-- max/min height for occupancy map, should be in meters -->
    <param name="pointcloud_max_z" value="1000" />
    <param name="pointcloud_min_z" value="-1000" />

    <param name="ground_filter_angle" value="3.14" />

    <!-- topic from where pointcloud2 messages are subscribed -->
    <remap from="cloud_in" to="/orbslam2_with_kinect2/output" />

  </node>

</launch>

点击add 按钮添加 "PointCloud2模块"
设置topic为 "/orbslam2_with_kinect2/output"
设置FixedFram为"camera_rgb_frame"

注意:参考过博主熊猫飞天https://blog.csdn.net/crp997576280/article/details/74605766#comments,发现运行的程序出来的图像和rviz网格是垂直的,显示出的2d栅格图有问题,故在博主原程序上做个点云图的旋转变换,现在可以正常显示出2d栅格图.

  • 5
    点赞
  • 93
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Travis.X

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

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

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

打赏作者

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

抵扣说明:

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

余额充值