ROS Group
Product Service
Official website
Technological exchanges
ROS Tourials
Deep Learning
Computer Vision

xiaoqiang ROS robot tutorial (17)

  • administrators

    Xiaoqiang ROS Robot Tutorial (17)_Using ORB_SLAM2 to create a three-dimensional model of the environment

    To achieve visual navigation, a three-dimensional model of space is a must. ORB_SLAM is a very effective algorithm for building spatial models. This algorithm is based on the recognition of ORB feature points, with high accuracy and high operating efficiency. We have modified the original algorithm, added the map’s save and load functions, making it more applicable to the actual application scenario. The following describes the specific use.

    Prepared work

    Before starting ORB_SLAM2, please confirm that Xiaoqiang’s camera is working properly. In the use of ORB_SLAM2 in the process of building plans to move Xiaoqiang, in the process of moving Xiaoqiang inconvenient to display the ORB_SLAM2 running status (ssh remote operation is not smooth, it is impossible to drag the monitor), so please install Xiaoqiang map remote control windows client.

    Start ORB_SLAM2

    Change the configuration file. The configuration file for ORB_SLAM2 is located in the /home/xiaoqiang/Documents/ros/workspace/src/ORB_SLAM2/Examples/ROS/orb_slam2/Data folder. Change the value of LoadMap in the setting.yaml and set it to 0. When set to 1, the program automatically loads map data from the /home/xiaoqiang/slamdb folder after startup. When set to 0, map data will not be loaded. Since we want to create a map, LoadMap needs to be set to 0.


    Use ssh to enter Xiaoqiang and execute the following command

    ssh -X
    roslaunch ORB_SLAM2 map.launch

    Began to establish an environmental 3D model

    Open Xiaoqiang Tuzhu remote control windows client, click on the “Not connected” button to connect Xiaoqiang. Right-click in the image window to open the “original image” and “ORB_SLAM2’s feature point image”



    In the figure above, the left image is the camera’s original color image, and the right side is the ORB_SLAM2 processed black and white image. The current ORB_SLAM2 has not been initialized successfully, so the black and white image has no feature points. Hold down the “w” key to start the remote control Xiaoqiang slowly move forward, so that ORB_SLAM2 initialized successfully, that is, black and white images began to appear red and green features.


    It is now possible to begin remote control of Xiaoqiang’s construction of the surrounding environment. During the remote control process, it is necessary to ensure that the black-and-white image always has red and green feature points. If it does not exist, it means that the visual lost, and it is necessary to remotely control Xiaoqiang to return to the place where the last missed lost position. Client Operation Demo Video.

    Use rviz to view the build effect

    Add Xiaoqiang IP address in the local virtual machine hosts, then open a new terminal to open rviz.

    export ROS_MASTER_URI=http://xiaoqiang-desktop:11311

    Open the /home/xiaoqiang/Documents/ros/src/ORB_SLAM/Data/rivz.rviz configuration file. Some systems may not be able to open this file. You can copy the file locally and open it locally.


    As shown in the figure below, the red and black points are three-dimensional models (sparse feature point clouds) established, and the blue boxes are keyframes that can represent the tracks of Xiaoqiang.


    Save the map

    After the map has been created to meet the requirements, create a new command window in the VM and enter the following command to save the map:

    ssh -X
    rostopic pub /map_save std_msgs/Bool '{data: true}'  -1

    This command triggers the save task every 10 seconds, so when you see the image below, please close the above window. In the virtual machine, open a new command window and enter the following command to detect whether the map save command has been issued.

    ssh -X
    rostopic echo /map_save


    The map file will be saved in the slamdb folder in the user’s home directory.

    Loading of maps

    You can load the ORB_SLAM2 program again after saving the map. After the map is loaded, the program can quickly locate the specific location of the camera. In this way, visual positioning-based navigation algorithms can be developed. The way to load the map is also very simple. Set the value of LoadMap to 1 in the setting.yaml file in the /home/xiaoqiang/Documents/ros/workspace/src/ORB_SLAM2/Examples/ROS/orb_slam2/Data folder.

    Post processing of maps

    After creating the map, you want to use this map for navigation, you need to do further operations on the map file. For example, to create a navigation line, mark the navigation path to walk and so on. This section can be found in the article Visual Navigation Path Editor Tutorial.