Installation of Cartographer tutorial and stepping pit

Keywords: Machine Learning AI Autonomous vehicles

Cartographer installation tutorial and pit record

Copyright notice: This article is reproduced from the original article of CSDN blogger "white boots", in accordance with CC 4.0 BY-SA copyright agreement. Please attach the original source link and this notice.
Original link: https://blog.csdn.net/weixin_44684139/article/details/104708387

Because I'm learning ros with Hu Chunxu's book, now I see the chapter of cartographer laser slam, so I install carto

But I never expected that there were so many pits in this thing!
Several important reference links, thank these bloggers for their guidance:

https://blog.csdn.net/qq_26482237/article/details/92676267
https://blog.csdn.net/qq_40081208/article/details/101606899
https://blog.csdn.net/m0_37923410/article/details/87407841
https://blog.csdn.net/seeseeatre/article/details/84863485?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
https://blog.csdn.net/qq_38649880/article/details/87903654?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
https://blog.csdn.net/mrh1714348719/article/details/103803110
https://blog.csdn.net/FK2016/article/details/83375048

First of all, I use the installation method of the official website (that is, the method introduced in the book).

Before that, let's make some very important preparations

0. Preparation

  1. Solve the problem of slow github cloning (there are many posts on the Internet. If you can't fq, consider modifying hosts)
  2. Join Google server domain name
sudo gedit /etc/resolv.conf

Comment the original nameserver line and add the following two lines:

nameserver 8.8.8.8 
nameserver 8.8.4.4 

Then save and close the file. This is for the future wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
This line of command paves the way. (otherwise it will be very slow. We'll talk about this later)

  1. Try to connect the mobile phone hotspot for the following download operations
  2. Install some necessary dependent packages:
sudo apt-get install -y \
    cmake \
    g++ \
    git \
    google-mock \
    libboost-all-dev \
    libcairo2-dev \
    libeigen3-dev \
    libgflags-dev \
    libgoogle-glog-dev \
    liblua5.2-dev \
    libsuitesparse-dev \
    libwebp-dev \
    ninja-build \
    protobuf-compiler \
    python-sphinx

Note that there is no libprotobuf dev!!!! This is installed in the following version
Secondly, note that some packages have version requirements, such as gmock (Google mock), which must be installed in the above way, if you installed them by compiling..... Be lucky, because some libraries add new features of C++11, but they can't match the installation dependency of cartographer.

Of course, the eigen library version may have little impact, that is, the installation location may need to be changed.

1. Install protobuf3

This is a very important step, because I installed proto2 when I installed ros. This lower version is not applicable to cartographer, so I reinstall proto3.
reference resources: https://blog.csdn.net/FK2016/article/details/83375048
Of course, without reference, look at me here:

  1. Unload ros proto2
# sudo apt-get remove libprotobuf-dev
# which protoc
// After running "which protoc ol", a path of protocol will be displayed. If it is not displayed, the following command does not need to be executed
# rm /usr/local/bin/protoc
// The specific path is subject to "which protoc ol". If it is the default, it is more likely to be usr / bin / protocol
 
Here, lower versions protobuf Uninstall complete.
  1. Install protobuf 3.6.0

(1) Install dependent libraries first

# sudo apt-get install autoconf automake libtool curl make g++ unzip

(2) Next, clone the source code. Note that the git submodule update --init --recursive cloning submodule must be available, otherwise an error will be reported later (the error that the file cannot be found). Of course, if you did not solve the problem of slow github download (0-1), it may be slow despair here.

# git clone -b v3.6.0 https://github.com/protocolbuffers/protobuf.git
// The above command means cloning the protobuf source code of version 3.6.0
# cd protobuf
# git submodule update --init --recursive
// This command means cloning the sub modules of protobuf, mainly gtest

(3) Compile and install

// Enter the cloned protobuf directory. Of course, if you were in this directory before, you don't have to cd again
# cd protobuf
# ./autogen.sh
# ./configure
# make
// If there is no clone sub module, make check will fail, but you can continue to make install, but errors may occur when using some functions
# make check
# sudo make install
# sudo ldconfig
// If the protobuf version information is output, the installation is successful
# protoc --version

Finally, check the installation location

which protoc

The result should be:

You can see that the default download location is / usr / local / bin / protocol
This is what we don't want, because the path of carto's search protocol is / usr / bin / protocol

Therefore, there are two adjustment methods, and the second one is recommended to be crisp:
① Establish soft connection

$ sudo ln -s /usr/local/bin/protoc /usr/bin/protoc

If you regret it, how to delete the soft connection? See this article
https://blog.csdn.net/weixin_44684139/article/details/104603432

② copy directly

sudo cp /usr/local/bin/protoc /usr/bin

Or just manually copy
Finally, the protobuf version 3.6 is installed and the position is adjusted.

2. Install cartographer

  1. Installation tools
sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build
  1. Create work interval "carto_ws" and initialize
mkdir carto_ws
cd carto_ws
wstool init src
  1. Join cartographer_ros.rosinstall and update dependencies

If you don't make preparations and add the Google server domain name (0-2), the link of merge may timeout. If it still doesn't work, please refer to https://www.it610.com/article/1288240522342739968.htm Write content directly to the file.

wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
 After entering the first command, you need to change the download address of the file and start the terminal to enter:
gedit carto_ws/src/.rosinstall
 Put the last one git Source URL by https://Change ceres-solver.googlesource.com/ceres-solver.git to https://github.com/ceres-solver/ceres-solver.git
wstool update -t src

Note here that the git source URL of the last Ceres solver is changed

If it is not changed, the cloning of Ceres solver will time out
Eventually in your workspace:

  1. Install dependency and download cartographer related function packs
    Note that rosdistro=kinetic -y is based on your version of ros
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y
(My default version is kinetic,If other ROS Version (replace accordingly)

However, an error may be reported here:

ERROR: error loading sources list:
The read operation timed out

This is an old problem of rosdep update. If you prepare 0-3, that is, change 4G for these operations, it should be easy to pass here.
If not, change the waiting time:

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

DOWNLOAD_TIMEOUT = 15.0 changed to 500

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

DOWNLOAD_TIMEOUT = 15.0 changed to 500

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

DOWNLOAD_TIMEOUT = 15.0 changed to 500

Note that all three are indispensable (of course, the number of 500 is given by chance, which is larger than the previous number)
Then, the success probability of rosdep update will increase again. If it is stuck, you can do it again several times

  1. Compile and install
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash

If catkin_ make_ Isolated -- install -- use Ninja this step reports an error (such as:... proto... Error of undefined reference, etc.)! That's not good. Maybe your protoc3 is not installed successfully or protoc2 remains. Of course, the most optimistic situation is that you don't adjust the location of protoc3. Just go back to steps 1-2-3 to adjust the location. Otherwise, you need to uninstall protoc2 or 3, reinstall protoc3 and repeat all steps

It will also report some other wonderful errors, such as the gmock library needs the C++11 standard, and so on. Because the version of the dependent library is wrong. It needs to be uninstalled and reinstalled. For reinstallation, use the installation method described in the initial 0. Preparation above. Of course, sudo apt get install... -- reinstall may be used here

If no error is reported, the installation is successful.

Of course, you can put the last line of command into the bashrc file, otherwise you need to enter it every time you run the demo, otherwise you can't find the launch file
use:

source /home/mjy/dev/carto_ws/install_isolated/setup.bash

You can also manually add a hidden file where the bashrc file is located under home /.

6. Conclusion - Test
stay cartographer official website
① First download a 2D package, such as

Then compile:
Its format is
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename: = follow the path of bag

roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=/home/mjy/dev/carto_ws/b0-2014-07-21-12-42-53.bag

② Test another 3D package

roslaunch cartographer_ros demo_backpack_3d.launch bag_filename: = follow the path of bag

roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=/home/mjy/dev/carto_ws/b3-2016-03-01-13-39-41.bag 

3. Supplement

If you want to install the turnbot, you should follow the original process, create a new workspace, and then balabala
Just need to

wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall

That is, the sentence requiring Google server should be changed to:

wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_turtlebot/master/cartographer_turtlebot.rosinstall

Just like other processes, you can refer to: https://www.ncnynl.com/archives/201810/2777.html

Copyright notice: This is the original article of CSDN blogger "white boots", which follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this notice for reprint. Original link: https://blog.csdn.net/weixin_44684139/article/details/104708387

Posted by aaaaCHoooo on Thu, 21 Oct 2021 19:52:42 -0700