|
@@ -9,6 +9,10 @@
|
|
|
#include <ndt_cpu/NormalDistributionsTransform.h>
|
|
|
#include <pcl/registration/ndt.h>
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+#include <thread>
|
|
|
+
|
|
|
//定义结构体,点的六自由度的数据
|
|
|
struct pose
|
|
|
{
|
|
@@ -31,7 +35,7 @@ static pose previous_pose, guess_pose, guess_pose_imu, guess_pose_odom, guess_po
|
|
|
static int max_iter = 30; // Maximum iterations
|
|
|
static float ndt_res = 1.0; // Resolution
|
|
|
static double step_size = 0.1; // Step size
|
|
|
-static double trans_eps = 0.01; // Transformation epsilon
|
|
|
+static double trans_eps = 0.001; // Transformation epsilon
|
|
|
|
|
|
//tf变换的状态值
|
|
|
static double _tf_x, _tf_y, _tf_z, _tf_roll, _tf_pitch, _tf_yaw;
|
|
@@ -42,7 +46,8 @@ static Eigen::Matrix4f tf_btol, tf_ltob;
|
|
|
static pcl::NormalDistributionsTransform<pcl::PointXYZI, pcl::PointXYZI> ndt;
|
|
|
|
|
|
void point_ndtcalib(pcl::PointCloud<pcl::PointXYZI>::Ptr raw_scan1,pcl::PointCloud<pcl::PointXYZI>::Ptr raw_scan2,
|
|
|
- double &x,double & y,double & z,double & yaw,double & pitch,double & roll)
|
|
|
+ double &x,double & y,double & z,double & yaw,double & pitch,double & roll,pcl::PointCloud<pcl::PointXYZI>::Ptr & merge_pc,
|
|
|
+ Eigen::Matrix4f & t_calib)
|
|
|
{
|
|
|
|
|
|
Eigen::Translation3f tl_btol(_tf_x, _tf_y, _tf_z); // tl: translation
|
|
@@ -53,8 +58,8 @@ void point_ndtcalib(pcl::PointCloud<pcl::PointXYZI>::Ptr raw_scan1,pcl::PointClo
|
|
|
tf_ltob = tf_btol.inverse();
|
|
|
|
|
|
|
|
|
- const double min_scan_range = 3.0;
|
|
|
- const double max_scan_range = 30.0;
|
|
|
+ const double min_scan_range = 6.0;
|
|
|
+ const double max_scan_range = 100.0;
|
|
|
double r;
|
|
|
pcl::PointXYZI p;
|
|
|
pcl::PointCloud<pcl::PointXYZI> tmp, scan1,scan2;
|
|
@@ -108,6 +113,7 @@ void point_ndtcalib(pcl::PointCloud<pcl::PointXYZI>::Ptr raw_scan1,pcl::PointClo
|
|
|
pcl::PointCloud<pcl::PointXYZI>::Ptr scan_ptr1(new pcl::PointCloud<pcl::PointXYZI>(scan1));
|
|
|
pcl::PointCloud<pcl::PointXYZI>::Ptr scan_ptr2(new pcl::PointCloud<pcl::PointXYZI>(scan2));
|
|
|
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr transformed_scan_ptr2(new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
|
|
|
double voxel_leaf_size = 0.1;
|
|
|
|
|
@@ -132,6 +138,7 @@ void point_ndtcalib(pcl::PointCloud<pcl::PointXYZI>::Ptr raw_scan1,pcl::PointClo
|
|
|
Eigen::AngleAxisf init_rotation_z(0.0, Eigen::Vector3f::UnitZ());
|
|
|
|
|
|
Eigen::Translation3f init_translation(0.0, 0.0, 0.0);
|
|
|
+// Eigen::Translation3f init_translation(-0.5, 0.0, -0.3);
|
|
|
|
|
|
Eigen::Matrix4f init_guess =
|
|
|
(init_translation * init_rotation_z * init_rotation_y * init_rotation_x).matrix() * tf_btol;
|
|
@@ -168,9 +175,14 @@ void point_ndtcalib(pcl::PointCloud<pcl::PointXYZI>::Ptr raw_scan1,pcl::PointClo
|
|
|
|
|
|
std::cout<<"prob is "<<transformation_probability<<std::endl;
|
|
|
|
|
|
+ std::cout<<" t loc "<<t_localizer<<std::endl;
|
|
|
+
|
|
|
t_base_link = t_localizer * tf_ltob;
|
|
|
// 执行点云变换,将该帧的点云变换到以初始状态为起点的坐标系下的点云
|
|
|
- // pcl::transformPointCloud(*scan_ptr2, *transformed_scan_ptr2, t_localizer);
|
|
|
+ int64_t time1 = std::chrono::system_clock::now().time_since_epoch().count()/1000;
|
|
|
+ pcl::transformPointCloud(*raw_scan2, *transformed_scan_ptr2, t_localizer);
|
|
|
+ int64_t time2 = std::chrono::system_clock::now().time_since_epoch().count()/1000;
|
|
|
+ std::cout<<"transformPointCloud use: "<<(time2 - time1)<<"us"<<std::endl;
|
|
|
// 取t_localizer和t_base_link的左上角的3*3的矩阵
|
|
|
tf::Matrix3x3 mat_l, mat_b;
|
|
|
|
|
@@ -208,4 +220,14 @@ void point_ndtcalib(pcl::PointCloud<pcl::PointXYZI>::Ptr raw_scan1,pcl::PointClo
|
|
|
pitch = ndt_pose.pitch;
|
|
|
roll = ndt_pose.roll;
|
|
|
|
|
|
+ // pcl::io::savePCDFile("/home/nvidia/app/app/trans.pcd",*transformed_scan_ptr2);
|
|
|
+
|
|
|
+
|
|
|
+ *merge_pc = *transformed_scan_ptr2 + *scan_ptr1;
|
|
|
+ t_calib = t_localizer;
|
|
|
+
|
|
|
+ pcl::io::savePCDFile("/home/nvidia/app/app/merge.pcd",*merge_pc);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|