Google Cartographer安装教程

官方安装步骤太复杂,而且容易失败
以下安装全部从hitcm大神的github下载,源码一样只是编译文件有所修改,亲测ubuntu16 ros kinetic一次成功
感谢hitcm 大神的无私分享

一、简单安装:

1.安装所有依赖项

sudo apt-get install -y google-mock libboost-all-dev  libeigen3-dev libgflags-dev libgoogle-glog-dev liblua5.2-dev libprotobuf-dev  libsuitesparse-dev libwebp-dev ninja-build protobuf-compiler python-sphinx  ros-kinetic-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev

2. 安装ceres solver,版本是1.11

git clone https://github.com/hitcm/ceres-solver-1.11.0.git
cd ceres-solver-1.11.0
mkdir build
cd build
cmake ..
make -j4
sudo make install

3. 安装 cartographer

git clone https://github.com/hitcm/cartographer.git
cd cartographer
mkdir build
cd build
cmake .. -G Ninja
ninja
ninja test
sudo ninja install

4.安装cartographer_ros

#初始化工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
echo "source catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

#安装cartographer_ros
cd ~/catkin_ws/src
git clone https://github.com/hitcm/cartographer_ros.git
cd ~/catkin_ws
catkin_make

二、官方安装

1.依赖安装

sudo apt-get install -y \
    g++ \
    git \
    google-mock \
    libboost-all-dev \
    libcairo2-dev \
    libeigen3-dev \
    libgflags-dev \
    libgoogle-glog-dev \
    liblua5.2-dev \
    libsuitesparse-dev \
    ninja-build \
    python-sphinx

2.安装ceres-solver版本1.13.0 、安装protobuf版本3.4.1

# Build and install Ceres.
git clone https://ceres-solver.googlesource.com/ceres-solver
cd ceres-solver
git checkout tags/1.13.0
mkdir build
cd build
cmake .. -G Ninja -DCXX11=ON
ninja
CTEST_OUTPUT_ON_FAILURE=1 ninja test
sudo ninja install

# Build and install proto3.
git clone https://github.com/google/protobuf.git
cd protobuf
git checkout tags/v3.4.1
mkdir build
cd build
cmake -G Ninja \
  -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  -DCMAKE_BUILD_TYPE=Release \
  -Dprotobuf_BUILD_TESTS=OFF \
  ../cmake
ninja
sudo ninja install

3.安装cartographer

# Build and install Cartographer.
cd cartographer
mkdir build
cd build
cmake .. -G Ninja

DProtobuf_DIR="/usr/local/lib/cmake/protobuf/" -DPROTOBUF_INCLUDE_DIR="/usr/local/include/google/protobuf/" -DPROTOBUF_LIBRARY="/usr/local/lib/libprotobuf.a" 

ninja
CTEST_OUTPUT_ON_FAILURE=1 ninja test
sudo ninja install

注意:如果报protobuf的错误
1. protoco –versian查看版本是否正确
2. 编译加DProtobuf_DIR、DPROTOBUF_INCLUDE_DIR、DPROTOBUF_LIBRAR指定路径

4.安装cartographer_ros

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

mkdir -p /code/ROS/catkin_ws_cartographer/src
cd /code/ROS/catkin_ws_cartographer/src
git clone --recursive https://github.com/googlecartographer/cartographer_ros.git

cd /code/ROS/catkin_ws_cartographer
catkin_make_isolated --install --use-ninja -Dcartographer_DIR="/usr/local/share/cartographer/"
source /code/ROS/catkin_ws_cartographer/devel_isolated/setup.bash
echo "source /code/ROS/catkin_ws_cartographer/devel_isolated/setup.bash" >> ~/.bashrc

5.数据下载测试

2d数据

https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag

3d数据

https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/cartographer_3d_deutsches_museum.bag
运行launch文件即可
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/cartographer_3d_deutsches_museum.bag

Google Cartographer安装教程_第1张图片
实验结论:使用自己的单线激光雷达与使用数据集效果无差,表现都很好,基本上没有什么误差

其他

cartographer发布的静态地图与mapserver的值不一致,具体表现为在cartographer代价区间在0~100,mapserver代价区间在0~255

//修改cartographer发布OccupancyGrid的程序位于occupancy_grid_node_main.cc中。关注CreateOccupancyGridMsg这一函数的调用。具体修改msg_conversion.cc

std::unique_ptr CreateOccupancyGridMsg(
  ...
  for (int y = height - 1; y >= 0; --y) {
    for (int x = 0; x < width; ++x) {
      const uint32_t packed = pixel_data[y * width + x];
      const unsigned char color = packed >> 16;
      const unsigned char observed = packed >> 8;

      int value_temp = ::cartographer::common::RoundToInt((1. - color / 255.) * 100.);
      if (value_temp > 65)
          value_temp = 100;
      else if (value_temp < 10)
          value_temp =  0;
      else
          value_temp += 0;  
      const int value =
          observed == 0
              ? -1
              : value_temp;
      CHECK_LE(-1, value);
      CHECK_GE(100, value);
      occupancy_grid->data.push_back(value);
    }
  }

  return occupancy_grid;

你可能感兴趣的:(SLAM探索总结)