ros部署orbslam2算法使用Astra pro相机输入
ros 中部署ORBslam2
Ubuntu 20.04 LTS
opencv 3.4.5
Pangolin 0.6
eigen 3.4
ros noetic
ros_astra_camera <= 1.2.0
ORBSLAM2 编译
安装依赖
编译 OpenCV 3.4.5
下载对应版本
https://opencv.org/releases/
添加新的源
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
安装依赖项
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev
sudo apt-get install libavformat-dev libjpeg.dev libtiff5.dev
sudo apt-get install libswscale-dev libjasper-dev
sudo apt-get install libcanberra-gtk-module libcanberra-gtk3-module
#或者
sudo apt-get install libcanberra-gtk*
编译
mkdir build && cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv -D CMAKE_BUILD_TYPE="Release" -D OPENCV_GENERATE_PKGCONFIG=ON ..
make -j4
sudo make install
sudo ldconfig
查看安装版本
pkg-config --modversion opencv
编译 Pangolin
下载源码:https://github.com/stevenlovegrove/Pangolin.git
从 release 页面下载 v0.6 版本,高版本可能会带来兼容性问题
error: ‘decay_t’ is not a member of ‘std’; did you mean ‘decay’? 269 | function_traits<std::decay_t<T>>::ptr(t, d);
c++11 兼容性问题,在CmakeList 中换成 c++14
编译
cd Pangolin-0.6
mkdir build
cd build
cmake ..
make
sudo make install
验证安装
cd Pangolin-0.8/build/examples/HelloPangolin/
./HelloPangolin
出现一个可以拖动的方块
编译 eigen
从官网https://eigen.tuxfamily.org/index.php?title=Main_Page下载
cd eigen-3.4.0
mkdir build
cd build
cmake ..
make
sudo make install
查看 eigen 版本
pkg-config --modversion eigen3
编译 libORBSLAM2.so
下载 ORBSLAM2 项目
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
编译,使用项目自带的编译脚本
cd ORB-SLAM2
chmod +x build.sh
./build.sh
ORLBSLAM2 中的定义错误
/LoopClosing.cc:438:21: required from here
/usr/include/c++/9/bits/stl_map.h:122:71: error: static assertion failed: std::map must have the same value_type as its allocator
122 | static_assert(is_same<typename _Alloc::value_type, value_type>::value,
| ^~~~~
修改 include/LoopClosing.h
typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
Eigen::aligned_allocator<std::pair<const KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;
改为:
typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
Eigen::aligned_allocator<std::pair<KeyFrame *const, g2o::Sim3> > > KeyFrameAndPose;
此外可能会出现部分未定义的变量的问题,为 opencv4 兼容性问题,需要加上对应头文件
- usleep()未声明
error: ‘usleep’ was not declared in this scope
加上头文件
#include <unistd.h>
ROS 安装
安装ros noetic
- 添加ros的软件源。确保ros软件源是使用的国内源。这里我仍然使用清华源。这行命令与ARM还是X86_64无关,都是这个命令。下面两三步复制粘贴的事,不建议用鱼香ros的脚本一键安装ros。
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
- 密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
- 更新
sudo apt update
- 下载安装
sudo apt install ros-noetic-desktop-full
rosdep 安装
- 安装rosdep依赖项管理工具。 rosdep是ros的依赖项管理工具,在安装完ros之后建议安装此工具,但是在rosdep init和 rosdep update时国外的网站实在令人头疼。所以使用rosdepc。
cd ~/
wget http://fishros.com/install -O fishros && . fishros
在终端界面中按照提示,选择一键安装rosdepc那一项对应的数字,输入回车,会自动下载和完成rosdep init的工作。需要其他软件的,等下可以继续输入 .fishros来运行脚本,选择安装其他软件
rosdepc update
至此,rosdepc安装完毕并且更新好了依赖项
- 设置环境变量
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
更新环境变量或者重启电脑
source ~/.bashrc
验证安装
- 测试小乌龟
roscore
新开一个终端
rosrun turtlesim turtlesim node
ros 中安装 ORBSLAM2 节点
兼容性错误:
warning: libopencv_core.so.4.2, needed by /opt/ros/noetic/lib/libcv_bridge.so, may conflict with libopencv_core.so.3.4.5
ros noetic 版本中默认opencv 版本为 4.2,需要使用 cv_brige 使用系统的 opencv3
安装新的 cv_brige
https://github.com/ros-perception/vision_opencv
选择 noetic 分支,下载 cv_brige 文件夹,
修改cv_bridge中的cmakelists.txt
find_package(OpenCV 3.4.5 REQUIRED) //改成你安装的opencv的版本
- cmake单独编译cv_bridge
在cv_bridge文件夹下,
mkdir build
cd build
cmake ..
make
sudo make install
5.在开源代码需要的 cmaklist.txt
中添加 cv_bridge
的cmake路径
set(cv_bridge_DIR /usr/local/share/cv_bridge/cmake) //在find_package前面
相机驱动安装
- 安装依赖
# Assuming you have sourced the ros environment, same below
sudo apt install libgflags-dev ros-$ROS_DISTRO-image-geometry ros-$ROS_DISTRO-camera-info-manager\
ros-$ROS_DISTRO-image-transport ros-$ROS_DISTRO-image-publisher libgoogle-glog-dev libusb-1.0-0-dev libeigen3-dev
- 安装 libuvc 库
git clone https://github.com/libuvc/libuvc.git
cd libuvc
mkdir build && cd build
cmake .. && make -j4
sudo make install
sudo ldconfig
- 创建工作目录
mkdir -p ~/ros_ws/src
- 从 github 上下载驱动项目
cd ~/ros_ws/src
git clone https://github.com/orbbec/ros_astra_camera.git
- 编译
cd ~/ros_ws
catkin_make
- 安装 udev rules.
cd ~/ros_ws
source ./devel/setup.bash
roscd astra_camera
./scripts/create_udev_rules
sudo udevadm control --reload && sudo udevadm trigger
开启相机
- 终端1
source ./devel/setup.bash
roslaunch astra_camera astra.launch
- 终端2
source ./devel/setup.bash
rviz
查看 topic
rostopic list
rosservice list
rosparam list
虚拟机中USB 接口兼容问题
Corrupt JPEG data: premature end of data segment Unsupported marker type 0x5
将虚拟机的 USB 兼容属性设置为 3.1
相机标定
使用 ros 的 camera_calibration 进行相机标定
标定格子的size指的是内部的格点,大小的单位为 米(m),pattern 默认为 棋盘格
在视野范围内移动和俯仰和横滚,使得进度条全部变绿
然后点击 CALIBRATE 进行校准,等待结果
rosrun camera_calibration cameracalibrator.py --size 8x11 --square 0.020 image:=/camera/color/image_raw
image_width: 640
image_height: 480
camera_name: narrow_stereo
camera_matrix:
rows: 3
cols: 3
data: [589.06045, 0. , 320.55288,
0. , 589.17341, 242.21867,
0. , 0. , 1. ]
distortion_model: plumb_bob
distortion_coefficients:
rows: 1
cols: 5
data: [0.118159, -0.148536, -0.000417, -0.000129, 0.000000]
rectification_matrix:
rows: 3
cols: 3
data: [1., 0., 0.,
0., 1., 0.,
0., 0., 1.]
projection_matrix:
rows: 3
cols: 4
data: [602.99677, 0. , 320.47976, 0. ,
0. , 602.93842, 242.04032, 0. ,
0. , 0. , 1. , 0. ]
运行
根据 topic 名称修改 orbslam2 中 rgbd 源文件的输入流名称
使用标定结果更新 config 文件
启动相机
source ./devel/setup.bash
roslaunch astra_camera astra.launch
启动算法节点
rosrun ORB_SLAM2 RGBD Vocabulary/ORBvoc.txt Examples/RGB-D/astrapro.yaml