Do It Together rgb-d SLAM (1)

Source: Internet
Author: User

    • Objective

SLAM, simultaneous Localization and Mapping, Chinese translation simultaneous positioning and map creation, is a major research direction in the field of robotics in recent decades. As the core technology of autonomous robot, slam has important research significance in robot navigation, control and production. Especially in the 21st century, visual slam technology, which is centered on visual sensor, has undergone obvious transformation and breakthrough in theory and method, and is gradually moving from laboratory research to mature market application. At the time of foreign research, it is still in the initial stage of domestic research. The Chinese literature and books about slam are difficult to see. However, with the national attention of robotics technology, more and more young researchers and students are gradually entering this field. This document attempts to provide some simple and practical references for these colleagues who have just walked into slam.

Turnip: Brother! What are you writing on top of all this stuff?

Brother: They are all useless nonsense ah ... But there's no such thing as a document without a grade.

Turnip: Brother! You're not going to do this nonsense! Teach me to do slam!

Brother: Preface only wrote a paragraph, the reader will think I was perfunctory them. Forget it, no matter, the first two days let you run Rgbd-slam how?

Turnip: it's running! And then what?

Brother: Then you can tune the parameters, change the code what AH.

Turnip: Brother! I can't read it!

Brother: Well, this ...

Turnip: Brother! You write a slam program for me!

Brother: Well, this ...

Radish: Hurry up and write brother! You invited me to dinner after I finished!

Brother: Eat, that's all right ...

So, brother began to write this document. Because the senior also do not know when will be finished, so he every write a paragraph to show the radish (and then invite him to dinner). Fortunately, the radish enthusiasm is very high, every time he wrote a good code, take back to look carefully and ran. This also gave a big motivation to continue to write down.

    • The goal of this article

This article will lead the reader to write a rgb-d slam program.

Because I believe that only by writing their own program, can really understand the principle of slam.

Radish: Why write a slam program instead of using the existing code?

-Brother: For a deeper understanding.

    1. A complete program contains a lot of algorithms with GUI code, how long do you need to read it over? How long does it take to figure out the principle?
    2. Other tools are done, the code is finished, the parameters are also adjusted, you take over to run. That's the best thing to do for others.
    3. You'll have to write your own code sooner or later.

On the other hand, writing your own program does not mean using C + + to implement the linear algebra of matrices. We'll still use the basic library.

We want to use the library: OpenCV, PCL, G2o.

What are you waiting for? Let's do it!

    • Pre-knowledge and programming environment

Programming Environment: Ubuntu 12.04. Readers are advised to use the same or similar environment as we do. If you (for cool or any other reason) want to use ARCH/FEDORA/MAC, please do your own environment.

Installation of prerequisite software:

  1. OpenCV
    Recommended mode for installing from source code. The compilation process takes a little time.
    Step 1.
    Download OpenCV source code: http://opencv.org/downloads.html.
    Currently (2015.6) the better version is the 2.4 series, because the 3.0 series is not perfect (mainly without documentation). Please download it to a random directory on your computer.
    During the download process, you can install dependencies. Basic dependencies are underneath those, which are directly copied to the terminal to perform.
    1 sudo Install build-essential libgtk2. 0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk Libtbb-dev Libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev Libvorbis-dev Libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-  -dev Libavcodec-dev Libavformat-dev Libswscale-dev
    Step 2.
    Unzip the OpenCV into the download directory, and then install it with CMake compilation.
    mkdir BUILDCD Buildcmake.  Make sudo  Make Install

    The compilation process takes a little time, and the long-sighted configuration of your machine depends. A little slower may be over in the afternoon, so please find something else to do, such as watching a movie or something.
    Turnip: Where is OPENCV after it is loaded?
    Brother: The head file is in/usr/local/include/, there are OpenCV and Opencv2 's header files. We basically only use OPENCV2.
    Brother: The library file is under the/usr/local/lib/, of course, these can be changed at the time of install, I listed the default location.
    Turnip: Brother! What was the cmake that was just used?
    Brother: CMake is the C + + management tool under Linux. Simple code you can use g++ to knock, and more can be used makefile to manage, CMake is automatically generated makefile tools, higher than makefile integration.
    Radish: Oh, yes! I understand, brother! Please let me have dinner Oh!
    Brother: Good!

  2. Pcl

    The PCL is the point Cloud library, a must-have tool for dealing with points.
    Turnip: Brother! Why deal with point clouds?
    Brother: Ah ... Forget to say, this document is about rgb-d Slam, the depth of the camera is the point of the cloud data.
    Turnip: Why don't you put it in the beginning to say something so important?
    Brother: I forgot ...
    In any case, the PCL official website (http://pointclouds.org) has already given the Ubuntu installation method. Because a lot of development tools in Ubuntu is the most convenient to install, but also suitable for the novice radish, so we chose Ubuntu.
    Step 1.

    1 sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/PCL2sudo apt- Get update 3 sudo Install Libpcl-all

    Brother: How about that? Isn't it simple?
    Turnip: Yes!
    Brother: So, similarly, can you find the PCL header file and the installation directory of the library file? Let's leave this as the homework for the reader!
    Radish: Brother, aren't you afraid that the reader should blow up your phone?

Here, the necessary library is installed. If you need to install another software later, we'll talk about it separately.

    • HELLO slam!

We have installed the OPENCV and PCL, so let's start writing the first program!

Radish: Finally, you can start writing programs! I love to write the program! I feel the programmer's soul burning inside me!

Brother: Well, but what's our first program to do?

Turnip: Let's write Slam right now!

Brother: But then readers can read it ... Let's start with something simple.

Radish: Good! Then write a simple slam!.

Brother: No, no, first of all, let's build a CMake project as a template for future code writing. The reader may find it difficult to begin with, but it is difficult at first, and then you get used to it.

The CMake project under Linux is usually made up of several folders. For example, the slam that we are talking about today, you can build a folder called Slam on the machine (note: This folder is the root directory of your code!) )。 Then build a few subfolders inside:

  

The bin is used to put the compiled executable binary files.
SRC is used to place source code.
Lib is used to put a compiled library file.
Include is used to place a header file.

Why use this directory structure? In fact, this is a compilation habit, of course, you can put all the files in a directory, but this looks very messy is not it. Usually we separate the source code from the compiled thing. If the source code is more, it will also be separated by the template. Code like OPENCV and PCL is made up of a good number of modules.

We're going to tell cmake the directory structure. So we write a CMakeLists.txt in the code root directory. CMake reads this file when it generates code and compiles your code according to it. We also used this step when we compiled the OPENCV. OK, now create a new CMakeLists.txt in the Code root directory:

Touch CMakeLists.txt

Write:

Cmake_minimum_required (VERSION 2.8) #设定版本PROJECT (slam) #设定工程名SET (Cmake_cxx_compiler "g++") #设定编译器 # Sets the directory set of executable binaries ( Executable_output_path ${project_source_dir}/bin) #设定存放编译出来的库文件的目录SET (Library_output_path ${project_source_dir}/ LIB) #并且把该目录设为连接目录LINK_DIRECTORIES (${project_source_dir}/lib) #设定头文件目录INCLUDE_DIRECTORIES (${project_source_dir}/ Include) #增加子文件夹, that is, enter the source code folder to continue building Add_subdirectory (${PROJECT_SOURCE_DIR}/SRC)

The number behind the well is my comment, just to help you understand that you can not knock. Through this file, you should understand some basic usage of CMakeLists.txt. If you are looking for a system introduction, we provide the "CMake Practice" ebook, which I think is a good reference.

Radish: Wait a second, brother! What are the library files and binaries?

Brother: Binary is a program that can run directly, library files, is to provide functions for these binary. The code with the main function can be compiled into binary, and the others are compiled into a library file. Link, the library file chain to the binary, you can run it.

Radish: Senior I still do not understand!

Brother: Well, let's do it by example. Create a new main.cpp file under the src/folder and enter:

1 #include <iostream>23int main (intChar* *argv)  4{5     std::cout<<"Hello slam! "<<Std::endl; 6     return 0 ; 7 }

This is, of course, a very simple, straightforward procedure. So I didn't add any comments. Then, we will generate a binary from this source code. Create a new CMakeLists.txt in the src/directory and enter:

# Add an executable binary add_executable (main main. CPP )

In this way, CMake will compile this main.cpp into a binary called Main. Come and try it. First go to the code root and enter:

1 mkdir Bulid 2 CD Build 3 CMake . 4  Make

If compiled, it will generate a binary of main in the bin/directory! If you execute this binary, it will output the statement of Hello Slam!

Do you think this program is too simple? It's okay, it's hard in the back!

Radish: Is that the end of the story?

Brother: Yes ... After all, it's hard to write, I have to take a break.

Radish: But we basically didn't write any program Ah!

Brother: Don't worry, you first take CMake to learn, then the work will have to do on this.

Turnip: All right! What are we going to do next, brother?
Brother: Well, we'll use OpenCV to read a picture, and then turn it into a point cloud, how about it?
Radish: It doesn't sound so hard, so say goodbye to the next one!

The PDF version of this article, source code, pictures and other resources can be downloaded in my git.

Website: HTTPS://GITHUB.COM/GAOXIANG12/RGBD-SLAM-TUTORIAL-GX

Do It Together rgb-d SLAM (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.