(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症

本人讲解关于slam一系列文章汇总链接:史上最全slam从零开始,针对于本栏目讲解(02)Cartographer源码无死角解析-接如下:
(02)Cartographer源码无死角解析-(00)目录_最新无死角讲解:https://blog.csdn.net/weixin_43013761/article/details/127350885
 
文末正下方中心提供了本人 联系方式, 点击本人照片即可显示 W X → 官方认证 {\color{blue}{文末正下方中心}提供了本人 \color{red} 联系方式,\color{blue}点击本人照片即可显示WX→官方认证} 文末正下方中心提供了本人联系方式,点击本人照片即可显示WX官方认证
 
请注意本人使用环境为 U b u n t u 18.04 \color{red}{Ubuntu18.04} Ubuntu18.04,另外本人现在的时间点为 20221016 \color{red}{20221016} 20221016 无法保证你现在的时间点,相应的依赖库或者工程作者是否有更新。
 

一、前言

官方文档的地址为
https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html
https://google-cartographer.readthedocs.io/en/latest/index.html
我们使用的是Ros的,所以以第一个为标准

官方提供数据集链接(不用着急下载)
https://github.com/cartographer-project/cartographer_ros/blob/master/docs/source/data.rst

 

二、docker环境搭建

本人使用的环境是基于 docker 进行搭建的,当然你也可以使用 Ubuntu18.04 系统的裸机或者虚拟机,那么直接跳过该内容即可:

docker pull ubuntu:18.04  # 拉取ubuntu18.04镜像

# 创建容器并且映射端口与目录
docker run  -dit --restart=always  --privileged   -v /tmp/.X11-unix:/tmp/.X11-unix   -v /work/4.my_work/1.zwh:/my_work      -p 12570:22    -e DISPLAY=:0    -e LANG=C.UTF-8  --shm-size 64G   --name   ub18.04-cartographer-zwh   -w /  35b3f4f76a24   /bin/bash

docker exec -it  ub18.04-cartographer-zwh /bin/bash # 进入容器 

apt-get update # 更新操作

apt-get install gcc g++ cmake git vim tree wget libcurl3-gnutls curl 
#安装基本软件

更换成清华源

cd /etc/apt/
# 备份源
sudo cp sources.list sources.list.bk

sudo vim sources.list # 把原换为清华源

apt-get update # 替换之后更新操作

替换成以下内容

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

 

三、环境搭建

1、基础依赖

sudo apt-get install -y   clang     cmake     g++     git     google-mock    
sudo apt-get install -y  libboost-all-dev     libcairo2-dev     libceres-dev     libcurl4-openssl-dev     
sudo apt-get install -y  libeigen3-dev     libgflags-dev     libgoogle-glog-dev     liblua5.2-dev    
sudo apt-get install -y  libsuitesparse-dev     lsb-release     ninja-build     python3-sphinx     stow
sudo apt-get install -y python3-wstool python3-rosdep ninja-build stow

# Install Protocol Buffers and Abseil if available.
# No need to build it ourselves.
case "$(lsb_release -sc)" in
    jammy|bullseye)
        sudo apt-get install -y libgmock-dev protobuf-compiler libabsl-dev ;;
    focal|buster)
        sudo apt-get install -y libgmock-dev protobuf-compiler ;;
    bionic)
        ;;
esac

 

2、源码获取

首先创建工作目录catkin_ws,进入该目录,创建文件cartographer_ros.rosinstall,在该文件中填写如下内容:

- git: {local-name: cartographer, uri: 'https://github.com/cartographer-project/cartographer.git', version: 'master'}
- git: {local-name: cartographer_ros, uri: 'https://github.com/cartographer-project/cartographer_ros.git', version: 'master'}

然后执行如下指令:

sudo apt-get install python-wstool
wstool init src
wstool merge -t src cartographer_ros.rosinstall
wstool update -t src
tree -L 2

执行完成之后,本人打印类似如下:
(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症_第1张图片
 

3、ROS安装

可以参考:
    (01) http://wiki.ros.org/melodic/Installation
    (02)一行代码搭建机器人开发环境(ROS/ROS2/ROSDEP)

	# 如果之前安装过ros先卸载
	sudo apt-get purge ros-*
	
	# 执行指令
	wget http://fishros.com/install -O fishros && . fishros

重复运行两次 \color{red}重复运行两次 重复运行两次 之后,本人打印如下:
(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症_第2张图片
本人选择如下:

[1]:一键安装:ROS(支持ROS和ROS2,树莓派Jetson)
[1]:更换系统源再继续安装
[2]:更换系统源并清理第三方源
[1]:melodic(ROS1)
[1]:melodic(ROS1)桌面版

安装成功之后本人打印如下:
(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症_第3张图片
后面我们进行一个测试实验,

	#完成上述工作之后,我们再验证ROS是否安装成功,我们首先要开启三个终端,每个终端运行对应的指令如下:
	第一个终端: roscore
	第二个终端: rosrun turtlesim turtlesim_node # 会出现一个小海龟,
	第三个终端: rosrun turtlesim turtle_teleop_key # 接下来就在可以通过方向键控制海龟的移动。

注意,其上所有终端需要重新开启 → 共三个终端运行不同指令 \color{red}{注意,其上所有终端需要重新开启→共三个终端运行不同指令} 注意,其上所有终端需要重新开启共三个终端运行不同指令
本人显示图像图下:
(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症_第4张图片
 

四、源码编译

# 进入catkin_ws目录
src/cartographer/scripts/install_abseil.sh
sudo apt-get remove ros-${ROS_DISTRO}-abseil-cpp
catkin_make_isolated --install --use-ninja

成功之后本人打印如下:
(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症_第5张图片
 

五、下载bag并且运行demo

注意 → 每次重启终端先执行如下指令 \color{red}{注意→每次重启终端先执行如下指令} 注意每次重启终端先执行如下指令

source install_isolated/setup.bash
# 查看一下环境变量,与 echo $ROS_PACKAGE_PATH 功能差不多
rospack profile

1、Deutsches Museum(建图定位)

Download and launch the 2D backpack 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

本人执行之后相似效果如下:
(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症_第6张图片
Download and launch the 3D backpack demo:

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/with_intensities/b3-2016-04-05-14-14-00.bag

roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag

 

2、Pure localization(纯定位)

Download the 2D bags from the Deutsche Museum:

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/b2-2016-04-05-14-44-52.bag

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/b2-2016-04-27-12-31-41.bag

Generate the map (wait until cartographer_offline_node finishes) and then run pure localization:

roslaunch cartographer_ros offline_backpack_2d.launch bag_filenames:=${HOME}/Downloads/b2-2016-04-05-14-44-52.bag

roslaunch cartographer_ros demo_backpack_2d_localization.launch \
   load_state_filename:=${HOME}/Downloads/b2-2016-04-05-14-44-52.bag.pbstream \
   bag_filename:=${HOME}/Downloads/b2-2016-04-27-12-31-41.bag

本人展示效果如下:
(02)Cartographer源码无死角解析-(01) 环境搭建,demo运行,ROS一键安装_清除各种疑难杂症_第7张图片

 
Download the 3D bags from the Deutsche Museum:

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-13-54-42.bag

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-15-52-20.bag

Generate the map (wait until cartographer_offline_node finishes) and then run pure localization:

roslaunch cartographer_ros offline_backpack_3d.launch bag_filenames:=${HOME}/Downloads/b3-2016-04-05-13-54-42.bag

roslaunch cartographer_ros demo_backpack_3d_localization.launch \
   load_state_filename:=${HOME}/Downloads/b3-2016-04-05-13-54-42.bag.pbstream \
   bag_filename:=${HOME}/Downloads/b3-2016-04-05-15-52-20.bag

 

3、Static landmarks(本人暂时未跑起来,后面再找原因)

# Download the landmarks example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/mir/landmarks_demo_uncalibrated.bag

# Launch the landmarks demo.
roslaunch cartographer_mir offline_mir_100_rviz.launch bag_filename:=${HOME}/Downloads/landmarks_demo_uncalibrated.bag

 

4、Revo LDS

Download and launch an example bag captured from a low-cost Revo Laser Distance Sensor from Neato Robotics vacuum cleaners:

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

roslaunch cartographer_ros demo_revo_lds.launch bag_filename:=${HOME}/Downloads/cartographer_paper_revo_lds.bag

 

5、PR2

Download and launch an example bag captured from a PR2 R&D humanoid robot from Willow Garage:

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/pr2/2011-09-15-08-32-46.bag

roslaunch cartographer_ros demo_pr2.launch bag_filename:=${HOME}/Downloads/2011-09-15-08-32-46.bag

 

6、Taurob Tracker

Download and launch an example bag captured from a Taurob Tracker teleoperation robot:

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

roslaunch cartographer_ros demo_taurob_tracker.launch bag_filename:=${HOME}/Downloads/taurob_tracker_simulation.bag

 
 
 

你可能感兴趣的:(#,自动驾驶,机器学习,无人机,增强现实,Cartographer)