|
@@ -16,6 +16,11 @@
|
|
#include <vector>
|
|
#include <vector>
|
|
#include <thread>
|
|
#include <thread>
|
|
|
|
|
|
|
|
+#include <pcl/common/transforms.h>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#include <Eigen/Eigen>
|
|
|
|
+
|
|
#include "lidarmerge.h"
|
|
#include "lidarmerge.h"
|
|
#include "modulecomm.h"
|
|
#include "modulecomm.h"
|
|
#include "ivversion.h"
|
|
#include "ivversion.h"
|
|
@@ -34,8 +39,14 @@ static char gstrcentermemename[256];
|
|
static char gstroutmemname[256];
|
|
static char gstroutmemname[256];
|
|
static void * gpaout;
|
|
static void * gpaout;
|
|
|
|
|
|
-static bool gbrun;
|
|
|
|
|
|
+static bool gbrun = true;
|
|
|
|
+
|
|
|
|
+static Eigen::Matrix4f gleft_calib(Eigen::Matrix4f::Identity());
|
|
|
|
+static Eigen::Matrix4f gright_calib(Eigen::Matrix4f::Identity());
|
|
|
|
|
|
|
|
+static bool gbLoadLeftCalib = false;
|
|
|
|
+static bool gbLoadRightCalib = false;
|
|
|
|
+static bool gbLimitSide = false; //if true, use yaml max min
|
|
|
|
|
|
static void InitLidarData()
|
|
static void InitLidarData()
|
|
{
|
|
{
|
|
@@ -65,8 +76,65 @@ static void InitLidarData()
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void dec_calibyaml(const char * stryamlpath,Eigen::Matrix4f & calib,bool & bload)
|
|
|
|
+{
|
|
|
|
+ YAML::Node config;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ config = YAML::LoadFile(stryamlpath);
|
|
|
|
+ }
|
|
|
|
+ catch(YAML::BadFile e)
|
|
|
|
+ {
|
|
|
|
+ qDebug("load %s error.",stryamlpath);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+ if(config["Calib"])
|
|
|
|
+ {
|
|
|
|
+ YAML::Node node_calib = config["Calib"];
|
|
|
|
+// bool isscalar = node_calib.IsScalar();
|
|
|
|
+// bool ismap = node_calib.IsMap();
|
|
|
|
+ bool isseq = node_calib.IsSequence();
|
|
|
|
+ if(isseq)
|
|
|
|
+ {
|
|
|
|
+ int size = node_calib.size();
|
|
|
|
+ int i=0;
|
|
|
|
+ int j= 0;
|
|
|
|
+ if(size == 16)
|
|
|
|
+ {
|
|
|
|
+ auto node_it = node_calib.begin();
|
|
|
|
+ for(;node_it != node_calib.end();node_it++)
|
|
|
|
+ {
|
|
|
|
+ std::string strvalue = node_it->as<std::string>();
|
|
|
|
+ // std::cout<<"value:["<<strvalue<<"]"<<std::endl;
|
|
|
|
+ calib(i,j) = atof(strvalue.data());
|
|
|
|
+ j++;
|
|
|
|
+ if(j>=4)
|
|
|
|
+ {
|
|
|
|
+ i++;
|
|
|
|
+ j=0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ bload = true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" calib not 16 values. "<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" calib value not seq. "<<std::endl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
void dec_yaml(const char * stryamlpath)
|
|
void dec_yaml(const char * stryamlpath)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -77,10 +145,18 @@ void dec_yaml(const char * stryamlpath)
|
|
}
|
|
}
|
|
catch(YAML::BadFile e)
|
|
catch(YAML::BadFile e)
|
|
{
|
|
{
|
|
- qDebug("load error.");
|
|
|
|
|
|
+ qDebug("load %s error.",stryamlpath);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if(config["limitside"])
|
|
|
|
+ {
|
|
|
|
+ std::string strlimit = config["limitside"].as<std::string>();
|
|
|
|
+ if(strlimit == "true")
|
|
|
|
+ {
|
|
|
|
+ gbLimitSide = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
if(config["left"]["memname"])
|
|
if(config["left"]["memname"])
|
|
{
|
|
{
|
|
@@ -131,6 +207,7 @@ void dec_yaml(const char * stryamlpath)
|
|
|
|
|
|
void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
{
|
|
{
|
|
|
|
+// std::cout<<" listen point cloud. "<<std::endl;
|
|
if(nSize <=16)return;
|
|
if(nSize <=16)return;
|
|
unsigned int * pHeadSize = (unsigned int *)strdata;
|
|
unsigned int * pHeadSize = (unsigned int *)strdata;
|
|
if(*pHeadSize > nSize)
|
|
if(*pHeadSize > nSize)
|
|
@@ -213,6 +290,38 @@ void sharepointcloud(pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud,void * pa)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+void LimitSide(pcl::PointCloud<pcl::PointXYZI>::Ptr & point_cloud,iv::lidar_data & xlidardata)
|
|
|
|
+{
|
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr new_scan(new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
|
+ new_scan->header = point_cloud->header;
|
|
|
|
+ new_scan->width = 0;
|
|
|
|
+
|
|
|
|
+ pcl::PointXYZI p;
|
|
|
|
+ for (pcl::PointCloud<pcl::PointXYZI>::const_iterator item = point_cloud->begin(); item != point_cloud->end(); item++)
|
|
|
|
+ {
|
|
|
|
+ p.x = (double)item->x;
|
|
|
|
+ if(p.x > xlidardata.fmax_x)continue;
|
|
|
|
+ if(p.x < xlidardata.fmin_x)continue;
|
|
|
|
+
|
|
|
|
+ p.y = (double)item->y;
|
|
|
|
+ if(p.y > xlidardata.fmax_y)continue;
|
|
|
|
+ if(p.y < xlidardata.fmin_y)continue;
|
|
|
|
+
|
|
|
|
+ p.z = (double)item->z;
|
|
|
|
+ if(p.z > xlidardata.fmax_z)continue;
|
|
|
|
+ if(p.z < xlidardata.fmin_z)continue;
|
|
|
|
+
|
|
|
|
+ p.intensity = (double)item->intensity;
|
|
|
|
+
|
|
|
|
+ new_scan->push_back(p);
|
|
|
|
+ new_scan->width++;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ point_cloud = new_scan;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
void mergethread()
|
|
void mergethread()
|
|
{
|
|
{
|
|
@@ -225,7 +334,6 @@ void mergethread()
|
|
pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud_center = NULL;
|
|
pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud_center = NULL;
|
|
while(gbrun)
|
|
while(gbrun)
|
|
{
|
|
{
|
|
-
|
|
|
|
bool bCenterUpdate = false;
|
|
bool bCenterUpdate = false;
|
|
bool bLeftUpdate = false;
|
|
bool bLeftUpdate = false;
|
|
bool bRightUpdate = false;
|
|
bool bRightUpdate = false;
|
|
@@ -252,26 +360,56 @@ void mergethread()
|
|
glidar_data_center.mmutex.lock();
|
|
glidar_data_center.mmutex.lock();
|
|
if(glidar_data_center.bUpdate)
|
|
if(glidar_data_center.bUpdate)
|
|
{
|
|
{
|
|
- point_cloud_center = glidar_data_left.mpoint_cloud;
|
|
|
|
- ncenterupdatetime = glidar_data_left.mupdatetime;
|
|
|
|
- glidar_data_left.bUpdate = false;
|
|
|
|
|
|
+ point_cloud_center = glidar_data_center.mpoint_cloud;
|
|
|
|
+ ncenterupdatetime = glidar_data_center.mupdatetime;
|
|
|
|
+ glidar_data_center.bUpdate = false;
|
|
bCenterUpdate = true;
|
|
bCenterUpdate = true;
|
|
}
|
|
}
|
|
- glidar_data_left.mmutex.unlock();
|
|
|
|
|
|
+ glidar_data_center.mmutex.unlock();
|
|
|
|
|
|
- if(bLeftUpdate)
|
|
|
|
|
|
+ if(bLeftUpdate && gbLoadLeftCalib)
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ if(gbLimitSide)
|
|
|
|
+ {
|
|
|
|
+ LimitSide(point_cloud_left,glidar_data_left);
|
|
|
|
+ }
|
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr transformed_scan_ptr2(new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
|
+ pcl::transformPointCloud(*point_cloud_left, *transformed_scan_ptr2, gleft_calib);
|
|
|
|
+ point_cloud_left = transformed_scan_ptr2;
|
|
}
|
|
}
|
|
- if(bRightUpdate)
|
|
|
|
|
|
+ if(bRightUpdate && gbLoadRightCalib)
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ if(gbLimitSide)
|
|
|
|
+ {
|
|
|
|
+ LimitSide(point_cloud_right,glidar_data_right);
|
|
|
|
+ }
|
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr transformed_scan_ptr2(new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
|
+ pcl::transformPointCloud(*point_cloud_right, *transformed_scan_ptr2, gright_calib);
|
|
|
|
+ point_cloud_right = transformed_scan_ptr2;
|
|
}
|
|
}
|
|
//transform
|
|
//transform
|
|
|
|
|
|
if(bCenterUpdate)
|
|
if(bCenterUpdate)
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud_out(new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
|
+ point_cloud_out = point_cloud_center;
|
|
|
|
+ if(gbLoadLeftCalib &&(abs(ncenterupdatetime - nleftupdatetime)<200) &&(point_cloud_left != NULL))
|
|
|
|
+ {
|
|
|
|
+ *point_cloud_out = *point_cloud_out + *point_cloud_left;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" no left "<<" left calib: "<<gbLoadLeftCalib<<" time diff: "<<(ncenterupdatetime - nleftupdatetime)<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ if(gbLoadRightCalib &&(abs(ncenterupdatetime - nrightupdatetime)<200) &&(point_cloud_right != NULL))
|
|
|
|
+ {
|
|
|
|
+ *point_cloud_out = *point_cloud_out + *point_cloud_right;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" no right "<<" right calib: "<<gbLoadRightCalib<<" time diff: "<<(ncenterupdatetime - nrightupdatetime)<<std::endl;
|
|
|
|
+ }
|
|
|
|
+ sharepointcloud(point_cloud_out,gpaout);
|
|
}
|
|
}
|
|
//Merge
|
|
//Merge
|
|
|
|
|
|
@@ -289,7 +427,15 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
InitLidarData();
|
|
InitLidarData();
|
|
|
|
|
|
|
|
+ snprintf(gstrcentermemename,256,"lidar_pc");
|
|
|
|
+ snprintf(gstroutmemname,256,"lidarpc_fusion");
|
|
|
|
+
|
|
dec_yaml("fusion_pointcloud_shenlan.yaml");
|
|
dec_yaml("fusion_pointcloud_shenlan.yaml");
|
|
|
|
+ dec_calibyaml("fusion_left.yaml",gleft_calib,gbLoadLeftCalib);
|
|
|
|
+ dec_calibyaml("fusion_right.yaml",gright_calib,gbLoadRightCalib);
|
|
|
|
+
|
|
|
|
+ std::cout<<"left calib: \n[ "<<gleft_calib<<" ]"<<std::endl;
|
|
|
|
+ std::cout<<"right calib: \n[ "<<gright_calib<<" ]"<<std::endl;
|
|
|
|
|
|
iv::modulecomm::RegisterRecv(glidar_data_left.strmemname,ListenPointCloud);
|
|
iv::modulecomm::RegisterRecv(glidar_data_left.strmemname,ListenPointCloud);
|
|
iv::modulecomm::RegisterRecv(glidar_data_right.strmemname,ListenPointCloud);
|
|
iv::modulecomm::RegisterRecv(glidar_data_right.strmemname,ListenPointCloud);
|
|
@@ -299,5 +445,7 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
std::thread xthread(mergethread);
|
|
std::thread xthread(mergethread);
|
|
|
|
|
|
|
|
+ (void)xthread;
|
|
|
|
+
|
|
return a.exec();
|
|
return a.exec();
|
|
}
|
|
}
|