SLAM Combat Project (2) — Run ORB-SLAM2 Dense Map Reconstruction under ROS

Table of contents

1 Operation steps

(1) Create a workspace

(2) Modify CmakeList.txt

(3) compile

(4) Download the bag file

(4) Write roslaunch file

2 running error

Error 1:

Error 2:

Error 3:

Error 4:


ROS learning documents: Introduction · Autolabor-ROS robot introductory course "ROS theory and practice" zero-based tutorial

1 Operation steps

(1) Create a workspace

mkdir -p /orbslam2_ws/src
cd /orbslam2_ws/src
cd ..
catkin_make
source ./devel/setup.bash
cd /orbslam2_ws/src
//将稠密建图的代码复制到/src目录下
cd ..
catkin_make
source ./devel/setup.bash

(2) Modify CmakeList.txt

Modify CmakeList.txt under /Examples/ROS/ORB-SLAM2
 

find_package(PCL 1.10 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
set(LIBS ${PCL_LIBRARIES})

(3) compile

Go to your ORB-SLAM2 folder and open the terminal

chmod +x ./build_ros.sh
./build_ros.sh

(4) Download the bag file

Download address: Computer Vision Group - Dataset Download

(4) Write roslaunch file

In ./orbslam2_ws/src/ORB_SLAM2 want to create a launch folder, create orbslam.launch file

<launch>
    <!--添加被执行的节点-->
    <node name = "ORB_SLAM2" pkg="ORB_SLAM2" type="RGBD" args="/home/qinlong/studydata/orbslam2_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/qinlong/studydata/orbslam2_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml" output="screen"/>
    <!--添加rosbag play-->
    <node pkg="rosbag" type="play" name="bag_play" args="/home/qinlong/bagfiles/rgbd_dataset_freiburg3_long_office_household.bag "/> 
</launch>

(5) run

Source ./devel/setup.bash under ./orbslam2_ws, and then run roslaunch ORB_SLAM2 orbslam2.launch to get the same effect.

2 running error

Error 1:

/usr/bin/ld: warning: libboost_filesystem.so.1.71.0, needed by /opt/ros/noetic/lib/libroscpp.so, may conflict with libboost_filesystem.so.1.80.0
/usr/bin/ld: warning: libopencv_imgcodecs.so.4.2, needed by /opt/ros/noetic/lib/libcv_bridge.so, may conflict with libopencv_imgcodecs.so.3.4
/usr/bin/ld: warning: libopencv_core.so.4.2, needed by /opt/ros/noetic/lib/libcv_bridge.so, may conflict with libopencv_core.so.3.4
/usr/bin/ld: ../../../../lib/libORB_SLAM2.so: undefined reference to `g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(g2o::Solver*)'
/usr/bin/ld: warning: libboost_filesystem.so.1.71.0, needed by /opt/ros/noetic/lib/libroscpp.so, may conflict with libboost_filesystem.so.1.80.0
/usr/bin/ld: warning: libopencv_imgcodecs.so.4.2, needed by /opt/ros/noetic/lib/libcv_bridge.so, maycollect2: error: ld returned 1 exit status
 conflict with libopencv_imgcodecs.so.3.4
/usr/bin/ld: warning: libopencv_core.so.4.2, needed by /opt/ros/noetic/lib/libcv_bridge.so, may conflict with libopencv_core.so.3.4
/usr/bin/ld: ../../../../lib/libORB_SLAM2.so: undefined reference to `g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(g2o::Solver*)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/RGBD.dir/build.make:254:../RGBD] 错误 1
make[2]: *** [CMakeFiles/Mono.dir/build.make:254:../Mono] 错误 1
make[1]: *** [CMakeFiles/Makefile2:157:CMakeFiles/RGBD.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务....
make[1]: *** [CMakeFiles/Makefile2:184:CMakeFiles/Mono.dir/all] 错误 2
make: *** [Makefile:130:all] 错误 2

Solution: This may be caused by not linking the g2o library correctly or the version of the g2o library is incompatible when compiling libORB_SLAM2.so. To relink the current project to g2o, you can change the content in the CMakeists.txt file and add the following code

target_link_libraries(project_name g2o -Wl,-rpath=${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o
)

Error 2:

/usr/bin/ld: warning: libopencv_core.so.4.2, needed by /opt/ros/noetic/lib/libcv_bridge.so, may conflict with libopencv_core.so.3.4

(11) ORBSLAM2 runs under ROS_Xiao C soy sauce soldier's blog-CSDN blog

Solution: The reason for the error is that ROS is inconsistent with the version of opencv installed by yourself. If there is no error, you can ignore the warning. When an error is reported, comment out the VR-related code according to the prompt.

Error 3:

After rosrun and rosbag, the bag information cannot be transmitted

rosrun ORB_SLAM3 RGBD Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml
rosbag play rgbd_dataset_freiburg3_long_office_household.bag

Solution:

View topic: rostopic list

/cam0/image_raw
/cam1/image_raw
/camera/depth/camera_info
/camera/depth/image
/camera/depth_registered/image_raw
/camera/left/image_raw
/camera/rgb/camera_info
/camera/rgb/image_color
/camera/rgb/image_raw
/camera/right/image_raw
/clock
/cortex_marker_array
/imu0
/leica/position
/rosout
/rosout_agg
/tf

Check the topic name under ros_rgbd.cc

message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/rgb/image_raw", 1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "camera/depth_registered/image_raw", 1);

Modify the topic name under ros_rgbd.cc

message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/rgb/image_color", 1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/camera/depth/image", 1);

Error 4:

After the previous step, it is found that the data can be imported, but the generated point cloud is abnormal.

Solution 1:  When using OpenCV to read the depth map in ROS, the 0 value in the depth map will be interpreted as an invalid (NaN) value, so that the pixel that fails to obtain the depth information can assign the depth value to 0. PointCloudMapping::GeneratePointCloud modify the following code:

void PointCloudMapping::GeneratePointCloud(KeyFrame* kf, cv::Mat &color_img, cv::Mat &depth_img)
    {
        PointCloud::Ptr tmp (new PointCloud());
        for ( int m=0; m<depth_img.rows; m+=3 )
        {
            for ( int n=0; n<depth_img.cols; n+=3 )
            {
                float d = depth_img.ptr<float>(m)[n];

                //修改部分
                if(std::isnan(d))
                {
                    d = 0.0;
                }
                ...
            }
        }
    }

Solution 2: If filter processing is performed, you can modify double resolution = 0.00000001. After modification, the color display is normal, but there is obvious drift, but the effect is much better than before.

Guess you like

Origin blog.csdn.net/qq_41921826/article/details/131012835