├── pic
├── ui.png
└── 3imu.png
├── depend_pack.rosinstall
├── .gitmodules
├── .gitignore
├── test
└── li_calib_gui.cpp
├── include
├── utils
│ ├── tic_toc.h
│ ├── ceres_callbacks.h
│ ├── pcl_utils.h
│ ├── eigen_utils.hpp
│ ├── dataset_reader.h
│ ├── math_utils.h
│ └── vlp_common.h
├── core
│ ├── inertial_initializer.h
│ ├── lidar_odometry.h
│ ├── surfel_association.h
│ ├── calibration.hpp
│ ├── trajectory_manager.h
│ └── scan_undistortion.h
└── ui
│ ├── calib_ui.h
│ └── calib_helper.h
├── calib.sh
├── launch
└── licalib_gui.launch
├── CMakeLists.txt
├── src
├── core
│ ├── inertial_initializer.cpp
│ ├── lidar_odometry.cpp
│ ├── surfel_association.cpp
│ └── trajectory_manager.cpp
└── ui
│ ├── calib_ui.cpp
│ └── calib_helper.cpp
├── package.xml
├── README.md
└── LICENSE
/pic/ui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/APRIL-ZJU/lidar_IMU_calib/HEAD/pic/ui.png
--------------------------------------------------------------------------------
/pic/3imu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/APRIL-ZJU/lidar_IMU_calib/HEAD/pic/3imu.png
--------------------------------------------------------------------------------
/depend_pack.rosinstall:
--------------------------------------------------------------------------------
1 | - git:
2 | local-name: ndt_omp
3 | uri: https://github.com/APRIL-ZJU/ndt_omp.git
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "thirdparty/Pangolin"]
2 | path = thirdparty/Pangolin
3 | url = https://github.com/stevenlovegrove/Pangolin.git
4 | [submodule "thirdparty/Kontiki"]
5 | path = thirdparty/Kontiki
6 | url = https://github.com/APRIL-ZJU/Kontiki.git
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pdf
2 | *.bag
3 |
4 | # Built objects
5 | *.so
6 | *.a
7 | *.pyc
8 |
9 | # Documentation build artifacts
10 | docs/_build/
11 |
12 | # Python build artifacts
13 | build/
14 | dist/
15 | *.egg-info/
16 |
17 | #CLion / PyCharm directories
18 | .cache/
19 | .idea/
20 | cmake-build-*/
21 |
22 | build-*/
23 | thirdparty/build-*/
24 | thirdparty/build-*
25 |
--------------------------------------------------------------------------------
/test/li_calib_gui.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 |
22 | #include
23 |
24 | using namespace licalib;
25 |
26 | int main(int argc, char **argv) {
27 | ros::init(argc, argv, "li_calib_gui");
28 | ros::NodeHandle n("~");
29 |
30 | CalibInterface calib_app(n);
31 |
32 | calib_app.renderingLoop();
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/include/utils/tic_toc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 | #pragma once
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | namespace licalib {
28 |
29 | class TicToc {
30 | public:
31 | TicToc() {
32 | tic();
33 | }
34 |
35 | void tic() {
36 | start = std::chrono::system_clock::now();
37 | }
38 |
39 | double toc() {
40 | end = std::chrono::system_clock::now();
41 | std::chrono::duration elapsed_seconds = end - start;
42 | return elapsed_seconds.count() * 1000;
43 | }
44 |
45 | private:
46 | std::chrono::time_point start, end;
47 | };
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/calib.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | bag_path="/home/ha/rosbag/li_calib_data"
4 |
5 | outdoor_sync_bag_name=(
6 | #"Court-01.bag"
7 | #"Court-02.bag"
8 | #"Court-03.bag"
9 | #"Court-04.bag"
10 | #"Court-05.bag"
11 | )
12 |
13 | indoor_sync_bag_name=(
14 | "Garage-01.bag"
15 | #"Garage-02.bag"
16 | #"Garage-03.bag"
17 | #"Garage-04.bag"
18 | #"Garage-05.bag"
19 | )
20 |
21 | imu_topic_name=(
22 | "/imu1/data_sync"
23 | #"/imu2/data_sync"
24 | #"/imu3/data_sync"
25 | )
26 |
27 | bag_start=1
28 | bag_durr=30
29 | scan4map=15
30 | timeOffsetPadding=0.015
31 |
32 | show_ui=true #false
33 |
34 | bag_count=-1
35 | sync_bag_name=(${outdoor_sync_bag_name[*]} ${indoor_sync_bag_name[*]})
36 | for i in "${!sync_bag_name[@]}"; do
37 | let bag_count=bag_count+1
38 |
39 | ndtResolution=0.5 # indoor
40 | if [ $bag_count -lt ${#outdoor_sync_bag_name[*]} ]; then
41 | ndtResolution=1.0 # outdoor
42 | fi
43 |
44 | for j in "${!imu_topic_name[@]}"; do
45 | path_bag="$bag_path/${sync_bag_name[i]}"
46 |
47 | echo "topic_imu:=${imu_topic_name[j]}"
48 | echo "path_bag:=${path_bag}"
49 | echo "ndtResolution:=${ndtResolution}"
50 | echo "=============="
51 |
52 | roslaunch li_calib licalib_gui.launch \
53 | topic_imu:="${imu_topic_name[j]}" \
54 | path_bag:="${path_bag}" \
55 | bag_start:="${bag_start}" \
56 | bag_durr:="${bag_durr}" \
57 | scan4map:="${scan4map}" \
58 | lidar_model:="VLP_16" \
59 | time_offset_padding:="${timeOffsetPadding}"\
60 | ndtResolution:="${ndtResolution}" \
61 | show_ui:="${show_ui}"
62 | done
63 | done
64 |
--------------------------------------------------------------------------------
/launch/licalib_gui.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/include/core/inertial_initializer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 | #ifndef CALIBR_INERTIALINITIALIZER_H
22 | #define CALIBR_INERTIALINITIALIZER_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | namespace licalib {
30 |
31 |
32 | class InertialInitializer {
33 |
34 | public:
35 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36 |
37 | typedef std::shared_ptr Ptr;
38 |
39 | explicit InertialInitializer() : rotaion_initialized_(false),
40 | q_ItoS_est_(Eigen::Quaterniond::Identity()) {
41 | }
42 |
43 | bool EstimateRotation(TrajectoryManager::Ptr traj_manager,
44 | const Eigen::aligned_vector& odom_data);
45 |
46 | bool isInitialized() {
47 | return rotaion_initialized_;
48 | }
49 |
50 | Eigen::Quaterniond getQ_ItoS() {
51 | return q_ItoS_est_;
52 | }
53 |
54 |
55 | private:
56 | bool rotaion_initialized_;
57 | Eigen::Quaterniond q_ItoS_est_;
58 |
59 | };
60 |
61 |
62 | }
63 |
64 | #endif //CALIBR_INERTIALINITIALIZER_H
65 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.2)
2 | project(li_calib)
3 |
4 | set(CMAKE_CXX_STANDARD 14)
5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -msse4.2")
6 | set(CMAKE_BUILD_TYPE "RELEASE")
7 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -msse4.2 -mavx")
8 |
9 | find_package(OpenMP)
10 | if (OPENMP_FOUND)
11 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
12 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
13 | endif()
14 |
15 | find_package(catkin REQUIRED COMPONENTS
16 | roscpp
17 | std_msgs
18 | rosbag
19 | geometry_msgs
20 | nav_msgs
21 | velodyne_msgs
22 | ndt_omp
23 | tf
24 | pcl_ros
25 | )
26 |
27 | find_package(Eigen3 REQUIRED)
28 | find_package(Boost REQUIRED COMPONENTS system filesystem thread date_time)
29 |
30 | set(PANGOLIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/build-pangolin")
31 | find_package(Pangolin REQUIRED)
32 |
33 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/Kontiki)
34 |
35 | # Set link libraries used by all binaries
36 | list(APPEND thirdparty_libraries
37 | ${Boost_LIBRARIES}
38 | ${catkin_LIBRARIES}
39 | ${Pangolin_LIBRARIES}
40 | Kontiki
41 | )
42 |
43 | catkin_package(
44 | INCLUDE_DIRS include
45 | # LIBRARIES li_calibr_lib
46 | # CATKIN_DEPENDS geometry_msgs nav_msgs roscpp std_msgs velodyne_msgs
47 | # DEPENDS system_lib
48 | )
49 |
50 | include_directories( include
51 | ${catkin_INCLUDE_DIRS}
52 | ${EIGEN3_INCLUDE_DIR}
53 | ${Boost_INCLUDE_DIRS}
54 | ${Pangolin_INCLUDE_DIRS}
55 | )
56 |
57 | add_library(li_calib_lib
58 | src/core/trajectory_manager.cpp
59 | src/core/inertial_initializer.cpp
60 | src/core/lidar_odometry.cpp
61 | src/core/surfel_association.cpp
62 | )
63 | target_link_libraries(li_calib_lib ${thirdparty_libraries})
64 |
65 | add_executable(li_calib_gui
66 | test/li_calib_gui.cpp
67 | src/ui/calib_helper.cpp
68 | src/ui/calib_ui.cpp)
69 | target_link_libraries(li_calib_gui li_calib_lib ${thirdparty_libraries})
--------------------------------------------------------------------------------
/include/ui/calib_ui.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 | #ifndef CALIB_UI_H
22 | #define CALIB_UI_H
23 |
24 | #include
25 | #include
26 |
27 | using namespace licalib;
28 |
29 | struct TranslationVector {
30 | Eigen::Vector3d trans = Eigen::Vector3d(0,0,0);
31 | };
32 |
33 | class CalibInterface : public CalibrHelper {
34 | public:
35 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36 | CalibInterface(ros::NodeHandle& nh);
37 |
38 | void initGui();
39 |
40 | void renderingLoop();
41 |
42 | void showCalibResult();
43 |
44 | void resetModelView() {
45 | s_cam_.SetModelViewMatrix(pangolin::ModelViewLookAt(0,0,40,0,0,0,pangolin::AxisNegY));
46 | }
47 |
48 | private:
49 | static constexpr int UI_WIDTH = 300;
50 |
51 | pangolin::View *pointcloud_view_display_;
52 | pangolin::OpenGlRenderState s_cam_;
53 |
54 | std::vector pangolin_colors_;
55 |
56 | pangolin::Var show_surfel_map_;
57 | pangolin::Var show_all_association_points_;
58 | pangolin::Var optimize_time_offset_;
59 | pangolin::Var show_lidar_frame_;
60 |
61 | pangolin::Var show_p_IinL_;
62 | pangolin::Var show_q_ItoL_;
63 | pangolin::Var show_gravity_;
64 | pangolin::Var show_gyro_bias_;
65 | pangolin::Var show_acce_bias_;
66 | pangolin::Var show_time_offset_;
67 | };
68 |
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/include/utils/ceres_callbacks.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 | #ifndef _CERES_CALLBACKS_
22 | #define _CERES_CALLBACKS_
23 |
24 | #include
25 | #include
26 | #include
27 |
28 |
29 | namespace licalib {
30 |
31 | class CheckStateCallback : public ceres::IterationCallback {
32 | public:
33 | CheckStateCallback() : iteration_(0u) {}
34 |
35 | ~CheckStateCallback() {}
36 |
37 | void addCheckState(const std::string& description, size_t block_size,
38 | double* param_block) {
39 | parameter_block_descr.push_back(description);
40 | parameter_block_sizes.push_back(block_size);
41 | parameter_blocks.push_back(param_block);
42 | }
43 |
44 | ceres::CallbackReturnType operator()(
45 | const ceres::IterationSummary& summary) {
46 | std::cout << "Iteration: " << iteration_ << std::endl;
47 | for (size_t i = 0; i < parameter_block_descr.size(); ++i) {
48 | std::cout << parameter_block_descr.at(i) << " ";
49 | for (size_t k = 0; k < parameter_block_sizes.at(i); ++k)
50 | std::cout << parameter_blocks.at(i)[k] << " ";
51 | std::cout << std::endl;
52 | }
53 |
54 | ++iteration_;
55 | return ceres::SOLVER_CONTINUE;
56 | }
57 |
58 | private:
59 |
60 | std::vector parameter_block_descr;
61 | std::vector parameter_block_sizes;
62 | std::vector parameter_blocks;
63 |
64 | // Count iterations locally
65 | size_t iteration_;
66 | };
67 |
68 | }
69 |
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/include/ui/calib_helper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 | #ifndef CALIB_HELPER_H
22 | #define CALIB_HELPER_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | //the following are UBUNTU/LINUX ONLY terminal color codes.
31 | #define RESET "\033[0m"
32 | #define BLACK "\033[30m" /* Black */
33 | #define RED "\033[31m" /* Red */
34 | #define GREEN "\033[32m" /* Green */
35 | #define YELLOW "\033[33m" /* Yellow */
36 | #define BLUE "\033[34m" /* Blue */
37 | #define MAGENTA "\033[35m" /* Magenta */
38 | #define CYAN "\033[36m" /* Cyan */
39 | #define WHITE "\033[37m" /* White */
40 |
41 | namespace licalib {
42 |
43 | class CalibrHelper {
44 | public:
45 |
46 | enum CalibStep {
47 | Error = 0,
48 | Start,
49 | InitializationDone,
50 | DataAssociationDone,
51 | BatchOptimizationDone,
52 | RefineDone
53 | };
54 |
55 | explicit CalibrHelper(ros::NodeHandle& nh);
56 |
57 | bool createCacheFolder(const std::string& bag_path);
58 |
59 | void Initialization();
60 |
61 | void DataAssociation();
62 |
63 | void BatchOptimization();
64 |
65 | void Refinement();
66 |
67 | void saveCalibResult(const std::string& calib_result_file) const;
68 |
69 | void saveMap() const;
70 |
71 | protected:
72 |
73 | void Mapping(bool relocalization = false);
74 |
75 | /// dataset
76 | std::string cache_path_;
77 | std::string topic_imu_;
78 | std::string bag_path_;
79 |
80 | /// optimization
81 | CalibStep calib_step_;
82 | int iteration_step_;
83 | bool opt_time_offset_;
84 |
85 | /// lidar odometry
86 | double map_time_;
87 | double ndt_resolution_;
88 | double scan4map_time_;
89 |
90 | /// data association
91 | double associated_radius_;
92 | double plane_lambda_;
93 |
94 | std::shared_ptr dataset_reader_;
95 | InertialInitializer::Ptr rotation_initializer_;
96 | TrajectoryManager::Ptr traj_manager_;
97 | LiDAROdometry::Ptr lidar_odom_;
98 | SurfelAssociation::Ptr surfel_association_;
99 |
100 | ScanUndistortion::Ptr scan_undistortion_;
101 | };
102 |
103 | }
104 |
105 | #endif
106 |
--------------------------------------------------------------------------------
/include/utils/pcl_utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 | #ifndef PCL_UTILS_H
22 | #define PCL_UTILS_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | namespace licalib {
32 |
33 | typedef pcl::PointXYZI VPoint;
34 | typedef pcl::PointCloud VPointCloud;
35 |
36 | typedef pcl::PointXYZRGB colorPointT;
37 | typedef pcl::PointCloud colorPointCloudT;
38 |
39 | struct PointXYZIT {
40 | PCL_ADD_POINT4D
41 | float intensity;
42 | double timestamp;
43 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
44 | } EIGEN_ALIGN16;
45 |
46 | inline void downsampleCloud(pcl::PointCloud::Ptr in_cloud,
47 | pcl::PointCloud::Ptr out_cloud,
48 | float in_leaf_size) {
49 | pcl::VoxelGrid sor;
50 | sor.setInputCloud(in_cloud);
51 | sor.setLeafSize((float)in_leaf_size, (float)in_leaf_size, (float)in_leaf_size);
52 | sor.filter(*out_cloud);
53 | }
54 |
55 | };
56 |
57 | POINT_CLOUD_REGISTER_POINT_STRUCT(licalib::PointXYZIT,
58 | (float, x, x)
59 | (float, y, y)
60 | (float, z, z)
61 | (float, intensity, intensity)
62 | (double, timestamp, timestamp))
63 |
64 | typedef licalib::PointXYZIT TPoint;
65 | typedef pcl::PointCloud TPointCloud;
66 |
67 | inline void TPointCloud2VPointCloud(TPointCloud::Ptr input_pc,
68 | licalib::VPointCloud::Ptr output_pc) {
69 | output_pc->header = input_pc->header;
70 | output_pc->height = input_pc->height;
71 | output_pc->width = input_pc->width;
72 | output_pc->is_dense = input_pc->is_dense;
73 | output_pc->resize(output_pc->width * output_pc->height);
74 | for(int h = 0; h < input_pc->height; h++) {
75 | for(int w = 0; w < input_pc->width; w++) {
76 | licalib::VPoint point;
77 | point.x = input_pc->at(w,h).x;
78 | point.y = input_pc->at(w,h).y;
79 | point.z = input_pc->at(w,h).z;
80 | point.intensity = input_pc->at(w,h).intensity;
81 | output_pc->at(w,h) = point;
82 | }
83 | }
84 | }
85 |
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/src/core/inertial_initializer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * LI_Calib: An Open Platform for LiDAR-IMU Calibration
3 | * Copyright (C) 2020 Jiajun Lv
4 | * Copyright (C) 2020 Kewei Hu
5 | * Copyright (C) 2020 Jinhong Xu
6 | * Copyright (C) 2020 LI_Calib Contributors
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 | #include
22 | #include
23 |
24 | namespace licalib {
25 |
26 | bool InertialInitializer::EstimateRotation(
27 | TrajectoryManager::Ptr traj_manager,
28 | const Eigen::aligned_vector& odom_data) {
29 |
30 | int flags = kontiki::trajectories::EvalOrientation;
31 | std::shared_ptr p_traj
32 | = traj_manager->getTrajectory();
33 |
34 | Eigen::aligned_vector A_vec;
35 | for (size_t j = 1; j < odom_data.size(); ++j) {
36 | size_t i = j - 1;
37 | double ti = odom_data.at(i).timestamp;
38 | double tj = odom_data.at(j).timestamp;
39 | if (tj >= p_traj->MaxTime())
40 | break;
41 | auto result_i = p_traj->Evaluate(ti, flags);
42 | auto result_j = p_traj->Evaluate(tj, flags);
43 | Eigen::Quaterniond delta_qij_imu = result_i->orientation.conjugate()
44 | * result_j->orientation;
45 |
46 | Eigen::Matrix3d R_Si_toS0 = odom_data.at(i).pose.topLeftCorner<3,3>();
47 | Eigen::Matrix3d R_Sj_toS0 = odom_data.at(j).pose.topLeftCorner<3,3>();
48 | Eigen::Matrix3d delta_ij_sensor = R_Si_toS0.transpose() * R_Sj_toS0;
49 | Eigen::Quaterniond delta_qij_sensor(delta_ij_sensor);
50 |
51 | Eigen::AngleAxisd R_vector1(delta_qij_sensor.toRotationMatrix());
52 | Eigen::AngleAxisd R_vector2(delta_qij_imu.toRotationMatrix());
53 | double delta_angle = 180 / M_PI * std::fabs(R_vector1.angle() - R_vector2.angle());
54 | double huber = delta_angle > 1.0 ? 1.0/delta_angle : 1.0;
55 |
56 | Eigen::Matrix4d lq_mat = mathutils::LeftQuatMatrix(delta_qij_sensor);
57 | Eigen::Matrix4d rq_mat = mathutils::RightQuatMatrix(delta_qij_imu);
58 | A_vec.push_back(huber * (lq_mat - rq_mat));
59 | }
60 | size_t valid_size = A_vec.size();
61 | if (valid_size < 15) {
62 | return false;
63 | }
64 | Eigen::MatrixXd A(valid_size * 4, 4);
65 | for (size_t i = 0; i < valid_size; ++i)
66 | A.block<4, 4>(i * 4, 0) = A_vec.at(i);
67 |
68 | Eigen::JacobiSVD svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV);
69 |
70 | Eigen::Matrix x = svd.matrixV().col(3);
71 | Eigen::Quaterniond q_ItoS_est(x);
72 | Eigen::Vector4d cov = svd.singularValues();
73 |
74 | if (cov(2) > 0.25) {
75 | q_ItoS_est_ = q_ItoS_est;
76 | rotaion_initialized_ = true;
77 | return true;
78 | } else {
79 | return false;
80 | }
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/include/utils/eigen_utils.hpp:
--------------------------------------------------------------------------------
1 | /**
2 | BSD 3-Clause License
3 |
4 | This file is part of the Basalt project.
5 | https://gitlab.com/VladyslavUsenko/basalt-headers.git
6 |
7 | Copyright (c) 2019, Vladyslav Usenko and Nikolaus Demmel.
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without
11 | modification, are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this
14 | list of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 |
20 | * Neither the name of the copyright holder nor the names of its
21 | contributors may be used to endorse or promote products derived from
22 | this software without specific prior written permission.
23 |
24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 | @file
36 | @brief Definition of the standard containers with Eigen allocator.
37 | */
38 |
39 | #pragma once
40 |
41 | #include
42 | #include