Skip to content

Commit 637c424

Browse files
authored
add calib param manager and imu intrinsic param (#10)
* add calib param * add calib param manager * add imu intrinsic param * update doc * code format * update doc
1 parent 1a1b1b1 commit 637c424

File tree

11 files changed

+308
-75
lines changed

11 files changed

+308
-75
lines changed

doc/calibration_file_format.md

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ cameras:
1616
type: pinhole_radtan
1717
intrinsics: [1057.79, 1059.8, 962.78, 581.29]
1818
distortion_coeffs: [-0.149116, 0.09615, -0.000526577, -0.000567049, -0.022971]
19+
imus:
20+
imu1:
21+
frame_id: imu1
22+
accel_matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
23+
accel_offset: [0, 0, 0]
24+
accel_noise_density: [1.86e-03, 1.86e-03, 1.86e-03]
25+
accel_random_walk: [4.33e-04, 4.33e-04, 4.33e-04]
26+
gyro_matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
27+
gyro_offset: [0, 0, 0]
28+
gyro_noise_density: [1.87e-04, 1.87e-04, 1.87e-04]
29+
gyro_random_walk: [2.66e-05, 2.66e-05, 2.66e-05]
1930
transforms:
2031
transform1:
2132
frame_id: camera1
@@ -29,24 +40,12 @@ transforms:
2940
rotation: [0.0 ,0.0 ,0.0 ,1.0] # x,y,z,w
3041
```
3142
32-
## 传感器外参说明
33-
34-
传感器的外参包括以下四个量
35-
36-
* frame_id:传感器的frame id
37-
* child_frame_id:另一个传感器的frame id
38-
* translation:外参坐标变换中的平移部分
39-
* rotation:外参坐标变换中的旋转部分,采用四元数表示,顺序为`[x,y,z,w]`
40-
41-
这里标定出的坐标变换表示为 $T_\text{frame id - child frame id}$,等价以下两种说法:
42-
43-
* 在`frame_id`传感器坐标系下,`child_frame_id`的位姿。
44-
* `child_frame_id`坐标系到`frame_id`坐标系下的位姿变换。
45-
4643
## 相机内参说明
4744
4845
相机内参包括以下三个量
4946
47+
* frame_id:传感器的frame id
48+
* height,width:标定相机的图片分辨率
5049
* type:采用的相机模型类型,为一个字符串
5150
* intrinsics:相机内参系数,为一个float数组
5251
* distortion_coeffs:畸变参数系数,为一个float数组
@@ -75,3 +74,39 @@ transforms:
7574
* distortion_coeffs: $[k_1, k_2, p_1, p_2, k_3]$ ,其中k为径向畸变参数,p为切向畸变参数。
7675
* 参考:https://docs.opencv.org/4.x/dd/d12/tutorial_omnidir_calib_main.html
7776

77+
78+
## Imu内参说明
79+
80+
IMU内参包括加速度计accel和陀螺仪gyro两组数据
81+
82+
* frame_id:传感器的frame id
83+
* accel_matrix,accel_offset:速度计accel的仿射变换模型参数,修正测量值。
84+
* accel_noise_density,accel_random_walk:速度计accel的白噪声以及零偏不稳定(随机游走)噪声。
85+
* gyro_matrix,gyro_offset:陀螺仪gyro的仿射变换模型参数,修正测量值。
86+
* gyro_noise_density,gyro_random_walk:陀螺仪gyro的白噪声以及零偏不稳定(随机游走)噪声。
87+
88+
速度计accel和陀螺仪gyro采用仿射变换建立确定性误差模型,修正scale,misalignment等误差,测量值修正公式如下:
89+
$$
90+
\hat x_{accel} = A_{accel}x_{accel} + b_{accel} \\
91+
\hat x_{gyro} = A_{gyro}x_{gyro} + b_{gyro} \\
92+
$$
93+
94+
* 其中$x$是原始测量值,$\hat x$是标定修正后的值,A对应matrix参数,b对应offset参数
95+
96+
random_walk和noise_density是随机误差(不确定性误差)模型参数,一般使用allan方差分析得到
97+
* 参考:https://github.com/ethz-asl/kalibr/wiki/IMU-Noise-Model
98+
99+
100+
## 传感器外参说明
101+
102+
传感器的外参包括以下四个量
103+
104+
* frame_id:传感器的frame id
105+
* child_frame_id:另一个传感器的frame id
106+
* translation:外参坐标变换中的平移部分
107+
* rotation:外参坐标变换中的旋转部分,采用四元数表示,顺序为`[x,y,z,w]`
108+
109+
这里标定出的坐标变换表示为 $T_\text{frame id - child frame id}$,等价以下两种说法:
110+
111+
* 在`frame_id`传感器坐标系下,`child_frame_id`的位姿。
112+
* `child_frame_id`坐标系到`frame_id`坐标系下的位姿变换。

ssct_camera_intrinsic_calib/include/ssct_camera_intrinsic_calib/calibration_node.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "rclcpp/rclcpp.hpp"
2323
#include "ssct_common/publisher/image_publisher.hpp"
2424
#include "ssct_common/subscriber/image_subscriber.hpp"
25-
#include "ssct_common/calibration_params.hpp"
25+
#include "ssct_common/calib_param_manager.hpp"
2626
#include "ssct_camera_intrinsic_calib/pinhole_calibrator.hpp"
2727
#include "ssct_interfaces/msg/calibration_status.hpp"
2828
#include "ssct_interfaces/msg/calibration_command.hpp"
@@ -72,7 +72,7 @@ class CalibrationNode
7272
bool exit_{false};
7373
// data
7474
std::deque<SensorData> sensor_data_buffer_;
75-
std::shared_ptr<ssct_common::CalibrationParams> calibration_params_;
75+
std::shared_ptr<ssct_common::CalibParamManager> calib_param_manager_;
7676
uint8_t state_;
7777
bool success_{false};
7878
bool is_auto_mode_{true};

ssct_camera_intrinsic_calib/src/calibration_node.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CalibrationNode::CalibrationNode(const rclcpp::NodeOptions & options)
6363
// calibrator
6464
YAML::Node config_node = YAML::LoadFile(calibrator_config);
6565
calibrator_ = std::make_shared<PinholeCalibrator>(config_node["pinhole_calibrator"]);
66-
calibration_params_ = std::make_shared<ssct_common::CalibrationParams>();
66+
calib_param_manager_ = std::make_shared<ssct_common::CalibParamManager>();
6767
// initialize status
6868
status_msg_.frame_id = frame_id_;
6969
status_msg_.sensor_topic = image_sub_->get_topic_name();
@@ -160,10 +160,10 @@ void CalibrationNode::save_result()
160160
return;
161161
}
162162
if (std::filesystem::exists(output_file_)) {
163-
if (!calibration_params_->load(output_file_)) {
163+
if (!calib_param_manager_->load(output_file_)) {
164164
RCLCPP_FATAL(
165165
node_->get_logger(), "failed to load existed calibration data, %s",
166-
calibration_params_->error_message().c_str());
166+
calib_param_manager_->error_message().c_str());
167167
return;
168168
}
169169
}
@@ -175,8 +175,8 @@ void CalibrationNode::save_result()
175175
param.width = image_size.width;
176176
param.intrinsics = calibrator_->get_intrinsics();
177177
param.distortion_coeffs = calibrator_->get_distortion_coeffs();
178-
calibration_params_->add_camera_intrinsic_param(frame_id_, param);
179-
if (calibration_params_->save(output_file_)) {
178+
calib_param_manager_->add_camera_intrinsic_param(param);
179+
if (calib_param_manager_->save(output_file_)) {
180180
RCLCPP_INFO(node_->get_logger(), "successed to save result: %s", output_file_.c_str());
181181
} else {
182182
RCLCPP_INFO(node_->get_logger(), "failed to save result: %s", output_file_.c_str());

ssct_common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ add_library(${PROJECT_NAME} SHARED
5050
src/dummy_sensor/dummy_lidar_node.cpp
5151
src/dummy_sensor/dummy_imu_node.cpp
5252
# utils
53-
src/calibration_params.cpp
53+
src/calib_param_manager.cpp
5454
src/msg_utils.cpp
5555
src/tic_toc.cpp
5656
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2025 Gezp (https://github.com/gezp).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <Eigen/Geometry>
18+
19+
#include <string>
20+
#include <vector>
21+
22+
namespace ssct_common
23+
{
24+
25+
struct CameraIntrinsicParam
26+
{
27+
std::string frame_id;
28+
int height;
29+
int width;
30+
std::string type;
31+
std::vector<double> intrinsics;
32+
std::vector<double> distortion_coeffs;
33+
};
34+
35+
} // namespace ssct_common
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 Gezp (https://github.com/gezp).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <Eigen/Geometry>
18+
19+
#include <string>
20+
21+
namespace ssct_common
22+
{
23+
24+
struct ExtrinsicParam
25+
{
26+
std::string frame_id;
27+
std::string child_frame_id;
28+
Eigen::Matrix4d transform;
29+
};
30+
31+
} // namespace ssct_common
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2025 Gezp (https://github.com/gezp).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <Eigen/Geometry>
18+
19+
#include <string>
20+
#include <vector>
21+
22+
namespace ssct_common
23+
{
24+
25+
struct ImuIntrinsicParam
26+
{
27+
std::string frame_id;
28+
// for accelerometer
29+
Eigen::Matrix3d accel_matrix;
30+
Eigen::Vector3d accel_offset;
31+
Eigen::Vector3d accel_noise_density;
32+
Eigen::Vector3d accel_random_walk;
33+
// for gyroscope
34+
Eigen::Matrix3d gyro_matrix;
35+
Eigen::Vector3d gyro_offset;
36+
Eigen::Vector3d gyro_noise_density;
37+
Eigen::Vector3d gyro_random_walk;
38+
};
39+
40+
} // namespace ssct_common

ssct_common/include/ssct_common/calibration_params.hpp renamed to ssct_common/include/ssct_common/calib_param_manager.hpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,33 @@
2121
#include <map>
2222
#include <utility>
2323

24-
namespace ssct_common
25-
{
24+
#include "ssct_common/calib_param/camera_intrinsic_param.hpp"
25+
#include "ssct_common/calib_param/imu_intrinsic_param.hpp"
26+
#include "ssct_common/calib_param/extrinsic_param.hpp"
2627

27-
struct CameraIntrinsicParam
28-
{
29-
std::string frame_id;
30-
int height;
31-
int width;
32-
std::string type;
33-
std::vector<double> intrinsics;
34-
std::vector<double> distortion_coeffs;
35-
};
36-
37-
struct ExtrinsicParam
28+
namespace ssct_common
3829
{
39-
std::string frame_id;
40-
std::string child_frame_id;
41-
Eigen::Matrix4d transform;
42-
};
4330

44-
class CalibrationParams
31+
class CalibParamManager
4532
{
4633
public:
47-
CalibrationParams() = default;
48-
~CalibrationParams() = default;
34+
CalibParamManager() = default;
35+
~CalibParamManager() = default;
4936
// for camera intrinsic params
50-
bool add_camera_intrinsic_param(const std::string & frame_id, const CameraIntrinsicParam & param);
37+
bool add_camera_intrinsic_param(const CameraIntrinsicParam & param);
5138
bool get_camera_intrinsic_param(const std::string & frame_id, CameraIntrinsicParam & param);
5239
void remove_camera_intrinsic_param(const std::string & frame_id);
40+
// for imu intrinsic params
41+
bool add_imu_intrinsic_param(const ImuIntrinsicParam & param);
42+
bool get_imu_intrinsic_param(const std::string & frame_id, ImuIntrinsicParam & param);
43+
void remove_imu_intrinsic_param(const std::string & frame_id);
5344
// for extrinsic params
45+
bool add_extrinsic_param(const ExtrinsicParam & param);
5446
bool add_extrinsic_param(
5547
const std::string & frame_id, const std::string & child_frame_id,
5648
const Eigen::Matrix4d & transform);
5749
bool get_extrinsic_param(
58-
const std::string & frame_id, const std::string & child_frame_id, Eigen::Matrix4d & transform);
50+
const std::string & frame_id, const std::string & child_frame_id, ExtrinsicParam & param);
5951
void remove_extrinsic_param(const std::string & frame_id, const std::string & child_frame_id);
6052
// save & load
6153
bool save(const std::string & file);
@@ -65,6 +57,7 @@ class CalibrationParams
6557

6658
private:
6759
std::map<std::string, CameraIntrinsicParam> camera_intrinsic_params_;
60+
std::map<std::string, ImuIntrinsicParam> imu_intrinsic_params_;
6861
std::map<std::string, ExtrinsicParam> extrinsic_params_;
6962
std::string error_message_;
7063
};

0 commit comments

Comments
 (0)