前提條件
- GPS、Localization模塊被正確配置且能正常啓動
- 實現了循跡
- 正確完成了感知設備集成
準備工作
- 下載multi-lidar-gnss標定工具、傳感器標定工具並將文件提取到
modules /calibration
目錄下,目錄結構如下所示:
工具目錄名稱 | 工具作用 |
---|---|
exporter | 從bag文件中提取odometry、pointcloud數據 |
lidar_gnss_calibrator | 根據提取的odometry、pointcloud數據,生成lidar-imu的標定結果 |
camera_camera_calibrator | camera-camera標定工具 |
lidar_camera_calibrator | lidar-camera標定工具 |
radar_camera_calibrator | radar-camera標定工具 |
radar_lidar_visualizer | radar標定結果可視化工具 |
進行傳感器標定之前的說明
介紹一些與傳感器標定相關的知識,希望用戶先對這些知識點理解後再進行傳感器的標定。
ch目錄文件結構說明
傳感器的外參文件、內參文件存儲在modules/calibration/data/ch
目錄下,標定的目的就是爲了獲得傳感器的外參、內參文件。
標定相關目錄的作用如下表所示:
目錄名稱 | 作用 |
---|---|
camera_params | 存放攝像頭內外參文件 |
init_params | 存放初始化外參文件 |
radar_params | 存放radar外參文件 |
velodyne_params | 存放lidar標定文件 |
標定相關文件的作用如下表所示:
目錄名稱 | 作用 |
---|---|
long_camera_extrinsics.yaml | 長焦攝像頭外參文件 |
long_camera_intrinsics.yaml | 長焦攝像頭內參文件 |
short_camera_extrinsics.yaml | 短焦攝像頭外參文件 |
short_camera_intrinsics.yaml | 短焦攝像頭內參文件 |
long_camera_extrinsics.yaml_init | 長焦攝像頭初始化外參文件 |
radar_extrinsics.yaml_init | radar初始化外參文件 |
short_camera_extrinsics.yaml_init | 短焦攝像頭初始化外參文件 |
radar_extrinsics.yaml | radar外參文件 |
VLP16_calibration.yaml | lidar內參標定文件(廠商提供) |
velodyne16_height.yaml | lidar到地面高度文件 |
velodyne16_novatel_extrinsics_example.yaml | lidar外參文件 |
yaml外參文件格式解析
ros使用yaml文件來描述兩個傳感器之間的位置、姿態的關係,上文中提到的.yaml
、.yaml_init
文件均採用相同的格式,這裏以short_camera_extrinsics.yaml
文件爲例對外參文件格式進行說明:
header:
seq: 0
frame_id: Velodyne16
stamp:
secs: 0
nsecs: 0
child_frame_id: short_camera
transform:
rotation:
z: -0.4753745911796197
y: 0.5034432392822331
x: -0.5043470074890593
w: 0.5159437943406748
translation:
x: 0.7608883414172971
y: 0.3774716827859863
z: -0.2866475203991122
其中:frame_id: Velodyne16
代表以座標系Velodyne16
爲基座標系,child_frame_id: short_camera
代表以座標系short_camera
爲子座標系,rotation
、translation
分別代表從基座標系變換到子座標系要進行的旋轉變換、平移變換。
各傳感器座標系的定義及初始化外參文件的配置
- 需要進行標定的傳感器包括 IMU、Lidar、Camera、Radar的初始化座標系定義如下圖所示:
傳感器標定的相關腳本
- 在進行傳感器標定時,需要向傳感器提供相應的
topic
,大部分topic
都可以由傳感器直接提供,但由於GNSS設備的限制,/apollo/sensor/gnss/odometry
、/apollo/sensor/gnss/ins_stat
這兩個topic
不能由GNSS設備直接給出,需要藉助/apollo/modules/tools/sensor_calibration/
下的兩個腳本工具。在localization
模塊正常啓動且輸出/apollo/localization/pose
數據時,分別執行python modules/tools/sensor_calibration/ins_stat_publisher.py
、python modules/tools/sensor_calibration/odom_publisher.py
兩個命令,便可以分別產生/apollo/sensor/gnss/ins_stat
、/apollo/sensor/gnss/odometry
這兩個topic
。 - 注意,在執行
sensor_calibration/ins_stat_publisher.py
腳本前,請務必檢查/apollo/sensor/gnss/best_pose
中GPS信號質量,確保GPS信號質量爲NARROW_INT
時,纔可以使用ins_stat_publisher.py
腳本。
修改配置文件:
修改文件 | 修改內容 |
---|---|
global_flagfile.txt | 添加--localization_tf2_child_frame_id=novatel |
global_flagfile.txt | 添加 --pointcloud_raw_topic=/apollo/sensor/velodyne16/PointCloud2 |
global_flagfile.txt | 添加 --velodyne_raw_topic=/apollo/sensor/velodyne16/VelodyneScanUnified |
global_flagfile.txt | 添加--pointcloud_topic=/apollo/sensor/velodyne16/compensator/PointCloud2 |
localization.conf | 修改pointcloud_topic 內容爲 /apollo/sensor/velodyne16/compensator/PointCloud2 |
localization.conf | 確認enable_lidar_localization 爲false ;所有傳感器標定完成後,需要再改爲true |
localization.conf | 根據實際修改lidar_height_default 參數 |
localization.conf | 根據實際修改local_utm_zone_id 參數 |
localization.conf | 根據實際修改imu_to_ant_offset_x 參數 |
localization.conf | 根據實際修改imu_to_ant_offset_y 參數 |
localization.conf | 根據實際修改imu_to_ant_offset_z 參數 |
localization.conf | 根據實際修改imu_to_ant_offset_ux 參數 |
localization.conf | 根據實際修改imu_to_ant_offset_uy 參數 |
localization.conf | 根據實際修改imu_to_ant_offset_uz 參數 |
Lidar-IMU的標定
參考文檔:multiple_lidar_gnss_calibration_guide_cn.md
Lidar-IMU標定流程圖如下圖所示:
錄製bag包
進行Lidar-IMU的標定,需要錄製包含傳感器信息的bag包作爲數據輸入,所需的topic
及topic
頻率如下表所示。
傳感器 | Topic名稱 | Topic發送頻率(Hz) |
---|---|---|
VLP-16 | /apollo/sensor/velodyne16/PointCloud2 | 10 |
INS | /apollo/sensor/gnss/odometry | 100 |
錄製bag時,以8字形軌跡控制車輛,緩慢行駛,並使轉彎半徑儘量小 。行駛的時長3分鐘即可,但要保證標定數據至少包含一個完整的8字,如下圖所示。
配置export_config.yaml
文件
- 將
/apollo/modules/calibration/exporter/conf
目錄下的export_config.yaml
文件修改爲如下內容: - 將錄製的包含傳感器信息的bag包存儲到
/apollo/data/bag/calibration/
目錄下
bag_path: "/apollo/data/bag/calibration/" #錄製的bag包位置
dump_dir: "/apollo/data/bag/calibration/export/" #從bag包提取出的文件存儲路徑
topics:
- /apollo/sensor/gnss/odometry:
type: ApolloOdometry
- /apollo/sensor/velodyne16/PointCloud2:
type: PointCloud2
處理bag包,獲得傳感器數據
在docker環境內執行如下指令,處理bag包,獲得傳感器數據:
budaoshi@in_dev_docker:/apollo$ /apollo/modules/calibration/exporter/export_msgs --config /apollo/modules/calibration/exporter/conf/export_config.yaml
其中:/apollo/modules/calibration/exporter/export_msgs
爲標定工具中可執行文件export_msgs
的絕對路徑;/apollo/modules/calibration/exporter/conf/export_config.yaml
爲上文中修改的配置文件的絕對路徑,執行成功後,會在上文中配置的dump_dir
目錄中生成從bag中提取的數據文件,如下圖所示:
配置multi_lidar_gnss_calibrator_config.yaml
文件
將/apollo/modules/calibration/lidar_gnss_calibrator/conf
目錄下的multi_lidar_gnss_calibrator_config.yaml
文件的內容修改爲如下的形式:
data:
odometry: "/apollo/data/bag/calibration/export/multi_lidar_gnss/_apollo_sensor_gnss_odometry/odometry"
lidars:
- velodyne16:
path: "/apollo/data/bag/calibration/export/multi_lidar_gnss/_apollo_sensor_velodyne16_PointCloud2/"
result: "/apollo/data/bag/calibration/export/multi_lidar_gnss/result/"
calibration:
init_extrinsics:
velodyne16:
translation:
x: 0.0
y: 1.77
z: 1.1
rotation:
x: 0.183014
y: -0.183014
z: 0.683008
w: 0.683008
steps:
- source_lidars: ["velodyne16"]
target_lidars: ["velodyne16"]
lidar_type: "multiple"
fix_target_lidars: false
fix_z: true
iteration: 3
- source_lidars: ["velodyne16"]
target_lidars: ["velodyne16"]
lidar_type: "multiple"
fix_target_lidars: false
fix_z: true
iteration: 3
注:校準部分提供了外部信息的初始猜測。所有的外部信息都是從激光雷達到GNSS,這意味着這種變換將激光雷達座標系中定義的點的座標映射到GNSS座標系中定義的這一點的座標。初始猜測要求旋轉角度誤差小於5度,平移誤差小於0.1米。
執行標定
執行如下命令,進行Lidar-IMU的標定,得到標定結果
budaoshi@in_dev_docker:/apollo$ /apollo/modules/calibration/lidar_gnss_calibrator/multi_lidar_gnss_calibrator --config /apollo/modules/calibration/lidar_gnss_calibrator/conf/multi_lidar_gnss_calibrator_config.yaml
標定結果校驗
Lidar-IMU標定結果驗證參考:multiple_lidar_gnss_calibration_guide_cn.md
Camera-Camera標定
相機內參文件
內參包含相機的焦距、主點和畸變係數等信息,可以通過一些成熟的相機標定工具來獲得,例如 ROS Camera Calibration Tools 和 Camera Calibration Toolbox for Matlab。內參標定完成後,需將結果轉換爲 .yaml
格式的文件。下面是一個正確的內參文件樣例:
header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: short_camera
height: 1080
width: 1920
distortion_model: plumb_bob
D: [-0.535253, 0.259291, 0.004276, -0.000503, 0.0]
K: [1959.678185, 0.0, 1003.592207, 0.0, 1953.786100, 507.820634, 0.0, 0.0, 1.0]
R: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P: [1665.387817, 0.0, 1018.703332, 0.0, 0.0, 1867.912842, 506.628623, 0.0, 0.0, 0.0, 1.0, 0.0]
binning_x: 0
binning_y: 0
roi:
x_offset: 0
y_offset: 0
height: 0
width: 0
do_rectify: False
標定後的內參文件,放置到形如/apollo/modules/calibration/data/ch
的路徑中,其中ch
爲車輛參數文件夾,用戶根據自身情況選擇,後文不再重複說明。
我們建議每一隻相機都需要單獨進行內參標定,而不是使用統一的內參結果。這樣可以提高外參標定的準確性。
配置camera_camera_calibrator.conf
文件,配置形式如下所示:
##################################################################
# the long focus camera image topic name.
# type: string
# default:
--long_image_topic=/apollo/sensor/camera/traffic/image_long
# the short focus camera image topic name.
# type: string
# default:
--short_image_topic=/apollo/sensor/camera/traffic/image_short
# the odometry topic name.
# type: string
# default:
--odometry_topic=/apollo/sensor/gnss/odometry
# the ins_stat topic name.
# type: string
# default:
--ins_stat_topic=/apollo/sensor/gnss/ins_stat
# the calibrated long focus camera intrinsics.
# type: string
# default:
--long_camera_intrinsics_filename=/apollo/modules/calibration/data/ch/camera_params/long_camera_intrinsics.yaml
# the calibrated short focus camera intrinsics.
# type: string
# default:
--short_camera_intrinsics_filename=/apollo/modules/calibration/data/ch/camera_params/short_camera_intrinsics.yaml
# the init camera-camera extrinsics.
# type: string
# default:
--init_extrinsics_filename=/apollo/modules/calibration/data/ch/init_params/long_camera_extrinsics.yaml_init
# calibration result output path.
# type: string
# default:
--output_path=/apollo/modules/calibration/data/ch
# max speed of car, unit: km/h
# type: double
# default: 20.0
--max_speed_kmh=20.0
配置初始化外參文件
用戶需根據車輛實際情況,測量攝像頭之間的初始化外參,並放修改/apollo/modules/calibration/data/ch/init_params/long_camera_extrinsics.yaml_init
文件。初始化外參文件的形式如下所示:
header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: short_camera
child_frame_id: long_camera
transform:
rotation:
x: 0
y: 0
z: 0
w: 1
translation:
x: -0.1
y: 0
z: 0
所需topic
傳感器 | Topic名稱 | Topic發送頻率(Hz) |
---|---|---|
Short_Camera | /apollo/sensor/camera/traffic/image_short | 9 |
Long_Camera | /apollo/sensor/camera/traffic/image_long | 9 |
INS | /apollo/sensor/gnss/odometry | 100 |
INS | /apollo/sensor/gnss/ins_stat | 2 |
修改攝像頭Topic的頻率
攝像頭數據默認的發佈頻率爲30HZ,在進行標定過程中,需要將頻率修改爲9HZ。修改方法如下:
- 關閉攝像頭模塊
- 分別將
modules/calibration/data/ch/camera_params/start_leopard.launch
、modules/drivers/camera/launch/start_leopard.launch
兩個文件中的<arg name="frame_rate" default="30"/>
修改爲<arg name="frame_rate" default="9"/>
- 執行如下命令,重新編譯攝像頭
bash apollo.sh build_usbcam
- 啓動攝像頭模塊,使用如下命令,查看攝像頭數據發佈頻率是否修改成功
rostopic hz /apollo/sensor/camera/traffic/image_short
rostopic hz /apollo/sensor/camera/traffic/image_long
執行標定
執行如下命令,進行camera_camera的標定:
cd /apollo/scripts
bash sensor_calibration.sh camera_camera
輸出內容
外參文件: 長焦相機到廣角相機的外參文件。
驗證參考圖片:包括一張長焦相機圖像、一張廣角相機圖像及一張長焦相機依據標定後的外參投影到廣角相機的去畸變融合圖像。
標定結果驗證
- 基本方法:根據長焦相機投影到短焦相機的融合圖像進行判斷,綠色通道爲短焦相機圖像,紅色和藍色通道是長焦投影后的圖像,目視判斷檢驗對齊情況。在融合圖像中的融合區域,選擇場景中距離較遠處(50米以外)的景物進行對齊判斷,能夠重合則精度高,出現粉色或綠色重影(錯位),則存在誤差,當誤差大於一定範圍時(範圍依據實際使用情況而定),標定失敗,需重新標定(正常情況下,近處物體因受視差影響,在水平方向存在錯位,且距離越近錯位量越大,此爲正常現象。垂直方向不受視差影響)。
- 結果示例:如下圖所示,圖1爲滿足精度要求外參效果,圖2爲不滿足精度要求的現象,請重新進行標定過程。
lidar-camera
配置lidar_camera_calibrator.conf
文件,配置形式如下所示,用戶根據實際情況修改:
##################################################################
# the camera image topic name.
# type: string
# default:
--image_topic=/apollo/sensor/camera/traffic/image_short
# the lidar topic name.
# type: string
# default:
--lidar_topic=/apollo/sensor/velodyne16/compensator/PointCloud2
# the odometry topic name.
# type: string
# default:
--odometry_topic=/apollo/sensor/gnss/odometry
# the ins_stat topic name.
# type: string
# default:
--ins_stat_topic=/apollo/sensor/gnss/ins_stat
# the calibrated camera intrinsics.
# type: string
# default:
--camera_intrinsics_filename=/apollo/modules/calibration/data/ch/camera_params/short_camera_intrinsics.yaml
# the init lidar-camera extrinsics.
# type: string
# default:
--init_extrinsics_filename=/apollo/modules/calibration/data/ch/init_params/short_camera_extrinsics.yaml_init
# calibration result output path.
# type: string
# default:
--output_path=/apollo/modules/calibration/data/ch
# the number of data used to calibrate
# type: int32
# default: 30
--calib_stop_count=30
# the maximum vehicle speed for capturing data, unit: km/h
# type: double
# default: 5
--max_speed_kmh=5
配置初始化外參文件
用戶需根據車輛實際情況,測量lidar到short_camera的初始化外參,並修改/apollo/modules/calibration/data/ch/init_params/short_camera_extrinsics.yaml_init
文件。初始化外參文件的形式如下所示:
header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: velodyne16
child_frame_id: short_camera
transform:
rotation:
y: -0.5
x: 0.5
w: -0.5
z: 0.5
translation:
x: 0.67
y: -0.1
z: -0.6
所需topic
傳感器 | Topic名稱 | Topic發送頻率(Hz) |
---|---|---|
Short_Camera | /apollo/sensor/camera/traffic/image_short | 9 |
LiDAR | /apollo/sensor/velodyne16/compensator/PointCloud2 | 10 |
INS | /apollo/sensor/gnss/odometry | 100 |
INS | /apollo/sensor/gnss/ins_stat | 2 |
執行標定
執行如下命令,進行lidar_camera的標定:
cd /apollo/scripts
bash sensor_calibration.sh lidar_camera
輸出內容
外參文件:相機到多線激光雷達的外參文件。
驗證參考圖片:兩張激光雷達點雲利用標定結果外參投影到相機圖像上的融合圖像,分別是依據點雲深度渲染的融合圖像,和依據點雲反射值渲染的融合圖像。
標定結果驗證
- 基本方法:在產生的點雲投影圖像內,可尋找其中具有明顯邊緣的物體和標誌物,查看其邊緣輪廓對齊情況。如果50米以內的目標,點雲邊緣和圖像邊緣能夠重合,則可以證明標定結果的精度很高。反之,若出現錯位現象,則說明標定結果存在誤差。當誤差大於一定範圍時(範圍依據實際使用情況而定),該外參不可用。
- 結果示例:如下圖所示,圖1爲準確外參的點雲投影效果,圖2爲有偏差外參的點雲投影效果
Radar-Camera標定
配置radar_camera_calibrator.conf
文件,配置形式如下所示,用戶根據實際情況修改:
##################################################################
# the camera image topic name.
# type: string
# default:
--image_topic=/apollo/sensor/camera/traffic/image_short
# the odometry topic name.
# type: string
# default:
--odometry_topic=/apollo/sensor/gnss/odometry
# the ins_stat topic name.
# type: string
# default:
--ins_stat_topic=/apollo/sensor/gnss/ins_stat
# the calibrated camera intrinsics.
# type: string
# default:
--camera_intrinsics_filename=/apollo/modules/calibration/data/ch/camera_params/short_camera_intrinsics.yaml
# the init radar-camera extrinsics.
# type: string
# default:
--init_extrinsics_filename=/apollo/modules/calibration/data/ch/init_params/radar_extrinsics.yaml_init
# calibration result output path.
# type: string
# default:
--output_path=/apollo/modules/calibration/data/ch/
# max speed of car, unit: km/h
# type: double
# default: 5.0
--max_speed_kmh=5.0
配置初始化外參文件
用戶需根據車輛實際情況,測量radar到short_camera的初始化外參,並修改/apollo/modules/calibration/data/ch/init_params/radar_extrinsics.yaml_init
文件。初始化外參文件的形式如下所示:
header:
seq: 0
stamp:
nsecs: 0
secs: 0
frame_id: short_camera
child_frame_id: radar
transform:
rotation:
x: 0.5
y: -0.5
z: 0.5
w: 0.5
translation:
x: -0.1
y: 0.26
z: 0.11
所需topic
傳感器 | Topic名稱 | Topic發送頻率(Hz) |
---|---|---|
Short_Camera | /apollo/sensor/camera/traffic/image_short | 9 |
INS | /apollo/sensor/gnss/odometry | 100 |
INS | /apollo/sensor/gnss/ins_stat | 2 |
Radar | /apollo/sensor/conti_radar | 13 |
執行標定
執行如下命令,進行lidar_camera的標定:
cd /apollo/scripts
bash sensor_calibration.sh radar_camera
輸出內容
外參文件:毫米波雷達到短焦相機的外參文件。
驗證參考圖片:將毫米波雷達投影到激光雷達座標系的結果,需運行 radar_lidar_visualizer 工具
標定結果驗證
- 基本方法:爲了更好地驗證毫米波雷達與相機間外參的標定結果,引入激光雷達作爲橋樑,通過同一系統中毫米波雷達與相機的外參和相機與激光雷達的外參,計算得到毫米波雷達與激光雷達的外參,將毫米波雷達數據投影到激光雷達座標系中與激光點雲進行融合,並畫出相應的鳥瞰圖進行輔助驗證。在融合圖像中,白色點爲激光雷達點雲,綠色實心圓爲毫米波雷達目標,通過圖中毫米波雷達目標是否與激光雷達檢測目標是否重合匹配進行判斷,如果大部分目標均能對應匹配,則滿足精度要求,否則不滿足,需重新標定。
- 結果示例:如下圖所示,圖1爲滿足精度要求外參效果,圖2爲不滿足精度要求外參效果。