ROS实验笔记之——基于kalibr来标定DAVIS346

Posted gwpscut

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ROS实验笔记之——基于kalibr来标定DAVIS346相关的知识,希望对你有一定的参考价值。

之前博客《ROS学习笔记之——DAVIS346 calibration》已经实现了用dv-gui(Calibration [Tutorial] · DV)来标定event camera了。但是缺少了跟IMU的外参标定等等。本博文利用Kalibr库来对其进行标定。

Kalibr安装

先创建一个工作空间

mkdir -p ~/kalibr_workspace/src
cd ~/kalibr_workspace
source /opt/ros/melodic/setup.bash
catkin init
catkin config --extend /opt/ros/melodic
catkin config --merge-devel
catkin config --cmake-args -DCMAKE_BUILD_TYPE=Release

cd ~/kalibr_workspace/src
git clone https://github.com/ethz-asl/Kalibr.git

cd ~/kalibr_workspace
catkin build -DCMAKE_BUILD_TYPE=Release -j4

可能会提示缺少libv4l,安装依赖包即可:

sudo apt-get install libv4l-dev

建立完之后需要source一下

source ~/kalibr_workspace/devel/setup.bash

还是没有办法。。。。还要把操蛋的opencv4安装了。。。。。

改为参考:melodic 安装 kalibr_matthewsyc的博客-CSDN博客

sudo apt-get install python-setuptools python-rosinstall ipython 
sudo apt-get install libeigen3-dev libboost-all-dev doxygen
sudo apt-get install ros-melodic-cmake-modules python-software-properties 
sudo apt-get install software-properties-common libpoco-dev python-matplotlib 
sudo apt-get install python-scipy python-git python-pip ipython libtbb-dev 
sudo apt-get install libblas-dev liblapack-dev python-catkin-tools libv4l-dev
sudo apt-get install python-igraph

安装完依赖后,编译好像就比较正常了~

每次运行前,记得加入

source ~/kalibr_workspace/devel/setup.bash

IMU标定

产生数据写入imu.yaml中,imu.yaml文件要用于联合标定。

imu_utils依赖code_utils,要先安装code_utils再安装imu_utils。

mkdir -p ~/imu_catkin_ws/src
cd ~/imu_catkin_ws/src
catkin_init_workspace
cd ..
catkin_make
source ~/imu_catkin_ws/devel/setup.bash

cd ~/imu_catkin_ws/src
git clone https://github.com/gaowenliang/code_utils.git
cd ..
catkin_make

可能出现报错,试试运行

sudo apt-get install libdw-dev

catkin_make时出现backward.hpp没有找到

解决方法:将sumpixel_test.cpp中# include "backward.hpp"改为:#include “code_utils/backward.hpp”

即可安装成功!

然后下载imu_utils

cd ~/imu_catkin_ws/src/
git clone https://github.com/gaowenliang/imu_utils.git
cd ..
catkin_make

然后运行

roslaunch vins davis_testing.launch

rostopic list

rostopic echo /dvs/imu

记录imu信息,这个过程要保持imu静止不动至少2个小时(这个太夸张了吧。。。)

17.26开始

在imu_utils文件下的launch文件目录下添加一个launch文件,我这里添加的是 imu.launch,并把以下代码复制进文件,代码中的/IMU_data改成自己imu的topic。

<launch>
    <node pkg="imu_utils" type="imu_an" name="imu_an" output="screen">
        <!--TOPIC名称-->
        <param name="imu_topic" type="string" value= "/dvs/imu"/>
        <!--imu_name 无所谓-->
        <param name="imu_name" type="string" value= "imu_davis346"/>
         <!--标定结果存放路径-->s
        <param name="data_save_path" type="string" value= "$(find imu_utils)/data/"/>
        <!--数据录制时间-min-->
        <param name="max_time_min" type="int" value= "120"/>
         <!--采样频率,即是IMU频率,采样频率可以使用rostopic hz /dvs/imu查看,设置为400,为后面的rosbag play播放频率-->
        <param name="max_cluster" type="int" value= "400"/>
    </node>
</launch>

运行之前要先source一下

source ~/imu_catkin_ws/devel/setup.bash
roslaunch imu_utils davis_imu.launch
rosbag play -r 400 /home/kwanwaipang/dataset/gwphku/hku_davis346_imu_2021-10-25-17-26-06.bag
rosbag play /home/kwanwaipang/dataset/gwphku/hku_davis346_imu_2021-10-25-17-26-06.bag

   标定结束后在imu_catkin_ws/src/imu_utils/data中生成许多文件,其中(d435i_imu_param.yaml)imu_davis346_imu_param.yaml就是我们想要的结果,展示如下:

%YAML:1.0
---
type: IMU
name: imu_davis346
Gyr:
   unit: " rad/s"
   avg-axis:
      gyr_n: 3.4207443164969696e-03
      gyr_w: 5.0328372766535944e-05
   x-axis:
      gyr_n: 2.8679837408646372e-03
      gyr_w: 5.2377301938209580e-05
   y-axis:
      gyr_n: 3.4204365908127145e-03
      gyr_w: 5.9820318994959333e-05
   z-axis:
      gyr_n: 3.9738126178135566e-03
      gyr_w: 3.8787497366438921e-05
Acc:
   unit: " m/s^2"
   avg-axis:
      acc_n: 4.0577448874376872e-02
      acc_w: 8.7349218314222493e-04
   x-axis:
      acc_n: 3.6370001351966601e-02
      acc_w: 9.6556492723349487e-04
   y-axis:
      acc_n: 3.4926548351679493e-02
      acc_w: 8.3124335009033201e-04
   z-axis:
      acc_n: 5.0435796919484514e-02
      acc_w: 8.2366827210284801e-04

编写imu.yaml,格式参考https://github.com/ethz-asl/kalibr/wiki/yaml-formats中的imu.yaml,具体参数使用之前imu标定得到的参数,示例如下:

#Accelerometers
accelerometer_noise_density: 4.0577448874376872e-02   #Noise density (continuous-time)
accelerometer_random_walk:   8.7349218314222493e-04   #Bias random walk

#Gyroscopes
gyroscope_noise_density:     3.4207443164969696e-03   #Noise density (continuous-time)
gyroscope_random_walk:       5.0328372766535944e-05   #Bias random walk

rostopic:                    /dvs/imu      #the IMU ROS topic
update_rate:                 1000.0      #Hz (for discretization of the values above)

若不加速播放rosbag得到的结果如下:

%YAML:1.0
---
type: IMU
name: imu_davis346
Gyr:
   unit: " rad/s"
   avg-axis:
      gyr_n: 3.4869979619824697e-03
      gyr_w: 4.4740603706140853e-05
   x-axis:
      gyr_n: 2.9539477648808021e-03
      gyr_w: 5.0580216740422281e-05
   y-axis:
      gyr_n: 3.5214141180930189e-03
      gyr_w: 5.4806050604838655e-05
   z-axis:
      gyr_n: 3.9856320029735878e-03
      gyr_w: 2.8835543773161611e-05
Acc:
   unit: " m/s^2"
   avg-axis:
      acc_n: 4.2153479580575477e-02
      acc_w: 8.5654389798364998e-04
   x-axis:
      acc_n: 3.7662088244236419e-02
      acc_w: 8.9242080034822346e-04
   y-axis:
      acc_n: 3.8469169601091632e-02
      acc_w: 8.9970652031743314e-04
   z-axis:
      acc_n: 5.0329180896398394e-02
      acc_w: 7.7750437328529356e-04

还是有点差别的~按这个来把~~~

camera标定

产生数据文件也是用于联合标定

1.标定板,可在kalibr的wiki中下载,地址:https://github.com/ethz-asl/kalibr/wiki/downloads

选择

下载(然后发现根本下载不了。。。eth这群货真的是。。。。event camera的驱动弄得崩溃,连标定的扳子也搞???)链接: 百度网盘 请输入提取码 提取码: r4ts

然后缩放到40%,用A4纸就可以打印出来
原始pdf的格子参数是:
6*6的格子
大格子边长:5.5cm
小格子边长:1.65cm
小格子与大格子边长比例:0.3
调整后的格子参数是:
大格子边长:2.4cm
小格子边长:0.75cm
小格子与大格子边长比例:0.3125

但这只是理想情况,实际情况还得实际测量。
新建april_6x6_A4.yaml文件,格式参考上图的yaml,内容展示如下:

target_type: 'aprilgrid' #gridtype
tagCols: 6               #number of apriltags
tagRows: 6               #number of apriltags
tagSize: 0.024           #size of apriltag, edge to edge [m]
tagSpacing: 0.3125          #ratio of space between tags to tagSize

录制bag,录制bag 的同时,相机对准标定板,或是固定相机或是固定标定板,晃动另一个,动作不要太大,不要让相机看不清标定板(就争取把标定板晃动到过相机像素平面的每个地方)

注意:需要修改相机帧数(官方推荐是4Hz,尽管实际频率不完全准确,但是不影响结果)
kalibr在处理标定数据的时候要求频率不能太高,一般为4Hz,我们可以使用如下命令来更改topic的频率,实际上是将原来的topic以新的频率转成新的topic,实际测试infra1才是对应左目相机

roslaunch vins davis_testing.launch

rostopic list

rostopic hz /dvs/image_raw

rosrun topic_tools throttle messages /dvs/image_raw 4.0 /color


rostopic hz /color


roslaunch vins davis_raw_image_recording.launch 

录制的topic就是转换频率后的topic

rosbag play /home/kwanwaipang/dataset/gwphku/hku_davis346_image_raw_imu_2021-10-26-14-31-10.bag

然后就使用上面安装好的Kalibr进行标定

source ~/kalibr_workspace/devel/setup.bash
kalibr_calibrate_cameras --target /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/april_6x6_A4.yaml --bag  /home/kwanwaipang/dataset/gwphku/hku_davis346_image_raw_imu_2021-10-26-14-31-10.bag --models pinhole-equi --topics /color --show-extraction

其中–target …/yaml/april_6x6_A4.yaml是标定板的配置文件,注意如果选择棋格盘,注意targetCols和targetRows表示的是内侧角点的数量,不是格子数量。–bag multicameras_calibration.bag是录制的数据包,models pinhole-equi pinhole-equi pinhole-equi表示三个摄像头的相机模型和畸变模型(解释参考https://github.com/ethz-asl/kalibr/wiki/supported-models,根据需要选取), --topics /infra_left /infra_right /color表示三个摄像头对应的拍摄的数据话题,–bag-from-to 10 100表示处理bag中10-100秒的数据。–show-extraction表示显示检测特征点的过程,这些参数可以相应的调整。

kalibr_calibrate_cameras --target ../yaml/april_6x6_A4.yaml --bag  multicameras_calibration.bag --models pinhole-equi pinhole-equi pinhole-equi --topics /infra_left /infra_right /color --bag-from-to 10 100 --show-extraction

出来的标定结果如下图所示

得到的结果如下所示

cam0:
  cam_overlaps: []
  camera_model: pinhole
  distortion_coeffs: [0.023761891762741624, -0.6457616668645434, 2.070114304159524,
    -2.4332476089446473]
  distortion_model: equidistant
  intrinsics: [333.6626192244177, 333.5395724565995, 162.74154656440015, 133.0594987830887]
  resolution: [346, 260]
  rostopic: /color

若改为降低速率前的topic效果如下:

source ~/kalibr_workspace/devel/setup.bash
kalibr_calibrate_cameras --target /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/april_6x6_A4.yaml --bag  /home/kwanwaipang/dataset/gwphku/hku_davis346_image_raw_imu_2021-10-26-14-31-10.bag --models pinhole-equi --topics /dvs/image_raw --show-extraction
cam0:
  cam_overlaps: []
  camera_model: pinhole
  distortion_coeffs: [0.007145831923439896, -0.4460587583609059, 1.2828141357453273,
    -1.3797467604219862]
  distortion_model: equidistant
  intrinsics: [333.649413082246, 333.5165283699802, 162.51929394284377, 132.6341713511583]
  resolution: [346, 260]
  rostopic: /dvs/image_raw

编写camchain.yaml,格式参考Kalibr官方教程https://github.com/ethz-asl/kalibr/wiki/yaml-formats中的chain.yaml,具体的参数参考上面得到的yaml文件,没有的参数可以删除,最终结果示例如下:

cam0:
  camera_model: pinhole
  intrinsics: [333.649413082246, 333.5165283699802, 162.51929394284377, 132.6341713511583]
  distortion_model: equidistant
  distortion_coeffs: [0.007145831923439896, -0.4460587583609059, 1.2828141357453273, -1.3797467604219862]
  T_cam_imu:
  - [0.01779318, 0.99967549,-0.01822936, 0.07008565]
  - [-0.9998017, 0.01795239, 0.00860714,-0.01771023]
  - [0.00893160, 0.01807260, 0.99979678, 0.00399246]
  - [0.0, 0.0, 0.0, 1.0]
  timeshift_cam_imu: -8.121e-05
  rostopic:  /dvs/image_raw
  resolution: [346, 260]

IMU与camera的联合标定

将之前矫正好的文件放好

source ~/kalibr_workspace/devel/setup.bash
kalibr_calibrate_imu_camera --bag [filename.bag] --cam [camchain.yaml] --imu [imu.yaml] --target [target.yaml] --bag-from-to 15 75 --show-extraction

kalibr_calibrate_imu_camera --bag /home/kwanwaipang/dataset/gwphku/hku_davis346_image_raw_imu_2021-10-26-14-31-10.bag --cam /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/camchain.yaml --imu /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/imu.yaml --target /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/april_6x6_A4.yaml --show-extraction

也有一种说法需要调整参数频率

注意选择的camera失真模型(https://github.com/ethz-asl/kalibr/wiki/supported-models

roslaunch vins davis_testing.launch
rosrun topic_tools throttle messages /dvs/image_raw 20.0 /image_raw 
rosrun topic_tools throttle messages /dvs/imu 200.0 /imu
roslaunch vins davis_raw_image_imu_recording.launch 

source ~/kalibr_workspace/devel/setup.bash
kalibr_calibrate_cameras --target /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/april_6x6_A4.yaml --bag /home/kwanwaipang/dataset/gwphku/hku_davis346_image_imu_2021-10-26-16-14-23.bag --models pinhole-radtan --topics /image_raw --show-extraction

kalibr_calibrate_imu_camera --bag /home/kwanwaipang/dataset/gwphku/hku_davis346_image_imu_2021-10-26-16-14-23.bag --cam /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/camchain_second.yaml --imu /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/imu_second.yaml --target /home/kwanwaipang/catkin_ws_dvs/src/EVIO/config/kalibr_davis/april_6x6_A4.yaml --show-extraction

至此,矫正完成!测试一下这些参数。

出来的pdf report如下

camera校正的report

 

camera-imu校正的report

 

 

参考资料

GitHub - ethz-asl/kalibr: The Kalibr visual-inertial calibration toolbox

GitHub - gaowenliang/imu_utils: A ROS package tool to analyze the IMU performance.

GitHub - rpng/kalibr_allan: IMU Allan standard deviation charts for use with Kalibr and inertial kalman filters.

联合标定双目相机和imu,使用工具Kalibr_甜甜圈吃不完的博客-CSDN博客

联合标定单目相机和imu,使用工具Kalibr_甜甜圈吃不完的博客-CSDN博客

realsenseD435i imu+双目标定_crazyfox的博客-CSDN博客_d435i imu标定

Installation · ethz-asl/kalibr Wiki · GitHubhttps://blog.csdn.net/Hanghang_/article/details/103546033Installation · ethz-asl/kalibr Wiki · GitHub

Realsense D435i RGB+IMU标定_追-CSDN博客

以上是关于ROS实验笔记之——基于kalibr来标定DAVIS346的主要内容,如果未能解决你的问题,请参考以下文章

ROS实验笔记之——基于dv-gui多次标定event与imu的实验记录

ROS实验笔记之——基于allan_variance_ros标定IMU

ROS学习笔记之——基于dv-gui的多种事件相机标定的方法对比

ROS学习笔记之——基于dv-gui的多种事件相机标定的方法对比

kalibr标定IMU

Kalibr 标定双目内外参数以及 IMU 外参数