rplidar跑cartographer

一、Cartographer编译

cartographer依赖的大型第三方库很少,编译时基本没有依赖项问题,基本按照官方文档的步骤来,略作修改。使用的环境是Ubuntu16.04+ROS Kinetic

1.先装好wstoolrosdep、ninja

  sudo apt-get install -y python-wstool python-rosdep ninja-build

2.建工作空间

  mkdir catkin_ws

  cd catkin_ws

  用wstool初始化一下

  wstool init src

  (不知道这种初始化方式和catkin_init_workspace有什么区别)

3.下载cartographer、cartographer_ros、ceres源码

  官方提供的下载方式是用rosinstall file,但是里面ceres的git地址要科学上网,可以自己把三部分源码下到 src 里就好,三部分地址https://github.com/googlecartographer/cartographer、https://github.com/googlecartographer/cartographer_ros、https://github.com/ceres-solver/ceres-solver。下载后都是最新的,也不用 wstool update -t src 这条了。

4.装proto3

protobuf是谷歌的开源序列化框架(现在还不懂这是干什么的。。。)

catkin_ws/src/cartographer/scripts/install_proto3.sh  这个文件运行一下就可以了

5.安装依赖项

  sudo rosdep init

  rosdep update

  rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

6.最后编译

  catkin_make_isolated --install --use-ninja

  最后把环境变量写到bash里

  vi .bashrc

  最后一行加上

   source ~/catkin_ws/install_isolated/setup.bash

7.跑一下官方demo试试

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag

roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag

 

二、rplidar驱动安装

https://github.com/robopeak/rplidar_ros 下载rplidar的ROS驱动,可以新建一个工作空间,用catkin_make 编译一下即可;也可以放在cartographer的工作空间里 src 下,执行一下最后的catkin_make_isolated --install --use-ninja 即可。

1.开始使用前要设置一下USB口的权限

  ls -l /dev |grep ttyUSB

  sudo chmod 666 /dev/ttyUSB0

这样每次插上rplidar都要设置一次,可以将权限写在rules里(参考这个):

root权限新建文件 /etc/udev/rules.d/70-ttyusb.rules

写入KERNEL=="ttyUSB[0-9]*", MODE="0666",保存,重新插上设备,在运行一次ls -l /dev |grep ttyUSB 查看权限,有两个 rw 就可以了。

(感觉这样写的话或许北阳的激光插上也不用设置权限了)

2.运行一下试试

驱动里提供了三个launch文件,跑cartographer的话用 rplidar.launch 即可

  roslaunch rplidar_ros rplidar.launch

 

三、测试cartographer

  先要修改 launch 文件和 lua 文件,launch文件在 demo_revo_lds.launch 基础上修改(跟其他教程学的)

  主要两个地方,<remap from="scan" to="horizontal_laser_2d" />这一句后面的 horizontal_laser_2d 改成 scan (直接删掉这一句应该也可以);最后的 playbag 节点删掉。

  然后是lua文件,这个里面对参数的调整也会关系到出图的效果,具体如何影响还在学习中,只想跑起来的话比较简单,在revo_lds.lua 基础上修改,tracking_frame  和 published_frame 这两个改成 laser 就可以了。

  

(随便放桌上运行了一下,为了截图而已。。)

 

四、总结

  Linux的知识真的很欠缺,暑假才第一次用过Ubuntu,很多基础的命令都不熟,特别是Linux下编译程序是真挺麻烦的,对cmakelists文件了解太少,只能慢慢用到啥就去查,然后多做笔记。

  一开始没搞明白ros里面几个坐标系的转换,虽然知道是tf 问题,但是 lua 文件老是设置不好,ROS的基础知识还是要多看,特别是后面看源码的话还是要有ros基础的。

  cartographer的源码要开始看了,现在只是对大体架构有了解,还是要深入了解,多半是个挺痛苦的过程吧,哈哈。

原文地址:https://www.cnblogs.com/liangyf0312/p/8028441.html