工作小笔记——基于ROS Melodic的cartographer安装

文章目录

  • 前言
  • 1. 环境要求
  • 2. 安装ROS Melodic
    • 2.1 配置国内源
    • 2.2 安装
    • 2.3 安装rosdep并设置国内源
      • 2.3.1 安装rosdep
      • 2.3.2 设置成本地源
        • 2.3.2.1 20-default.list
        • 2.3.2.2 /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
        • 2.3.2.3 /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
        • 2.3.2.4 /usr/lib/python2.7/dist-packages/rosdistro/\_\_init\_\_.py
        • 2.3.2.5 /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
  • 2.3.3 更新rosdep源
    • 2.4 安装编译依赖
    • 2.5 验证安装
  • 3. 安装Cartographer
    • 3.1 ROS下的直接安装
    • 3.2 源码安装
      • 3.2.1 检查环境要求
      • 3.2.2 安装依赖与编译工具
      • 3.2.3 初始化工作空间
        • 3.2.3.1 方法1:使用wstool
        • 3.2.3.2 方法2:直接git获取源码
      • 3.2.4 安装功能包依赖
      • 3.2.5 编译安装
  • 4. 测试安装
  • 参考文献


前言

基于Cartographer的安装过程比较简单,基本就是ubuntu18.04,ros-melodic,cartographer,cartographer-ros。本文主要针对国内上网不便的情况,给出快速安装的过程说明。

1. 环境要求

  • Ubuntu 18.04 desktop
  • ROS Melodic
  • cartographer
  • Ubuntu系统:64bit-18.04+
  • gcc版本:6.3.0、7.5.0、9.3.0
  • proto版本:3.0+
  • ceres-solver版本:1.12.0、1.13.0

2. 安装ROS Melodic

2.1 配置国内源

sudo sh -c 'echo "deb https://mirrors.ustc.edu.cn/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

2.2 安装

sudo apt update
sudo apt install ros-melodic-desktop-full

2.3 安装rosdep并设置国内源

2.3.1 安装rosdep

sudo apt-get -y install python-rosdep

2.3.2 设置成本地源

为了把rosdep的依赖设置成本地,需要修改多个文件,具体如下。

2.3.2.1 20-default.list

cd ~/
git clone https://gitee.com/c1h2/rosdistro.git
cd /home/h1c/rosdistro/rosdep/sources.list.d/

将20-default.list的所有内容替换为:

# os-specific listings first
yaml file:///home/h1c/rosdistro/rosdep/osx-homebrew.yaml osx

# generic
yaml file:///home//rosdistro/rosdep/base.yaml
yaml file:///home//rosdistro/rosdep/python.yaml
yaml file:///home//rosdistro/rosdep/ruby.yaml
gbpdistro file:///home//rosdistro/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

2.3.2.2 /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py

替换文件中的对应内容为:

FUERTE_GBPDISTRO_URL = 'file:///home//rosdistro/releases/fuerte.yaml'

2.3.2.3 /usr/lib/python2.7/dist-packages/rosdep2/rep3.py

替换文件中的对应内容为:

REP3_TARGETS_URL = 'file:///home//rosdistro/releases/targets.yaml'

2.3.2.4 /usr/lib/python2.7/dist-packages/rosdistro/__init__.py

替换文件中的对应内容为:

DEFAULT_INDEX_URL = 'file:///home//rosdistro/index-v4.yaml'

2.3.2.5 /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py

替换文件中的对应内容为:

DEFAULT_SOURCES_LIST_URL = 'file:///home//rosdistro/rosdep/sources_list.d/20-default.list'

2.3.3 更新rosdep源

sudo rosdep init
rosdep update

2.4 安装编译依赖

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

2.5 验证安装

rosversion -d

3. 安装Cartographer

3.1 ROS下的直接安装

sudo apt-get update
sudo apt-get install ros-melodic-cartographer*

3.2 源码安装

3.2.1 检查环境要求

运行如下命令确认protoc版本是3.0以上。

protoc --version

3.2.2 安装依赖与编译工具

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

3.2.3 初始化工作空间

需要从源码安装如下包:

  • cartographer:cartographer包
  • cartographer_ros:cartographer的ros wrapper
  • ceres-solver:cartographer使用的优化器

3.2.3.1 方法1:使用wstool

  • 使用wstool初始化工作空间
mkdir -p ~/carto_ws
cd ~/carto_ws
wstool init src
#wstool merge -t src https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
  • 修改~/carto_ws/src/.rosinstall文件,加入cartographer、cartographer_ros、ceres-solver的功能包,在文件末尾添加如下内容:
- 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
- git:
    local-name: ceres-solver
    uri: https://github.com/ceres-solver/ceres-solver.git
    version: 1.13.0
  • 更新依赖。
wstool update -t src

3.2.3.2 方法2:直接git获取源码

cd ~/carto_ws/src
git clone https://github.com/cartographer-project/cartographer.git
git clone https://github.com/cartographer-project/cartographer_ros.git
git clone https://github.com/ceres-solver/ceres-solver.git

3.2.4 安装功能包依赖

  • 打开文件~/carto_ws/src/cartographer/package.xml,删除行“libabsl-dev
  • 安装abseil-cpp库:
cd ~/carto_ws/src/cartographer/scripts
./install_abseil.sh
  • 安装依赖
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

3.2.5 编译安装

catkin_make_isolated --install --use-ninja

4. 测试安装

  • 下载测试包:
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
  • 运行:
cd ~/carto_ws
source install_isolated/setup.bash
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag

参考文献

  • ROS Melodic安装教程,https://blog.csdn.net/qq_35395195/article/details/122114402
  • 【杂记1】PC-Ubuntu18.04.5+ROS-melodic环境下安装cartographer功能包,https://blog.csdn.net/weixin_46135347/article/details/122748871

你可能感兴趣的:(学习,机器人,算法)