Realsense d435i 驱动安装以及kalibr和imu_utils标定[Ubuntu 16 LTS]

为什么要标定?

在进行视觉方向的研究时,往往会接触到各种各样的传感器,对于深度相机来说,有很多参数是未知的,比如说光学相机的内参(不知道什么是内参可以查一下资料).就目前slam的现状而言,想要有较鲁棒的效果,就要有一个还不错的初始化,要有还不错的初始化,就要有还行的传感器标定来支撑这些工作.
事实上也有很多大佬发了标定教程,我写这篇博客目的是为了交流(水经验),顺便熟悉一下标定流程,巩固已有知识.尽量不查找现有博客的情况下,进行这个工作.也是对自己的一种锻炼

具体工作

具体工作分两部走,首先下载安装realsense驱动,和ros驱动,然后利用kalibr这个工具进行标定.由于之前在办公室电脑安装过…所以知道有的地方会特别的慢,挂VPN可以解决.

1.gayhub 找librealsense安装驱动

realsense地址戳这里

1.1apt方式安装

Ubuntu 16 LTS:

sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main" -u

Ubuntu 18 LTS:

sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo bionic main" -u

1.1.1 安装lib

sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils

这时候你就可以重新差一下d435i
然后终端运行
realsense-viewer确定你已正确安装
Realsense d435i 驱动安装以及kalibr和imu_utils标定[Ubuntu 16 LTS]_第1张图片

1.2 源码编译安装

参考自这篇博客(我好像打自己脸了)
这篇博客的操作我没做,没做!真的没!只是给你们参考一下

#ke long一下
git clone https://github.com/IntelRealSense/librealsense
cd librealsense
#install some dependencies
sudo apt-get install libudev-dev pkg-config libgtk-3-dev
sudo apt-get install libusb-1.0-0-dev pkg-config
sudo apt-get install libglfw3-dev
sudo apt-get install libssl-dev
#这个应该是权限相关的
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger 
#eject your d435i device and run these code
./scripts/patch-realsense-ubuntu-lts.sh
sudo dmesg | tail -n 50
#make your project via cmake
mkdir build
cd build
cmake ../ -DBUILD_EXAMPLES=true
make
sudo make install

Now you finished the installation,have a try:

./rs-capture 

1.3 安装realsense-ros

找个地方放好这个宝贝
创建catkin workspace

mkdir -p ~/catkin_ws/src #如果你已经有了,就跳过
cd ~/catkin/src

clone

git clone https://github.com/IntelRealSense/realsense-ros.git
cd realsense-ros/
#check version
git checkout `git tag | sort -V | grep -P "^\d+\.\d+\.\d+" | tail -1`
cd ..  

编译

catkin_init_workspace
cd ..
catkin_make clean
catkin_make -DCATKIN_ENABLE_TESTING=False -DCMAKE_BUILD_TYPE=Release
catkin_make install
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

如果出现这样的错误:

CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by
  "ddynamic_reconfigure" with any of the following names:
    ddynamic_reconfigureConfig.cmake
    ddynamic_reconfigure-config.cmake

进行如下操作之后在进行编译

cd ~/catkin_ws/src
git clone https://github.com/pal-robotics/ddynamic_reconfigure.git

回去编译realsense_ros
运行roslaunch realsense2_camera rs_camera.launch(要记得source ~catkin_ws/devel/setup.bash哦)

[ INFO] [1571704541.243366196]: setupPublishers...
[ INFO] [1571704541.252026915]: Expected frequency for depth = 30.00000
[ INFO] [1571704541.340746698]: Expected frequency for infra1 = 30.00000
[ INFO] [1571704541.424141364]: Expected frequency for infra2 = 30.00000
[ INFO] [1571704541.496796702]: Expected frequency for color = 30.00000
[ INFO] [1571704541.536956766]: setupStreams...
[ INFO] [1571704541.537596667]: insert Depth to Stereo Module
[ INFO] [1571704541.537661607]: insert Color to RGB Camera
[ INFO] [1571704541.537724571]: insert Infrared to Stereo Module
[ INFO] [1571704541.537764894]: insert Infrared to Stereo Module
[ INFO] [1571704541.537792457]: insert Gyro to Motion Module
[ INFO] [1571704541.537838527]: insert Accel to Motion Module
[ INFO] [1571704541.551826830]: SELECTED BASE:Depth, 0
[ INFO] [1571704541.574865680]: RealSense Node Is Up!

2.进行标定

imu_utils
kalibr在这
简单介绍一下kalibr,他是一个很强大的标定工具,可以解决多相机标定,视觉imu模组的标定(camera-IMU),以及卷帘快门相机(Rolling Shutter Camera)的标定等等.

2.1 下载编译

imu_utils编译

cd ~/catkin_ws/src
git clone https://github.com/gaowenliang/code_utils.git #这是code utils 安装imu utils前要有这个
cd ..
catkin_make
cd src
git clone https://github.com/gaowenliang/imu_utils.git
catkin_make

Resiquite:

sudo apt-get install python-setuptools python-rosinstall ipython libeigen3-dev libboost-all-dev doxygen libopencv-dev ros-kinetic-vision-opencv ros-kinetic-image-transport-plugins ros-kinetic-cmake-modules python-software-properties software-properties-common libpoco-dev python-matplotlib python-scipy python-git python-pip ipython libtbb-dev libblas-dev liblapack-dev python-catkin-tools libv4l-dev

python-igraph installation:

sudo pip install python-igraph --upgrade

build it:

cd ~
mkdir -p kalibr_ws/src
cd kalibr_ws/
catkin_make
source devel/setup.bash
cd ~/kalibr_ws/src
git clone https://github.com/ethz-asl/kalibr.git
cd ..
catkin build -DCMAKE_BUILD_TYPE=Release -j16

2.2 calibrate

首先是用imu_utils标定imu的角速度以及加速度的随机游走和噪声
找到rs_camera.launch这个文件,在realsense-ros的launch文件夹里面,修改



然后

roslaunch realsense2_camera rs_camera.launch
rosbag record /camera/imu #把相机放在一个地方静止不动,录制2小时的imu数据
#开一个终端 
rosbag play -r 200 your_imu_data.bag

#在/imu_utils/launch/文件夹下面添加一个realsense.launch文件,内容如下:

<launch>
    <node pkg="imu_utils" type="imu_an" name="imu_an" output="screen">
        <param name="imu_topic" type="string" value= "/camera/imu"/>
        <param name="imu_name" type="string" value= "realsense"/>
        <param name="data_save_path" type="string" value= "$(find imu_utils)/data/"/>
        <param name="max_time_min" type="int" value= "120"/>
        <param name="max_cluster" type="int" value= "100"/>
    </node>
</launch>

#再开一个终端
roslaunch imu_utils realsense.launch

然后在imu_utils/data下找到realsense开头的标定结果。

touch ~/calibration/imu_d435i.yaml
内容如下:

rostopic: /camera/imu
update_rate: 250.0 #Hz
# 这里的数据是前面标定结果,只需要取avg 值就ok
accelerometer_noise_density: 3.1484590206428492e-02
accelerometer_random_walk: 4.8466887224622534e-04
gyroscope_noise_density: 3.3647879366480102e-03
gyroscope_random_walk: 3.6237137067216794e-05

在标定camera-imu之前你需要到这里 下载标定用的标定板和配置文件,具体怎么使用看看kalibr的wiki. 把标定纸打印出来,原样打印,保证尺寸是相同的
整个流程如下:
1.用rosbag 录制 双目摄像头的数据,进行双目摄像头内参标定

2.根据imu和步骤1得到的相机内参,录制stereo_IMU的数据包,进行imu和相机的联合标定最终得出标定结果


#将相机的数据降频到10,这时候得到新的topic叫/left_cam
rosrun topic_tools throttle messages /camera/infra1/image_rect_raw 10 /left_cam
#再打开一个终端,作用同上
rosrun topic_tools throttle messages /camera/infra2/image_rect_raw 10 /right_cam
#再开一个终端用于录制数据
cd ~/calibration
rosbag record -o stereo.bag /left_cam /right_cam
# ctrl+c同时按,得到录制的bag包

start calibrate via the command follow:

rosrun kalibr kalibr_calibrate_cameras --bag /home/damon/stereo.bag --topics /left_cam /right_cam --models pinhole-radtan pinhole-radtan --target /home/damon/Downloads/april_6x6_80x80cm.yaml

标定单目的(color)的话一样,录制数据的时候只需要录制单目,然后–topics 只需要一个topic
kalibr 的wiki

碰到的一些错误:

错误1:No corners could be extracted for camera /left_cam! Check the calibration target configuration and dataset
解决办法:首先要做的是确定topic没错,具体怎么看,关掉所有跟摄像头有关的终端,一个终端运行roscore,另外一个终端运行rosbag play your.bag 然后用rqt查看输出的内容,我这里发现d435i的红外线干扰到特征提取,经过一番搜索暂时没有找到解决办法。。所以我用眼镜布,把红外传感器遮住,重新录制数据解决问题。
Realsense d435i 驱动安装以及kalibr和imu_utils标定[Ubuntu 16 LTS]_第2张图片

错误2:‘max must be larger than min in range parameter.’)
ValueError: max must be larger than min in range parameter.
解决办法:发现这个问题的时候我也一脸懵逼。。应该是图形化展示标定结果失败,我看到目录下出现了camchain开头的标定文件,vim一下。。里面全是空值,所以初步估计标定失败导致控值无法展示,重新录制数据,多方面多角度多pose录制一遍,得到解决。
终于走入正轨:
Realsense d435i 驱动安装以及kalibr和imu_utils标定[Ubuntu 16 LTS]_第3张图片 错误3:ImportError: cannot import name NavigationToolbar2Wx
解决办法:将/home/damon/kalibr_ws/src/kalibr/Schweizer-Messer/sm_python/python/sm/PlotCollection.py中的from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar修改为
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as Toolbar

现在你已经标定好双目了。开始录制imu_stereo数据…(深夜了。。明天再更把)

前面已经准备了imu_d435i.yaml,是你设备的imu一些随机游走参数

录制imu数据,注意要多角度,camera的频率可以高点,我用默认30fps否则会提示没有足够的特征点,确保imu的加速度和角速度计每一轴都有充分的激励,并且相机要保持观测标定板

rosbag record -o stereo_imu.bag /left_cam_topic /right_cam_topic /camera/imu

标定这里有一个前面标定双目时候的标定结果,imu的参数yaml

kalibr_calibrate_imu_camera --target ./april_6x6_80x80cm.yaml --cam ./camchain-homedamonsh_for_kalibrstereo.yaml --imu ./imu_d453i.yaml --bag /home/damon/stereo_imu.bag --bag-from-to 5 110

出现以下信息就是正在开始标定了,去洗个澡,吃个饭,差不多就标定结束了

Optimizing...
Using the block_cholesky linear system solver
Using the levenberg_marquardt trust region policy
Using the block_cholesky linear system solver
Using the levenberg_marquardt trust region policy
Initializing
Optimization problem initialized with 20977 design variables and 538535 error terms
The Jacobian matrix is 1213884 x 94378
[0.0]: J: 1.71275e+07

到这里标定结束,要想有比较好的标定结果,必须使得加速度和角速度得到充分激励,就是不能单纯的旋转,也不能单纯的平移,并且一直观测到标定版。

你可能感兴趣的:(SLAM)