Commit 0bf6b9f9 authored by xiebojie's avatar xiebojie

merge files from pcl-1 online code

parent 01ea89a7
File added
...@@ -3,26 +3,27 @@ ...@@ -3,26 +3,27 @@
#ifndef PCL_POINT_TYPE_H #ifndef PCL_POINT_TYPE_H
#define PCL_POINT_TYPE_H #define PCL_POINT_TYPE_H
#include <pcl/point_types.h>
#include <pcl/point_cloud.h> #include <pcl/point_cloud.h>
#include <pcl/point_types.h>
namespace pcl { namespace pcl {
struct PointInternal { struct PointInternal {
PCL_ADD_POINT4D PCL_ADD_POINT4D
PCL_ADD_RGB PCL_ADD_RGB
float intensity; float intensity;
float ring; float ring;
float label = 0; float label = 0;
float distance; float distance;
double timestamp; double timestamp;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
} EIGEN_ALIGN16; } EIGEN_ALIGN16;
}//end namespace pcl } // end namespace pcl
POINT_CLOUD_REGISTER_POINT_STRUCT( POINT_CLOUD_REGISTER_POINT_STRUCT(
pcl::PointInternal, (float, x, x)(float, y, y)(float, z, z)(float, rgb, rgb) pcl::PointInternal,
(float, intensity, intensity)(float, ring, ring)(float, label, label) (float, x, x)(float, y, y)(float, z, z)(float, rgb, rgb)(
(float, distance, distance)(double, timestamp, timestamp)) float, intensity, intensity)(float, ring, ring)(float, label, label)(
float, distance, distance)(double, timestamp, timestamp))
typedef pcl::PointInternal Point; typedef pcl::PointInternal Point;
typedef pcl::PointCloud<Point> PointCloud; typedef pcl::PointCloud<Point> PointCloud;
...@@ -32,19 +33,19 @@ typedef pcl::PointCloud<Point> PointCloud; ...@@ -32,19 +33,19 @@ typedef pcl::PointCloud<Point> PointCloud;
/// ///
namespace pcl { namespace pcl {
struct PointRos { struct PointRos {
PCL_ADD_POINT4D PCL_ADD_POINT4D
float intensity; float intensity;
float ring; float ring;
float label = 0; float label = 0;
float timestamp; float timestamp;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
} EIGEN_ALIGN32; } EIGEN_ALIGN32;
}//end namespace pcl } // end namespace pcl
POINT_CLOUD_REGISTER_POINT_STRUCT( POINT_CLOUD_REGISTER_POINT_STRUCT(
pcl::PointRos, (float, x, x)(float, y, y)(float, z, z) pcl::PointRos,
(float, intensity, intensity)(float, ring, ring)(float, label, label) (float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity)(
(float, timestamp, timestamp)) float, ring, ring)(float, label, label)(float, timestamp, timestamp))
typedef pcl::PointRos PointRos; typedef pcl::PointRos PointRos;
typedef pcl::PointCloud<PointRos> PointCloudRos; typedef pcl::PointCloud<PointRos> PointCloudRos;
...@@ -54,18 +55,19 @@ typedef pcl::PointCloud<PointRos> PointCloudRos; ...@@ -54,18 +55,19 @@ typedef pcl::PointCloud<PointRos> PointCloudRos;
/// ///
namespace pcl { namespace pcl {
struct PointExport { struct PointExport {
PCL_ADD_POINT4D PCL_ADD_POINT4D
PCL_ADD_RGB PCL_ADD_RGB
float intensity = 0; float intensity = 0;
float label = 0; float label = 0;
float info = 0; float info = 0;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
} EIGEN_ALIGN16; } EIGEN_ALIGN16;
}//end namespace pcl } // end namespace pcl
POINT_CLOUD_REGISTER_POINT_STRUCT( POINT_CLOUD_REGISTER_POINT_STRUCT(
pcl::PointExport, (float, x, x)(float, y, y)(float, z, z)(float, rgb, rgb) pcl::PointExport,
(float, intensity, intensity)(float, label, label)(float, info, info)) (float, x, x)(float, y, y)(float, z, z)(float, rgb, rgb)(
float, intensity, intensity)(float, label, label)(float, info, info))
typedef pcl::PointExport PointExport; typedef pcl::PointExport PointExport;
typedef pcl::PointCloud<PointExport> PointCloudExport; typedef pcl::PointCloud<PointExport> PointCloudExport;
...@@ -73,21 +75,39 @@ typedef pcl::PointCloud<PointExport> PointCloudExport; ...@@ -73,21 +75,39 @@ typedef pcl::PointCloud<PointExport> PointCloudExport;
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
namespace pcl { namespace pcl {
struct PointTemp1 { struct PointTemp1 {
PCL_ADD_POINT4D PCL_ADD_POINT4D
float intensity; float intensity;
float ring; float ring;
float label = 0; float label = 0;
float time; float time;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
} EIGEN_ALIGN16; } EIGEN_ALIGN16;
}//end namespace pcl } // end namespace pcl
POINT_CLOUD_REGISTER_POINT_STRUCT( POINT_CLOUD_REGISTER_POINT_STRUCT(
pcl::PointTemp1, (float, x, x)(float, y, y)(float, z, z) pcl::PointTemp1,
(float, intensity, intensity)(float, ring, ring)(float, label, label) (float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity)(
(float, time, time)) float, ring, ring)(float, label, label)(float, time, time))
typedef pcl::PointTemp1 PointTemp1; typedef pcl::PointTemp1 PointTemp1;
/////////////////////////////////////////////////////////////
namespace pcl {
struct PointI {
PCL_ADD_POINT4D
float intensity;
float stamp_offset;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
} EIGEN_ALIGN16;
} // end namespace pcl
POINT_CLOUD_REGISTER_POINT_STRUCT(
pcl::PointI,
(float, x, x)(float, y, y)(float, z, z)(float, intensity,
intensity)(float, stamp_offset,
stamp_offset))
typedef pcl::PointI PointI;
typedef pcl::PointCloud<PointI> PointCloudI;
#endif // PCL_POINT_TYPE_H #endif // PCL_POINT_TYPE_H
...@@ -49,7 +49,8 @@ bool PcdReader::loadFile() { ...@@ -49,7 +49,8 @@ bool PcdReader::loadFile() {
bool PcdReader::getNextFrame(PointCloud*& frame) { bool PcdReader::getNextFrame(PointCloud*& frame) {
if (pcdIndex_ >= pcdPathVec_.size()) return false; if (pcdIndex_ >= pcdPathVec_.size()) return false;
bool suceess = false; bool suceess = false;
PointCloud tempFrame; PointCloudI tempFrame;
double time;
while (!suceess) { while (!suceess) {
string pcdPath = pcdPathVec_.at(pcdIndex_); string pcdPath = pcdPathVec_.at(pcdIndex_);
pcdIndex_++; pcdIndex_++;
...@@ -60,17 +61,25 @@ bool PcdReader::getNextFrame(PointCloud*& frame) { ...@@ -60,17 +61,25 @@ bool PcdReader::getNextFrame(PointCloud*& frame) {
if (iter == frameTimeMap_.end()) { if (iter == frameTimeMap_.end()) {
continue; continue;
} }
double time = iter->second; time = iter->second;
int8_t ret = checkTime(time, durations_); int8_t ret = checkTime(time, durations_);
if (ret != 1) { if (ret != 1) {
continue; continue;
} }
for (auto& point : tempFrame) { // LOG(INFO) << setprecision(15) << "frameId: " << frameId
point.timestamp = time; // << " time: " << time;
}
suceess = true; suceess = true;
} }
frame = new PointCloud; frame = new PointCloud;
*frame = tempFrame; for (auto& pointI : tempFrame) {
Point point;
point.x = pointI.x;
point.y = pointI.y;
point.z = pointI.z;
point.timestamp = time + pointI.stamp_offset * 0.001;
point.intensity = pointI.intensity;
point.distance = sqrt(pow(point.x, 2) + pow(point.y, 2) + pow(point.z, 2));
frame->push_back(point);
}
return true; return true;
} }
...@@ -5,778 +5,767 @@ ...@@ -5,778 +5,767 @@
MapTask::MapTask(const vector<vector<Time_Duration>> &timeDurations, MapTask::MapTask(const vector<vector<Time_Duration>> &timeDurations,
boost::shared_ptr<StrategyControl> strategyControl, boost::shared_ptr<StrategyControl> strategyControl,
boost::shared_ptr<ParamsServer> paramsServer) boost::shared_ptr<ParamsServer> paramsServer)
:timeDurations_(timeDurations), : timeDurations_(timeDurations),
strategyControl_(strategyControl), strategyControl_(strategyControl),
paramsServer_(paramsServer) paramsServer_(paramsServer) {
{ voxeled_pointcloud_.reset(new PointCloud);
voxeled_pointcloud_.reset(new PointCloud); export_cloud_.reset(new PointCloudExport);
export_cloud_.reset(new PointCloudExport); filtered_cloud_.reset(new PointCloudExport);
filtered_cloud_.reset(new PointCloudExport); uint16_t cal_miss_cnt = strategyControl_->getStageInfos().size() - 1;
uint16_t cal_miss_cnt = strategyControl_->getStageInfos().size() - 1; dynamicRemover_.reset(new DynamicRemover(
dynamicRemover_.reset(new DynamicRemover( 0.06, MISS_PER_HIT_PER_STAGE * cal_miss_cnt, voxeled_pointcloud_));
0.06, MISS_PER_HIT_PER_STAGE * cal_miss_cnt, voxeled_pointcloud_)); for (const auto &durationvec : timeDurations_) {
for(const auto &durationvec : timeDurations_){ for (const auto &duration : durationvec) {
for(const auto &duration : durationvec){ LOG(INFO) << setprecision(15) << "MapTask "
LOG(INFO) <<setprecision(15) << "MapTask " << " duration.start_sec: " << duration.start_sec
<< " duration.start_sec: " << duration.start_sec << " duration.end_sec: " << duration.end_sec;
<<" duration.end_sec: " << duration.end_sec; }
} }
} configTrajectory();
configTrajectory();
} }
void MapTask::configTrajectory() void MapTask::configTrajectory() {
{ auto traj_mode = strategyControl_->getTrajMode();
auto traj_mode = strategyControl_->getTrajMode(); LOG(INFO) << "traj_mode: " << traj_mode;
LOG(INFO) << "traj_mode: " << traj_mode; if (traj_mode == PPK_UNDISORT_NODE_MAP_MODE) {
if(traj_mode == PPK_UNDISORT_NODE_MAP_MODE){ undistortion_traj_ = paramsServer_->getPPKTraj();
undistortion_traj_ = paramsServer_->getPPKTraj(); mapping_traj_ = paramsServer_->getNodeTraj();
mapping_traj_ = paramsServer_->getNodeTraj(); } else if (traj_mode == NODE_MODE) {
}else if(traj_mode == NODE_MODE){ undistortion_traj_ = paramsServer_->getNodeTraj();
undistortion_traj_ = paramsServer_->getNodeTraj(); mapping_traj_ = paramsServer_->getNodeTraj();
mapping_traj_ = paramsServer_->getNodeTraj(); } else if (traj_mode == PPK_MODE) {
}else if(traj_mode == PPK_MODE){ undistortion_traj_ = paramsServer_->getPPKTraj();
undistortion_traj_ = paramsServer_->getPPKTraj(); mapping_traj_ = paramsServer_->getPPKTraj();
mapping_traj_ = paramsServer_->getPPKTraj(); }
}
} }
bool MapTask::addTrajectory(const boost::shared_ptr<Trajectory> &trajectory) bool MapTask::addTrajectory(const boost::shared_ptr<Trajectory> &trajectory) {
{ TrajType trajType = trajectory->getTrajType();
TrajType trajType = trajectory->getTrajType(); auto traj_mode = strategyControl_->getTrajMode();
auto traj_mode = strategyControl_->getTrajMode(); if (traj_mode == PPK_UNDISORT_NODE_MAP_MODE) {
if(traj_mode == PPK_UNDISORT_NODE_MAP_MODE){ if (trajType == PPK) {
if(trajType == PPK){ if (!undistortion_traj_) {
if(!undistortion_traj_){ undistortion_traj_ = trajectory;
undistortion_traj_ = trajectory; } else {
}else{ LOG(INFO) << "undistortion_traj_: " << undistortion_traj_->getTrajPath()
LOG(INFO) << "undistortion_traj_: " << undistortion_traj_->getTrajPath() << " already set!";
<< " already set!"; return false;
return false; }
} } else if (trajType == NODE) {
}else if(trajType == NODE){ if (!mapping_traj_) {
if(!mapping_traj_){ mapping_traj_ = trajectory;
mapping_traj_ = trajectory; } else {
}else{ LOG(INFO) << "mapping_traj_: " << mapping_traj_->getTrajPath()
LOG(INFO) << "mapping_traj_: " << mapping_traj_->getTrajPath() << " already set!";
<< " already set!"; return false;
return false; }
} }
} } else if (traj_mode == NODE_MODE) {
}else if(traj_mode == NODE_MODE){ if (trajType == NODE) {
if(trajType == NODE){ if (!mapping_traj_) {
if(!mapping_traj_){ mapping_traj_ = trajectory;
mapping_traj_ = trajectory; undistortion_traj_ = trajectory;
undistortion_traj_ = trajectory; } else {
}else{ LOG(INFO) << "mapping_traj_: " << mapping_traj_->getTrajPath()
LOG(INFO) << "mapping_traj_: " << mapping_traj_->getTrajPath() << " already set!";
<< " already set!"; return false;
return false; }
} }
} } else if (traj_mode == PPK_MODE) {
}else if(traj_mode == PPK_MODE){ if (trajType == PPK) {
if(trajType == PPK){ if (!mapping_traj_) {
if(!mapping_traj_){ mapping_traj_ = trajectory;
mapping_traj_ = trajectory; undistortion_traj_ = trajectory;
undistortion_traj_ = trajectory; } else {
}else{ LOG(INFO) << "mapping_traj_: " << mapping_traj_->getTrajPath()
LOG(INFO) << "mapping_traj_: " << mapping_traj_->getTrajPath() << " already set!";
<< " already set!"; return false;
return false; }
}
}
} }
return true; }
return true;
} }
void MapTask::build() void MapTask::build() {
{ configTraj();
configTraj(); if (MERGE == strategyControl_->getTaskMode() && !isMerged) {
if(MERGE == strategyControl_->getTaskMode() && !isMerged){ return;
return; }
} if (taskTrajectory_.size() == 0 &&
if(taskTrajectory_.size() == 0 && strategyControl_->getOption() != "rawframe"){ strategyControl_->getOption() != "rawframe") {
return; return;
} }
vector<StageInfo> stageInfos = strategyControl_->getStageInfos(); vector<StageInfo> stageInfos = strategyControl_->getStageInfos();
request_to_end_ = false; request_to_end_ = false;
for(stage_ = 0; stage_ < stageInfos.size(); stage_++){ for (stage_ = 0; stage_ < stageInfos.size(); stage_++) {
stageInfo_ = strategyControl_->getStageInfos()[stage_]; stageInfo_ = strategyControl_->getStageInfos()[stage_];
LOG(INFO) << "stage_ " << stage_; LOG(INFO) << "stage_ " << stage_;
if(0 == stage_){ if (0 == stage_) {
establishProcessTrds(trdVec_); establishProcessTrds(trdVec_);
LOG(INFO) << "establishProcessTrds Done"; LOG(INFO) << "establishProcessTrds Done";
} }
getRawPointCloud(stageInfos[stage_]); getRawPointCloud(stageInfos[stage_]);
LOG(INFO) << "getRawPointCloud Done"; LOG(INFO) << "getRawPointCloud Done";
waitUntilFramesEmpty(); waitUntilFramesEmpty();
LOG(INFO) << "waitUntilFramesEmpty Done"; LOG(INFO) << "waitUntilFramesEmpty Done";
if(stageInfos.size() - 1 == stage_){ if (stageInfos.size() - 1 == stage_) {
joinProcessTrds(trdVec_); joinProcessTrds(trdVec_);
LOG(INFO) << "joinProcessTrds Done"; LOG(INFO) << "joinProcessTrds Done";
} }
if(strategyControl_->getFilterMode() == DIRECT_OUTPUT_MODE){ if (strategyControl_->getFilterMode() == DIRECT_OUTPUT_MODE) {
auto voxeledPointcloud = dynamicRemover_->getVoxeledPointcloud(); auto voxeledPointcloud = dynamicRemover_->getVoxeledPointcloud();
for(size_t i = 0; i < voxeledPointcloud->size(); i++){ for (size_t i = 0; i < voxeledPointcloud->size(); i++) {
auto p = voxeledPointcloud->at(i); auto p = voxeledPointcloud->at(i);
PointExport point; PointExport point;
point.x = p.x;point.y = p.y;point.z = p.z; point.x = p.x;
point.intensity = p.intensity; point.y = p.y;
export_cloud_->push_back(point); point.z = p.z;
} point.intensity = p.intensity;
return; export_cloud_->push_back(point);
} }
// dynamicRemover_->grid_coord_->printGrid(); return;
} }
dynamicRemover_->multiThreadFilter(export_cloud_, filtered_cloud_); // dynamicRemover_->grid_coord_->printGrid();
LOG(INFO) << "multiThreadFilter"; }
dynamicRemover_->multiThreadFilter(export_cloud_, filtered_cloud_);
LOG(INFO) << "multiThreadFilter";
} }
void MapTask::buildMappedFrame( void MapTask::buildMappedFrame(PointCloud *&frame, const StageInfo &stageInfo,
PointCloud*& frame, const StageInfo &stageInfo, size_t &guessUndisortIndex,
size_t &guessUndisortIndex, size_t &guessMapIndex) size_t &guessMapIndex) {
{ if (strategyControl_->getOption() == "rawframe") {
if(strategyControl_->getOption() == "rawframe"){ boost::unique_lock<boost::mutex> lock(Mtx_);
boost::unique_lock<boost::mutex> lock(Mtx_); if (frame->size()) {
if(frame->size()){ tempFrames_.push_back(*frame);
tempFrames_.push_back(*frame); }
} return;
return; }
}
auto frameSize = frame->size(); Matrix4d calib_1;
calib_1 = configCalib(stageInfo, 1);
Matrix4d calib_1; if (stageInfo.pointcloudSource == BAG &&
calib_1 = configCalib(stageInfo, 1); strategyControl_->getBagMode() == Disorted) {
if(stageInfo.pointcloudSource == BAG && calib_1.block(0, 0, 3, 3) = Matrix3d::Identity();
strategyControl_->getBagMode() == Disorted){ // LOG(INFO) << "calib linear = identity";
calib_1.block(0, 0, 3, 3) = Matrix3d::Identity(); }
// LOG(INFO) << "calib linear = identity"; Isometry3d T1;
} T1.translation() = calib_1.block(0, 3, 3, 1);
Isometry3d T1; T1.linear() = calib_1.block(0, 0, 3, 3);
T1.translation() = calib_1.block(0, 3, 3, 1); Isometry3d T = T1;
T1.linear() = calib_1.block(0, 0, 3, 3); Matrix4d calib_2 = configCalib(stageInfo, 2);
Isometry3d T = T1; Isometry3d T2;
Matrix4d calib_2 = configCalib(stageInfo, 2); T2.translation() = calib_2.block(0, 3, 3, 1);
Isometry3d T2; T2.linear() = calib_2.block(0, 0, 3, 3);
T2.translation() = calib_2.block(0, 3, 3, 1); T = T2 * T1;
T2.linear() = calib_2.block(0, 0, 3, 3);
T = T2 * T1; Matrix4d calib;
calib.block(0, 3, 3, 1) = T.translation();
Matrix4d calib; calib.block(0, 0, 3, 3) = T.linear();
calib.block(0, 3, 3, 1) = T.translation(); conductCalib(frame, calib);
calib.block(0, 0, 3, 3) = T.linear();
conductCalib(frame, calib); if ((stageInfo.pointcloudSource != BAG) ||
if((stageInfo.pointcloudSource == PCAP) strategyControl_->getBagMode() == Undisorted) {
|| strategyControl_->getBagMode() == Undisorted){ conductMappingByPoint(frame, guessUndisortIndex);
conductMappingByPoint(frame, guessUndisortIndex); if (0 == frame->size()) {
return;
if(0 == frame->size()){ }
return;
} if (PPK_UNDISORT_NODE_MAP_MODE == strategyControl_->getTrajMode()) {
conductInverse(frame);
if(PPK_UNDISORT_NODE_MAP_MODE == strategyControl_->getTrajMode()){ }
conductInverse(frame); }
}
} if (strategyControl_->getOption() == "undisortedframe") {
if (PPK_UNDISORT_NODE_MAP_MODE != strategyControl_->getTrajMode()) {
if(strategyControl_->getOption() == "undisortedframe"){ conductInverse(frame);
if(PPK_UNDISORT_NODE_MAP_MODE != strategyControl_->getTrajMode()){ }
conductInverse(frame); boost::unique_lock<boost::mutex> lock(Mtx_);
} if (frame->size()) {
boost::unique_lock<boost::mutex> lock(Mtx_); tempFrames_.push_back(*frame);
if(frame->size()){ }
tempFrames_.push_back(*frame); return;
} }
return;
} if (PPK_UNDISORT_NODE_MAP_MODE == strategyControl_->getTrajMode() &&
strategyControl_->getMappingLidar() == Fill &&
if(PPK_UNDISORT_NODE_MAP_MODE == strategyControl_->getTrajMode() && stageInfo.lidarPosition == TopLidar && stageInfo.hirMissmode == HIT) {
strategyControl_->getMappingLidar() == Fill && PointCloud topGroundCloud;
stageInfo.lidarPosition == TopLidar && for (const auto &p : *frame) {
stageInfo.hirMissmode == HIT){ if (p.z < 0 && p.z > -3 && fabs(p.x) < 10 && fabs(p.y) < 15) {
PointCloud topGroundCloud; topGroundCloud.push_back(p);
for(const auto &p : *frame){ }
if(p.z < 0 && p.z > -3 && }
fabs(p.x) < 10 && fabs(p.y) < 15){ topGroundCloud.sensor_orientation_ = frame->sensor_orientation_;
topGroundCloud.push_back(p); topGroundCloud.sensor_origin_ = frame->sensor_origin_;
}
} frame->swap(topGroundCloud);
topGroundCloud.sensor_orientation_ = frame->sensor_orientation_; // pcl::io::savePCDFileBinary("/tmp/temp.pcd", *frame);
topGroundCloud.sensor_origin_ = frame->sensor_origin_; // exit(0);
}
frame->swap(topGroundCloud);
// pcl::io::savePCDFileBinary("/tmp/temp.pcd", *frame); if (PPK_UNDISORT_NODE_MAP_MODE == strategyControl_->getTrajMode()) {
// exit(0); for (auto &p : *frame) {
} if (p.z < -1.4) {
p.data[3] = 1.0f;
if(PPK_UNDISORT_NODE_MAP_MODE == strategyControl_->getTrajMode()){ } else {
p.data[3] = 0.0f;
for(auto &p : *frame){ }
if(p.z < -1.4){ }
p.data[3] = 1.0f; conductMapping(frame, guessMapIndex);
}else{ } else {
p.data[3] = 0.0f; for (auto &p : *frame) {
} p.x -= local_traj_center_.x();
} p.y -= local_traj_center_.y();
conductMapping(frame, guessMapIndex); p.z -= local_traj_center_.z();
}else{ }
for(auto &p : *frame){ }
p.x -= local_traj_center_.x();
p.y -= local_traj_center_.y(); if (strategyControl_->getOption() == "mappedframe") {
p.z -= local_traj_center_.z(); boost::unique_lock<boost::mutex> lock(Mtx_);
} auto cloud = *frame;
} Vector3d local_center_from_center =
local_traj_center_ + paramsServer_->getCenterToSlamStartOffset();
if(strategyControl_->getOption() == "mappedframe"){ for (auto &p : cloud) {
boost::unique_lock<boost::mutex> lock(Mtx_); p.x += local_center_from_center.x();
auto cloud = *frame; p.y += local_center_from_center.y();
Vector3d local_center_from_center = local_traj_center_ + p.z += local_center_from_center.z();
paramsServer_->getCenterToSlamStartOffset(); }
for(auto &p : cloud){ if (cloud.size()) {
p.x += local_center_from_center.x(); tempFrames_.push_back(cloud);
p.y += local_center_from_center.y(); }
p.z += local_center_from_center.z(); return;
} }
if(cloud.size()){
tempFrames_.push_back(cloud);
}
return;
}
} }
void MapTask::directOutput(vector<PointCloud::Ptr> &Frames) void MapTask::directOutput(vector<PointCloud::Ptr> &Frames) {
{ if (Frames.size() == 0) {
if(Frames.size() == 0){ LOG(WARNING) << "Frames.size() == 0";
LOG(WARNING) << "Frames.size() == 0"; return;
return; }
} sort(Frames.begin(), Frames.end(),
sort(Frames.begin(), Frames.end(), [](const PointCloud::Ptr &query, const PointCloud::Ptr &target) {
[](const PointCloud::Ptr& query, const PointCloud::Ptr& target) { return query->front().timestamp < target->front().timestamp;
return query->front().timestamp < target->front().timestamp; });
}); for (const auto &frame : Frames) {
for(const auto &frame : Frames){ for (const auto &point : *frame) {
for(const auto &point : *frame){ PointExport p;
PointExport p; p.x = point.x;
p.x = point.x;p.y = point.y;p.z = point.z; p.y = point.y;
p.intensity = point.intensity;p.label = point.label; p.z = point.z;
p.rgb = point.rgb;p.info = point.ring; p.intensity = point.intensity;
export_cloud_->push_back(p); p.label = point.label;
} p.rgb = point.rgb;
} p.info = point.ring;
export_cloud_->sensor_origin_ = Frames.front()->sensor_origin_; export_cloud_->push_back(p);
export_cloud_->sensor_orientation_ = Frames.front()->sensor_orientation_; }
}
export_cloud_->sensor_origin_ = Frames.front()->sensor_origin_;
export_cloud_->sensor_orientation_ = Frames.front()->sensor_orientation_;
} }
vector<vector<TrajPoint>> MapTask::getTaskTrajectory() vector<vector<TrajPoint>> MapTask::getTaskTrajectory() {
{ return taskTrajectory_;
return taskTrajectory_;
} }
PointCloudExport::Ptr MapTask::getExportCloud() PointCloudExport::Ptr MapTask::getExportCloud() { return export_cloud_; }
{
return export_cloud_;
}
PointCloudExport::Ptr MapTask::getFilteredCloud() PointCloudExport::Ptr MapTask::getFilteredCloud() { return filtered_cloud_; }
{
return filtered_cloud_;
}
PointCloud::Ptr MapTask::getVoxeledCloud() PointCloud::Ptr MapTask::getVoxeledCloud() { return voxeled_pointcloud_; }
{
return voxeled_pointcloud_;
}
Vector3d MapTask::getLocalOffset() Vector3d MapTask::getLocalOffset() { return local_traj_center_; }
{
return local_traj_center_;
}
void MapTask::waitUntilFramesEmpty() void MapTask::waitUntilFramesEmpty() {
{ while (!frames_.empty()) {
while(!frames_.empty()){ std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::this_thread::sleep_for(std::chrono::milliseconds(10)); }
} std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
void MapTask::getRawPointCloud(const StageInfo &stageInfo) void MapTask::getRawPointCloud(const StageInfo &stageInfo) {
{ for (const auto &meshDuration : timeDurations_) {
for(const auto &meshDuration : timeDurations_){ if (!reader_) {
if(!reader_){ DevicePosition lidarPos = stageInfo.lidarPosition;
DevicePosition lidarPos = stageInfo.lidarPosition; PointCloudSource pcSource = stageInfo.pointcloudSource;
PointCloudSource pcSource = stageInfo.pointcloudSource; reader_.reset(
reader_.reset(new TaskReader(meshDuration, lidarPos, pcSource, paramsServer_)); new TaskReader(meshDuration, lidarPos, pcSource, paramsServer_));
} }
PointCloud* frame; PointCloud *frame;
uint32_t boostSize = 0; uint32_t boostSize = 0;
bool dataRemain = true; bool dataRemain = true;
while(dataRemain){ while (dataRemain) {
auto start = system_clock::now(); auto start = system_clock::now();
dataRemain = reader_->getNextFrame(frame); dataRemain = reader_->getNextFrame(frame);
auto end = system_clock::now(); auto end = system_clock::now();
auto duration = duration_cast<milliseconds>(end - start); auto duration = duration_cast<milliseconds>(end - start);
double elapse = double(duration.count()) / 1000; double elapse = double(duration.count()) / 1000;
// if(elapse > 0.1){ // if(elapse > 0.1){
// std::this_thread::sleep_for(std::chrono::milliseconds(50)); // std::this_thread::sleep_for(std::chrono::milliseconds(50));
// } // }
LOG_EVERY_N(INFO, 999) << "process take " << elapse << " seconds"; LOG_EVERY_N(INFO, 999) << "process take " << elapse << " seconds";
if(dataRemain){ if (dataRemain) {
frames_.push(frame); frames_.push(frame);
} }
// LOG(INFO) << "boostSize: " << boostSize; // LOG(INFO) << "boostSize: " << boostSize;
boostSize++; boostSize++;
if(boostSize == MAX_THREAD_CNT * 10){ if (boostSize == MAX_THREAD_CNT * 10) {
waitUntilFramesEmpty(); waitUntilFramesEmpty();
boostSize = 0; boostSize = 0;
// LOG(INFO) << "waitUntilFramesEmpty"; // LOG(INFO) << "waitUntilFramesEmpty";
} }
// if(strategyControl_->getOption().find("frame") != string::npos){ // if(strategyControl_->getOption().find("frame") !=
// if(boostSize >= 1500){ // string::npos){
// break; // if(boostSize >= 1500){
// } // break;
// } // }
} // }
reader_.reset(); }
} reader_.reset();
}
} }
void MapTask::configTraj() void MapTask::configTraj() {
{ while (!paramsServer_->getTrajectoryLoded()) {
while(!paramsServer_->getTrajectoryLoded()){ std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(100)); }
} if (taskTrajectory_.size() == 0) {
if(taskTrajectory_.size() == 0){ vector<vector<TrajPoint>> poseTraj, ppkTraj;
vector<vector<TrajPoint>> poseTraj, ppkTraj; vector<Time_Duration> durations;
vector<Time_Duration> durations;
for (const auto &durationvec : timeDurations_) {
for(const auto &durationvec : timeDurations_){ for (const auto &duration : durationvec) {
for(const auto &duration : durationvec){ durations.push_back(duration);
durations.push_back(duration); }
} }
} if (mapping_traj_) {
if(mapping_traj_){ size_t guessTrajIndex = 0;
size_t guessTrajIndex = 0; auto basePoseTraj = mapping_traj_->getDurationsTrajs(
auto basePoseTraj = mapping_traj_->getDurationsTrajs(timeDurations_.front(), guessTrajIndex); timeDurations_.front(), guessTrajIndex);
guessTrajIndex = 0; guessTrajIndex = 0;
poseTraj = mapping_traj_->getDurationsTrajs(durations, guessTrajIndex); poseTraj = mapping_traj_->getDurationsTrajs(durations, guessTrajIndex);
LOG(INFO) << "basePoseTraj: " << basePoseTraj.size() LOG(INFO) << "basePoseTraj: " << basePoseTraj.size()
<< " poseTraj: " << poseTraj.size(); << " poseTraj: " << poseTraj.size();
isMerged = basePoseTraj.size() != poseTraj.size(); isMerged = basePoseTraj.size() != poseTraj.size();
if(MERGE == strategyControl_->getTaskMode() && !isMerged){ if (MERGE == strategyControl_->getTaskMode() && !isMerged) {
return; return;
} }
mapping_mesh_.reset(new Trajectory("", NODE)); mapping_mesh_.reset(new Trajectory("", NODE));
vector<TrajPoint> meshTraj; vector<TrajPoint> meshTraj;
for(const auto &traj : poseTraj){ for (const auto &traj : poseTraj) {
if(traj.size() == 0){ if (traj.size() == 0) {
continue; continue;
} }
for(const auto &traj_point : traj){ for (const auto &traj_point : traj) {
meshTraj.push_back(traj_point); meshTraj.push_back(traj_point);
} }
} }
sort(meshTraj.begin(), meshTraj.end(), sort(meshTraj.begin(), meshTraj.end(),
[](const TrajPoint& query, const TrajPoint& target) { [](const TrajPoint &query, const TrajPoint &target) {
return query.timestamp < target.timestamp; return query.timestamp < target.timestamp;
}); });
mapping_mesh_->setTrajectory(meshTraj); mapping_mesh_->setTrajectory(meshTraj);
} }
if(undistortion_traj_){ if (undistortion_traj_) {
size_t guessTrajIndex = 0; size_t guessTrajIndex = 0;
ppkTraj = undistortion_traj_->getDurationsTrajs(durations, guessTrajIndex); ppkTraj =
auto traj_mode = strategyControl_->getTrajMode(); undistortion_traj_->getDurationsTrajs(durations, guessTrajIndex);
if(traj_mode == NODE_MODE){ auto traj_mode = strategyControl_->getTrajMode();
undisort_mesh_.reset(new Trajectory("", NODE)); if (traj_mode == NODE_MODE) {
}else{ undisort_mesh_.reset(new Trajectory("", NODE));
undisort_mesh_.reset(new Trajectory("", PPK)); } else {
} undisort_mesh_.reset(new Trajectory("", PPK));
// undisort_mesh_.reset(new Trajectory("", PPK)); }
vector<TrajPoint> meshTraj; // undisort_mesh_.reset(new Trajectory("", PPK));
for(const auto &traj : ppkTraj){ vector<TrajPoint> meshTraj;
if(traj.size() == 0){ for (const auto &traj : ppkTraj) {
continue; if (traj.size() == 0) {
} continue;
for(const auto &traj_point : traj){ }
meshTraj.push_back(traj_point); for (const auto &traj_point : traj) {
} meshTraj.push_back(traj_point);
} }
sort(meshTraj.begin(), meshTraj.end(), }
[](const TrajPoint& query, const TrajPoint& target) { sort(meshTraj.begin(), meshTraj.end(),
return query.timestamp < target.timestamp; [](const TrajPoint &query, const TrajPoint &target) {
}); return query.timestamp < target.timestamp;
undisort_mesh_->setTrajectory(meshTraj); });
} undisort_mesh_->setTrajectory(meshTraj);
if(mapping_traj_){ }
taskTrajectory_ = poseTraj; if (mapping_traj_) {
}else if(undistortion_traj_){ taskTrajectory_ = poseTraj;
taskTrajectory_ = ppkTraj; } else if (undistortion_traj_) {
} taskTrajectory_ = ppkTraj;
LOG(INFO) << "taskTrajectory_.size(): " << taskTrajectory_.size(); }
uint32_t trajpoint_cnt = 0; LOG(INFO) << "taskTrajectory_.size(): " << taskTrajectory_.size();
double dis = 0; uint32_t trajpoint_cnt = 0;
for(const auto &traj : taskTrajectory_){ double dis = 0;
if(traj.size() == 0){ for (const auto &traj : taskTrajectory_) {
continue; if (traj.size() == 0) {
} continue;
Vector3d last_trans = traj.front().translation; }
for(const auto &traj_point : traj){ Vector3d last_trans = traj.front().translation;
local_traj_center_ += traj_point.translation; for (const auto &traj_point : traj) {
dis += (traj_point.translation - last_trans).norm(); local_traj_center_ += traj_point.translation;
last_trans = traj_point.translation; dis += (traj_point.translation - last_trans).norm();
} last_trans = traj_point.translation;
trajpoint_cnt += traj.size(); }
} trajpoint_cnt += traj.size();
local_traj_center_ /= trajpoint_cnt; }
LOG(INFO) << "local_traj_center_: " << local_traj_center_.transpose(); local_traj_center_ /= trajpoint_cnt;
Vector3d local_center_from_center = local_traj_center_ + paramsServer_->getCenterToSlamStartOffset(); LOG(INFO) << "local_traj_center_: " << local_traj_center_.transpose();
Vector3d mod_006_offset = Vector3d::Zero(); Vector3d local_center_from_center =
mod_006_offset.x() = fmod(local_center_from_center.x(), 0.06); local_traj_center_ + paramsServer_->getCenterToSlamStartOffset();
mod_006_offset.y() = fmod(local_center_from_center.y(), 0.06); Vector3d mod_006_offset = Vector3d::Zero();
LOG(INFO) << "mod_006_offset: " << mod_006_offset.transpose(); mod_006_offset.x() = fmod(local_center_from_center.x(), 0.06);
local_traj_center_ -= mod_006_offset; mod_006_offset.y() = fmod(local_center_from_center.y(), 0.06);
LOG(INFO) << "mod_006_offset: " << mod_006_offset.transpose();
LOG(INFO) << "dis: " << dis; local_traj_center_ -= mod_006_offset;
LOG(INFO) << "trajpoint_cnt - taskTrajectory_.size(): " << trajpoint_cnt - taskTrajectory_.size();
avg_dis_ = dis / (trajpoint_cnt - taskTrajectory_.size()); LOG(INFO) << "dis: " << dis;
if(mapping_traj_->getTrajType() == NODE){ LOG(INFO) << "trajpoint_cnt - taskTrajectory_.size(): "
setupGridCoord(); << trajpoint_cnt - taskTrajectory_.size();
} avg_dis_ = dis / (trajpoint_cnt - taskTrajectory_.size());
} if (mapping_traj_->getTrajType() == NODE) {
setupGridCoord();
}
}
} }
void MapTask::process() void MapTask::process() {
{ PointCloud *frame;
PointCloud* frame; LOG(INFO) << "thread in threadCnt_: " << threadCnt_++;
LOG(INFO) << "thread in threadCnt_: " << threadCnt_++; size_t guessUndisortIndex = 0;
size_t guessUndisortIndex = 0; size_t guessMapIndex = 0;
size_t guessMapIndex = 0; while (!request_to_end_) {
while(!request_to_end_ ){ if (!frames_.pop(frame)) {
if(!frames_.pop(frame)){ std::this_thread::sleep_for(std::chrono::milliseconds(5));
std::this_thread::sleep_for(std::chrono::milliseconds(5)); LOG_EVERY_N(WARNING, 1000000) << "request_to_end_: " << request_to_end_;
LOG_EVERY_N(WARNING, 1000000) << "request_to_end_: " << request_to_end_; continue;
continue; }
} if (nullptr == frame || frame->size() == 0) {
if(nullptr == frame || frame->size() == 0){ continue;
continue; }
}
// if(!reader_){
// if(frames_->size() == 0){
// if(!reader_){ // tempSwitch = true;
// if(frames_->size() == 0){ // pid = std::this_thread::get_id();
// tempSwitch = true; // LOG(INFO) << "pid: " << pid;
// pid = std::this_thread::get_id(); // }
// LOG(INFO) << "pid: " << pid; // }
// } if ((stageInfo_.lidarPosition == TopLidar &&
// } paramsServer_->getL0SN() == "PA4039CA5B9839CA53") ||
if((stageInfo_.lidarPosition == TopLidar (stageInfo_.lidarPosition == BackLidar &&
&& paramsServer_->getL0SN() == "PA4039CA5B9839CA53") || paramsServer_->getL1SN() == "PA4039CA5B9839CA53")) {
(stageInfo_.lidarPosition == BackLidar PointCloud removeLine39;
&& paramsServer_->getL1SN() == "PA4039CA5B9839CA53")){ for (auto p : frame->points) {
PointCloud removeLine39; if (p.ring == 39) {
for(auto p : frame->points){ continue;
if(p.ring == 39){ }
continue; removeLine39.push_back(p);
} }
removeLine39.push_back(p); frame->swap(removeLine39);
} }
frame->swap(removeLine39); PointCloud *originFrame = nullptr;
} if (stageInfo_.hirMissmode == MISS) {
PointCloud* originFrame; originFrame = new PointCloud;
if(stageInfo_.hirMissmode == MISS){ *originFrame = *frame;
originFrame = new PointCloud; for (auto &p : *originFrame) {
*originFrame = *frame; p.x = 0;
for(auto &p : *originFrame){ p.y = 0;
p.x = 0;p.y = 0;p.z = 0; p.z = 0;
} }
} }
buildMappedFrame(frame, stageInfo_, guessUndisortIndex, guessMapIndex); buildMappedFrame(frame, stageInfo_, guessUndisortIndex, guessMapIndex);
if(0 == frame->size()){ if (0 == frame->size()) {
continue; continue;
} }
if(strategyControl_->getOption().size() != 0){ if (strategyControl_->getOption().size() != 0) {
continue; continue;
} }
if(stageInfo_.hirMissmode == HIT){ if (stageInfo_.hirMissmode == HIT) {
uint8_t type = 0; uint8_t type = 0;
if(stageInfo_.pointcloudSource == BAG){ if (stageInfo_.pointcloudSource == BAG) {
type = 1; type = 1;
} }
conductHits(*frame, stage_, type); conductHits(*frame, stage_, type);
}else if(stageInfo_.hirMissmode == MISS){ } else if (stageInfo_.hirMissmode == MISS) {
buildMappedFrame(originFrame, stageInfo_, guessUndisortIndex, guessMapIndex); if (nullptr != originFrame) {
buildMappedFrame(originFrame, stageInfo_, guessUndisortIndex,
conductMisses(frame, originFrame); guessMapIndex);
delete originFrame; conductMisses(frame, originFrame);
} delete originFrame;
// tempSwitch = false; }
}
delete frame; // tempSwitch = false;
}
LOG(INFO) << "thread quit threadCnt_: " << threadCnt_--; delete frame;
}
LOG(INFO) << "thread quit threadCnt_: " << threadCnt_--;
} }
void MapTask::establishProcessTrds(vector<ThreadPtr> &trdVec, uint32_t trdCnt) void MapTask::establishProcessTrds(vector<ThreadPtr> &trdVec, uint32_t trdCnt) {
{ for (size_t i = 0; i < trdCnt; i++) {
for(size_t i = 0; i < trdCnt; i++){ ThreadPtr trd;
ThreadPtr trd; trd.reset(new boost::thread(boost::bind(&MapTask::process, this)));
trd.reset(new boost::thread(boost::bind(&MapTask::process, this))); trdVec.push_back(trd);
trdVec.push_back(trd); }
}
} }
void MapTask::joinProcessTrds(vector<ThreadPtr> &trdVec) void MapTask::joinProcessTrds(vector<ThreadPtr> &trdVec) {
{ request_to_end_ = true;
request_to_end_ = true; // for(size_t i = 0; i < trdVec.size(); i++){
// for(size_t i = 0; i < trdVec.size(); i++){ // frames_->stopQueue();
// frames_->stopQueue(); // usleep(10000);
// usleep(10000); // }
// } // LOG(INFO) << "stopQueue";
// LOG(INFO) << "stopQueue";
for (auto &trd : trdVec) {
for(auto &trd : trdVec){ trd->timed_join(boost::posix_time::seconds(5));
trd->timed_join(boost::posix_time::seconds(1)); }
}
} }
Matrix4d MapTask::configCalib(const StageInfo &stageInfo, const uint8_t &type) Matrix4d MapTask::configCalib(const StageInfo &stageInfo, const uint8_t &type) {
{ if (type == 1) {
if(type == 1){ return paramsServer_->getDeviceCalib(stageInfo.lidarPosition);
return paramsServer_->getDeviceCalib(stageInfo.lidarPosition); } else if (type == 2) {
}else if(type == 2){ return paramsServer_->getDeviceCalib(IMU);
return paramsServer_->getDeviceCalib(IMU); } else if (type == 3) {
}else if(type == 3){ return paramsServer_->getCalib(stageInfo.lidarPosition);
return paramsServer_->getCalib(stageInfo.lidarPosition); }
} return Matrix4d::Identity();
return Matrix4d::Identity();
} }
void MapTask::conductCalib(PointCloud* &Frame) void MapTask::conductCalib(PointCloud *&Frame) { conductCalib(Frame, calib_); }
{
conductCalib(Frame, calib_);
}
void MapTask::conductCalib(PointCloud* &Frame, const Matrix4d &calib) void MapTask::conductCalib(PointCloud *&Frame, const Matrix4d &calib) {
{ pcl::transformPointCloud(*Frame, *Frame, calib);
pcl::transformPointCloud(*Frame, *Frame, calib);
} }
bool checkTimeStamp(const double &time, bool checkTimeStamp(const double &time, const double &time_1,
const double &time_1, const double &time_2) {
const double &time_2){ if (time >= time_1 && time < time_2) {
if(time >= time_1 && time < time_2){ return true;
return true; } else {
}else{ return false;
return false; }
}
} }
void MapTask::conductMappingByPoint(PointCloud* &Frame, size_t &guessTrajIndex) void MapTask::conductMappingByPoint(PointCloud *&Frame,
{ size_t &guessTrajIndex) {
if(0 == Frame->size()){ if (0 == Frame->size()) {
return; return;
} }
double time_1 = 0, time_2 = 0; double time_1 = 0, time_2 = 0;
bool frame_sensor_odom_set = false; bool frame_sensor_odom_set = false;
PointCloud locatedFrame; PointCloud locatedFrame;
Time_Duration duration; Time_Duration duration;
double timeBuffer = 0.05; double timeBuffer = 0.05;
if(NODE_MODE == strategyControl_->getTrajMode()){ if (NODE_MODE == strategyControl_->getTrajMode()) {
timeBuffer = 1; timeBuffer = 1;
} }
duration.start_sec = Frame->front().timestamp - timeBuffer; duration.start_sec = Frame->front().timestamp - timeBuffer;
duration.end_sec = Frame->back().timestamp + timeBuffer; duration.end_sec = Frame->back().timestamp + timeBuffer;
vector<TrajPoint> trajInFrame = undisort_mesh_->getDurationsTraj(duration, guessTrajIndex); vector<TrajPoint> trajInFrame =
if(trajInFrame.size() < 2){ undisort_mesh_->getDurationsTraj(duration, guessTrajIndex);
LOG_EVERY_N(WARNING, 99) << setprecision(15) << "trajInFrame.size() < 2: " << Frame->front().timestamp; if (trajInFrame.size() < 2) {
Frame->clear(); LOG_EVERY_N(WARNING, 99)
return; << setprecision(15)
<< "trajInFrame.size() < 2: " << Frame->front().timestamp;
Frame->clear();
return;
}
uint32_t lastTrajIndex = 0;
TrajPoint currTraj, nextTraj;
for (const auto &point : *Frame) {
double curr_point_timestamp = point.timestamp;
Point transformed_point = point;
bool found = false;
if (!checkTimeStamp(curr_point_timestamp, time_1, time_2)) {
for (uint32_t i = lastTrajIndex; i < trajInFrame.size() - 1; i++) {
currTraj = trajInFrame.at(i);
nextTraj = trajInFrame.at(i + 1);
if (checkTimeStamp(curr_point_timestamp, currTraj.timestamp,
nextTraj.timestamp)) {
time_1 = currTraj.timestamp;
time_2 = nextTraj.timestamp;
found = true;
break;
}
}
if (!found) {
continue;
}
} }
uint32_t lastTrajIndex = 0;
TrajPoint currTraj, nextTraj;
for(const auto &point : *Frame){
double curr_point_timestamp = point.timestamp;
Point transformed_point = point;
bool found = false;
if(!checkTimeStamp(curr_point_timestamp, time_1, time_2)){
for(uint32_t i = lastTrajIndex; i < trajInFrame.size() - 1; i++){
currTraj = trajInFrame.at(i);
nextTraj = trajInFrame.at(i + 1);
if(checkTimeStamp(curr_point_timestamp, currTraj.timestamp, nextTraj.timestamp)){
time_1 = currTraj.timestamp;
time_2 = nextTraj.timestamp;
found = true;
break;
}
}
if(!found){
continue;
}
}
TrajPoint interpolated_traj;
double radio = (curr_point_timestamp - currTraj.timestamp) / (nextTraj.timestamp - currTraj.timestamp);
interpolated_traj = currTraj;
interpolated_traj.translation = currTraj.translation + radio * (nextTraj.translation - currTraj.translation);
interpolated_traj.rotation = currTraj.rotation.slerp(radio, nextTraj.rotation);
interpolated_traj.timestamp = curr_point_timestamp;
// LOG_EVERY_N(INFO, 999) << "interpolated_traj.translation.transpose(): " << interpolated_traj.translation.transpose();
if(!frame_sensor_odom_set){
TrajPoint interpolated_traj;
locatedFrame.sensor_origin_ = {interpolated_traj.translation.x(), double radio = (curr_point_timestamp - currTraj.timestamp) /
interpolated_traj.translation.y(), (nextTraj.timestamp - currTraj.timestamp);
interpolated_traj.translation.z(), interpolated_traj = currTraj;
0}; interpolated_traj.translation =
locatedFrame.sensor_orientation_ = interpolated_traj.rotation.cast<float>(); currTraj.translation +
frame_sensor_odom_set = true; radio * (nextTraj.translation - currTraj.translation);
} interpolated_traj.rotation =
Vector3d point_vec(point.x, point.y, point.z); currTraj.rotation.slerp(radio, nextTraj.rotation);
interpolated_traj.timestamp = curr_point_timestamp;
Vector3d transformed_vec = interpolated_traj.rotation * point_vec + interpolated_traj.translation; // LOG_EVERY_N(INFO, 999) <<
transformed_point.x = transformed_vec.x(); // "interpolated_traj.translation.transpose(): " <<
transformed_point.y = transformed_vec.y(); // interpolated_traj.translation.transpose();
transformed_point.z = transformed_vec.z();
locatedFrame.push_back(transformed_point); if (!frame_sensor_odom_set) {
locatedFrame.sensor_origin_ = {interpolated_traj.translation.x(),
} interpolated_traj.translation.y(),
Frame->swap(locatedFrame); interpolated_traj.translation.z(), 0};
locatedFrame.sensor_orientation_ =
interpolated_traj.rotation.cast<float>();
frame_sensor_odom_set = true;
}
Vector3d point_vec(point.x, point.y, point.z);
Vector3d transformed_vec =
interpolated_traj.rotation * point_vec + interpolated_traj.translation;
transformed_point.x = transformed_vec.x();
transformed_point.y = transformed_vec.y();
transformed_point.z = transformed_vec.z();
locatedFrame.push_back(transformed_point);
}
Frame->swap(locatedFrame);
} }
void MapTask::conductInverse(PointCloud* &Frame) void MapTask::conductInverse(PointCloud *&Frame) {
{ auto sensor_t = Frame->sensor_origin_;
auto sensor_t = Frame->sensor_origin_; Matrix3f sensor_r = Matrix3f(Frame->sensor_orientation_);
Matrix3f sensor_r = Matrix3f(Frame->sensor_orientation_); Matrix4f frame_T;
Matrix4f frame_T; frame_T.block(0, 0, 3, 3) = sensor_r.inverse();
frame_T.block(0, 0, 3, 3) = sensor_r.inverse(); frame_T.block(0, 3, 3, 1) =
frame_T.block(0, 3, 3, 1) = sensor_r.inverse() * Vector3f(-sensor_t.x(), -sensor_t.y(), -sensor_t.z()); sensor_r.inverse() *
pcl::transformPointCloud(*Frame, *Frame, frame_T); Vector3f(-sensor_t.x(), -sensor_t.y(), -sensor_t.z());
pcl::transformPointCloud(*Frame, *Frame, frame_T);
} }
void MapTask::conductMapping(PointCloud* &Frame, size_t &guessTrajIndex) void MapTask::conductMapping(PointCloud *&Frame, size_t &guessTrajIndex) {
{ if (Frame->size() == 0) {
if(Frame->size() == 0){ return;
return; }
}
PointCloud dummy_frame = *Frame;
PointCloud dummy_frame = *Frame; Frame->clear();
Frame->clear();
double curr_frame_timestamp = dummy_frame.front().timestamp;
double curr_frame_timestamp = dummy_frame.front().timestamp; bool isSkip;
bool isSkip; if (!mapping_mesh_->findFloorTrajPoint(curr_frame_timestamp, guessTrajIndex,
if(!mapping_mesh_->findFloorTrajPoint(curr_frame_timestamp, guessTrajIndex, isSkip)){ isSkip)) {
return; return;
} }
if(isSkip){ if (isSkip) {
return; return;
} }
TrajPoint local_traj; TrajPoint local_traj;
Isometry3d frameTransform; Isometry3d frameTransform;
TrajPoint interpolated_traj; TrajPoint interpolated_traj;
if(!mapping_mesh_->interpolation(curr_frame_timestamp, guessTrajIndex, interpolated_traj)){ if (!mapping_mesh_->interpolation(curr_frame_timestamp, guessTrajIndex,
LOG_EVERY_N(WARNING, 99) << "interpolation fail"; interpolated_traj)) {
return; LOG_EVERY_N(WARNING, 99) << "interpolation fail";
} return;
local_traj = interpolated_traj; }
Matrix4d interpolated_node = Trajectory::getTransformFromTrajPoint(local_traj); local_traj = interpolated_traj;
Matrix4d interpolated_node =
frameTransform.translation() = interpolated_node.block(0, 3, 3, 1); Trajectory::getTransformFromTrajPoint(local_traj);
frameTransform.linear() = interpolated_node.block(0, 0, 3, 3);
frameTransform.translation() = interpolated_node.block(0, 3, 3, 1);
frameTransform.translation() -= local_traj_center_; frameTransform.linear() = interpolated_node.block(0, 0, 3, 3);
Matrix4d frameMatrix;
frameMatrix.block(0, 3, 3, 1) = frameTransform.translation(); frameTransform.translation() -= local_traj_center_;
frameMatrix.block(0, 0, 3, 3) = frameTransform.linear(); Matrix4d frameMatrix;
pcl::transformPointCloud(dummy_frame, dummy_frame, frameMatrix); frameMatrix.block(0, 3, 3, 1) = frameTransform.translation();
frameMatrix.block(0, 0, 3, 3) = frameTransform.linear();
local_traj.translation = frameTransform.translation(); pcl::transformPointCloud(dummy_frame, dummy_frame, frameMatrix);
StageInfo stageInfo = strategyControl_->getStageInfos()[stage_];
if(stageInfo.hirMissmode == HIT && mapping_mesh_->getTrajType() == NODE local_traj.translation = frameTransform.translation();
&& strategyControl_->getFilterMode() != DIRECT_OUTPUT_MODE){ StageInfo stageInfo = strategyControl_->getStageInfos()[stage_];
PointCloud dynamicAccepted_frame; if (stageInfo.hirMissmode == HIT && mapping_mesh_->getTrajType() == NODE &&
for(auto &point : dummy_frame){ strategyControl_->getFilterMode() != DIRECT_OUTPUT_MODE) {
double distance = point.distance; PointCloud dynamicAccepted_frame;
int res = dynamicRemover_->grid_coord_->isDynamicallyAccepted( for (auto &point : dummy_frame) {
point.x, point.y, distance, local_traj); double distance = point.distance;
int res = dynamicRemover_->grid_coord_->isDynamicallyAccepted(
if(res >= 0) { point.x, point.y, distance, local_traj);
// point.ring = res;
dynamicAccepted_frame.push_back(point); if (res >= 0) {
} // point.ring = res;
} dynamicAccepted_frame.push_back(point);
dummy_frame.swap(dynamicAccepted_frame); }
} }
// double traj_dis = 0; dummy_frame.swap(dynamicAccepted_frame);
// if(traj_index > 0){ }
// TrajPoint traj_upper = mapping_traj_->getTrajPointByIndex(traj_index + 1); // double traj_dis = 0;
// if(traj_upper.translation.x() != 0){ // if(traj_index > 0){
// traj_dis = (traj_at_index.translation - traj_upper.translation).norm(); // TrajPoint traj_upper = mapping_traj_->getTrajPointByIndex(traj_index
// } // + 1); if(traj_upper.translation.x() != 0){
// } // traj_dis = (traj_at_index.translation -
Frame->swap(dummy_frame); // traj_upper.translation).norm();
Frame->sensor_origin_ = {local_traj.translation.x(), // }
local_traj.translation.y(), // }
local_traj.translation.z(), Frame->swap(dummy_frame);
0}; Frame->sensor_origin_ = {local_traj.translation.x(),
Frame->sensor_orientation_ = Matrix3f(frameTransform.linear().cast<float>()); local_traj.translation.y(),
local_traj.translation.z(), 0};
Frame->sensor_orientation_ = Matrix3f(frameTransform.linear().cast<float>());
} }
void MapTask::conductHits( void MapTask::conductHits(const PointCloud &Frame, uint8_t stage,
const PointCloud &Frame, uint8_t stage, uint8_t type) uint8_t type) {
{ // double radio = Frame->sensor_origin_[3] / avg_dis_;
// double radio = Frame->sensor_origin_[3] / avg_dis_; dynamicRemover_->calculateHits(Frame, stage, type);
dynamicRemover_->calculateHits(Frame, stage, type);
} }
void MapTask::conductMisses(const PointCloud *mappedFrame, void MapTask::conductMisses(const PointCloud *mappedFrame,
const PointCloud *mappedOriginFrame) const PointCloud *mappedOriginFrame) {
{ // double radio = mappedFrame->sensor_origin_[3] / avg_dis_;
// double radio = mappedFrame->sensor_origin_[3] / avg_dis_; dynamicRemover_->calculateMisses(mappedFrame, mappedOriginFrame, 1);
dynamicRemover_->calculateMisses(mappedFrame, mappedOriginFrame, 1);
} }
void MapTask::setupGridCoord() void MapTask::setupGridCoord() {
{ auto localTrajactory = taskTrajectory_;
auto localTrajactory = taskTrajectory_; for (auto &traj : localTrajactory) {
for(auto &traj : localTrajactory){ for (auto &traj_point : traj) {
for(auto &traj_point : traj){ traj_point.translation -= local_traj_center_;
traj_point.translation -= local_traj_center_;
}
} }
}
string path = "/tmp/localTrajactory.txt"; string path = "/tmp/localTrajactory.txt";
std::ofstream ofs(path); std::ofstream ofs(path);
if(!ofs){ if (!ofs) {
LOG(WARNING) << path << " load fail!"; LOG(WARNING) << path << " load fail!";
} }
for(auto& trajectory : localTrajactory){ for (auto &trajectory : localTrajactory) {
for(auto& pt : trajectory){ for (auto &pt : trajectory) {
ofs << setprecision(15) << pt.translation[0] << " " << pt.translation[1] << " " ofs << setprecision(15) << pt.translation[0] << " " << pt.translation[1]
<< pt.translation[2] << " " << pt.nodeId << endl; << " " << pt.translation[2] << " " << pt.nodeId << endl;
}
} }
ofs.close(); }
ofs.close();
for(auto &traj : localTrajactory){ for (auto &traj : localTrajactory) {
for(auto &traj_point : traj){ for (auto &traj_point : traj) {
dynamicRemover_->grid_coord_->updateArea(traj_point); dynamicRemover_->grid_coord_->updateArea(traj_point);
}
} }
}
dynamicRemover_->grid_coord_->peakTrajDrationAround(); dynamicRemover_->grid_coord_->peakTrajDrationAround();
// dynamicRemover_->grid_coord_->printGrid(); // dynamicRemover_->grid_coord_->printGrid();
LOG(INFO) << "setupGridCoord done!"; LOG(INFO) << "setupGridCoord done!";
} }
...@@ -7,444 +7,436 @@ uint16_t MIN_NODE_LINE_ITEM_CNT = 10; ...@@ -7,444 +7,436 @@ uint16_t MIN_NODE_LINE_ITEM_CNT = 10;
float SquaredMinDis = pow(15, 2); float SquaredMinDis = pow(15, 2);
Trajectory::Trajectory(const string &traj_path, const TrajType &trajType) Trajectory::Trajectory(const string &traj_path, const TrajType &trajType)
:trajectory_path_(traj_path), : trajectory_path_(traj_path), trajType_(trajType) {
trajType_(trajType) switch (trajType_) {
{
switch(trajType_){
case PPK: case PPK:
frequency_ = 1000; frequency_ = 1000;
break; break;
case NODE: case NODE:
frequency_ = 10; frequency_ = 10;
break; break;
} }
} }
Trajectory::~Trajectory() Trajectory::~Trajectory() {}
{
}
bool Trajectory::init() bool Trajectory::init() {
{ string range;
string range; switch (trajType_) {
switch(trajType_){
case PPK: case PPK:
range = ","; range = ",";
break; break;
case NODE: case NODE:
range = " "; range = " ";
break; break;
} }
LOG(INFO) << "Trajectory set frequency: " << frequency_; LOG(INFO) << "Trajectory set frequency: " << frequency_;
io_.reset(new TextIO(trajectory_path_, range)); io_.reset(new TextIO(trajectory_path_, range));
boost::function<void(const vector<string>&)> parse_callback = boost::function<void(const vector<string> &)> parse_callback =
boost::bind(&Trajectory::parseAndPush, this, _1); boost::bind(&Trajectory::parseAndPush, this, _1);
io_->setParseCallback(parse_callback); io_->setParseCallback(parse_callback);
if(!io_){ if (!io_) {
LOG(WARNING) << "io_ is nullptr!"; LOG(WARNING) << "io_ is nullptr!";
return false; return false;
} }
if(!io_->load()){ if (!io_->load()) {
LOG(WARNING) << "io_ load fail!"; LOG(WARNING) << "io_ load fail!";
return false;
}
if (taskTrajInfo_.size()) {
setupBaseTrajOctree();
onRelativeTraj_ = true;
for (auto iter = taskTrajInfo_.begin(); iter != taskTrajInfo_.end();
iter++) {
const string &taskTrajPath = iter->first;
taskTrajPoseDiff_ = iter->second;
auto ppk_dir = taskTrajPath + "/raw_trace/ie.txt";
auto pose_dir = taskTrajPath + "/slam/cartographer.bag.pbstream.pose";
if (PPK == trajType_) {
io_.reset(new TextIO(ppk_dir, range));
} else if (NODE == trajType_) {
io_.reset(new TextIO(pose_dir, range));
} else {
return false; return false;
}
boost::function<void(const vector<string> &)> parse_callback =
boost::bind(&Trajectory::parseAndPush, this, _1);
io_->setParseCallback(parse_callback);
io_->load();
LOG(INFO) << "relative traj " << taskTrajPath << " done";
} }
}
if(taskTrajInfo_.size()){
setupBaseTrajOctree(); sort(trajectory_.begin(), trajectory_.end(),
onRelativeTraj_ = true; [](const TrajPoint &query, const TrajPoint &target) {
for(auto iter = taskTrajInfo_.begin(); return query.timestamp < target.timestamp;
iter != taskTrajInfo_.end(); iter++){ });
const string &taskTrajPath = iter->first;
taskTrajPoseDiff_ = iter->second; LOG(INFO) << "trajectory_ size: " << trajectory_.size();
auto ppk_dir = taskTrajPath + "/raw_trace/ie.txt"; if (NODE == trajType_) {
auto pose_dir = taskTrajPath + "/slam/cartographer.bag.pbstream.pose"; fullTraj_ = trajectory_;
if(PPK == trajType_){ Vector3d lastTranslation;
io_.reset(new TextIO(ppk_dir, range)); int cnt = 0;
}else if(NODE == trajType_){ for (auto iter = trajectory_.begin(); iter != trajectory_.end();) {
io_.reset(new TextIO(pose_dir, range)); if (0 != cnt && (lastTranslation - iter->translation).norm() < 0.39) {
}else{ iter = trajectory_.erase(iter);
return false; } else {
} lastTranslation = iter->translation;
boost::function<void(const vector<string>&)> parse_callback = iter++;
boost::bind(&Trajectory::parseAndPush, this, _1); }
io_->setParseCallback(parse_callback); cnt++;
io_->load();
LOG(INFO) << "relative traj " << taskTrajPath << " done";
}
} }
}
sort(trajectory_.begin(), trajectory_.end(), LOG(INFO) << "after filter trajectory_ size: " << trajectory_.size();
[](const TrajPoint& query, const TrajPoint& target) { return true;
return query.timestamp < target.timestamp;
});
LOG(INFO) << "trajectory_ size: " << trajectory_.size();
if(NODE == trajType_){
fullTraj_ = trajectory_;
Vector3d lastTranslation;
int cnt = 0;
for(auto iter = trajectory_.begin(); iter != trajectory_.end();){
if(0 != cnt && (lastTranslation - iter->translation).norm() < 0.39){
iter = trajectory_.erase(iter);
}else{
lastTranslation = iter->translation;
iter++;
}
cnt++;
}
}
LOG(INFO) << "after filter trajectory_ size: " << trajectory_.size();
return true;
} }
string Trajectory::getTrajPath() const string Trajectory::getTrajPath() const { return trajectory_path_; }
{
return trajectory_path_;
}
TrajType Trajectory::getTrajType() const TrajType Trajectory::getTrajType() const { return trajType_; }
{
return trajType_;
}
bool Trajectory::findFloorTrajPoint(const double &timestamp, size_t &guessTrajIndex, bool& isSkip) const bool Trajectory::findFloorTrajPoint(const double &timestamp,
{ size_t &guessTrajIndex,
isSkip = false; bool &isSkip) const {
if(trajectory_.size() < 2){ isSkip = false;
return false; if (trajectory_.size() < 2) {
} return false;
if(trajectory_.front().timestamp > timestamp){ }
return false; if (trajectory_.front().timestamp > timestamp) {
return false;
}
for (; guessTrajIndex < trajectory_.size() - 1; guessTrajIndex++) {
if (trajectory_.at(guessTrajIndex).timestamp > timestamp) {
guessTrajIndex = 0;
return findFloorTrajPoint(timestamp, guessTrajIndex, isSkip);
} }
for(; guessTrajIndex < trajectory_.size() - 1; guessTrajIndex++){ auto pre = trajectory_.at(guessTrajIndex);
if(trajectory_.at(guessTrajIndex).timestamp > timestamp){ auto pro = trajectory_.at(guessTrajIndex + 1);
guessTrajIndex = 0;
return findFloorTrajPoint(timestamp, guessTrajIndex, isSkip); if (pre.timestamp <= timestamp && pro.timestamp > timestamp) {
} if ((pro.timestamp - pre.timestamp) * frequency_ > 20) {
auto pre = trajectory_.at(guessTrajIndex); isSkip = true;
auto pro = trajectory_.at(guessTrajIndex + 1); }
// LOG_EVERY_N(INFO, 9) << setprecision(15)
if(pre.timestamp <= timestamp && pro.timestamp > timestamp){ // << "hit!!!! timestamp: " << timestamp
if((pro.timestamp - pre.timestamp) * frequency_ > 20){ // << " pre: " << pre.timestamp
isSkip = true; // << " pro: " << pro.timestamp
} // << " guessTrajIndex: " <<
// LOG_EVERY_N(INFO, 9) << setprecision(15) // guessTrajIndex;
// << "hit!!!! timestamp: " << timestamp return true;
// << " pre: " << pre.timestamp
// << " pro: " << pro.timestamp
// << " guessTrajIndex: " << guessTrajIndex;
return true;
}
} }
return false; }
return false;
} }
int32_t Trajectory::traversalFindTrajPoint(const uint32_t &start_index, int32_t Trajectory::traversalFindTrajPoint(const uint32_t &start_index,
const uint32_t &end_index, const uint32_t &end_index,
const double &timestamp) const const double &timestamp) const {
{ for (uint32_t index = start_index; index < end_index; index++) {
for(uint32_t index = start_index; index < end_index; index++){ if (checkSatisfied(index, timestamp)) {
if(checkSatisfied(index, timestamp)){ return index;
return index;
}
} }
return -1; }
return -1;
} }
bool Trajectory::interpolation(const double &timestamp, bool Trajectory::interpolation(const double &timestamp,
const int32_t &floor_index, const int32_t &floor_index,
TrajPoint &res_traj) const TrajPoint &res_traj) const {
{ int32_t upper_index = floor_index + 1;
int32_t upper_index = floor_index + 1; if ((uint32_t)upper_index >= trajectory_.size()) {
if((uint32_t)upper_index >= trajectory_.size()){ LOG_EVERY_N(WARNING, 99) << "upper_index: " << upper_index
LOG_EVERY_N(WARNING, 99) << "upper_index: " << upper_index << "trajectory_.size(): " << trajectory_.size();
<< "trajectory_.size(): " << trajectory_.size(); return false;
return false; }
}
const TrajPoint &traj_floor = trajectory_[floor_index];
const TrajPoint &traj_floor = trajectory_[floor_index]; const TrajPoint &traj_upper = trajectory_[upper_index];
const TrajPoint &traj_upper = trajectory_[upper_index];
double radio = (timestamp - traj_floor.timestamp) /
double radio = (timestamp - traj_floor.timestamp) / (traj_upper.timestamp - traj_floor.timestamp); (traj_upper.timestamp - traj_floor.timestamp);
res_traj = traj_floor; res_traj = traj_floor;
res_traj.translation = traj_floor.translation + radio * (traj_upper.translation - traj_floor.translation); res_traj.translation =
res_traj.rotation = traj_floor.rotation.slerp(radio, traj_upper.rotation); traj_floor.translation +
res_traj.timestamp = timestamp; radio * (traj_upper.translation - traj_floor.translation);
return true; res_traj.rotation = traj_floor.rotation.slerp(radio, traj_upper.rotation);
res_traj.timestamp = timestamp;
return true;
} }
Matrix4d Trajectory::getTransformFromTrajPoint(const TrajPoint &trajPoint) Matrix4d Trajectory::getTransformFromTrajPoint(const TrajPoint &trajPoint) {
{ Matrix4d T;
Matrix4d T; T.block(0, 0, 3, 3) = trajPoint.rotation.toRotationMatrix();
T.block(0, 0, 3, 3) = trajPoint.rotation.toRotationMatrix(); T.block(0, 3, 3, 1) = trajPoint.translation;
T.block(0, 3, 3, 1) = trajPoint.translation; return T;
return T;
} }
vector<vector<TrajPoint>> Trajectory::getDurationsTrajs( vector<vector<TrajPoint>> Trajectory::getDurationsTrajs(
const vector<Time_Duration> &durations, size_t &guessTrajIndex) const const vector<Time_Duration> &durations, size_t &guessTrajIndex) const {
{ vector<vector<TrajPoint>> ret;
vector<vector<TrajPoint>> ret; for (const auto &duration : durations) {
for(const auto &duration : durations){ vector<TrajPoint> durationsTrajs;
vector<TrajPoint> durationsTrajs;
bool isSkip;
if(!findFloorTrajPoint(duration.start_sec, guessTrajIndex, isSkip)){
LOG(INFO) << setprecision(15) << "findFloorTrajPoint fail:"
"duration.start_sec: " << duration.start_sec
<< " guessTrajIndex: " << guessTrajIndex;
guessTrajIndex = 0;
}
int32_t traj_index = guessTrajIndex;
for(uint32_t index = traj_index; index < trajectory_.size(); index++){
auto &traj = trajectory_.at(index);
if(traj.timestamp < duration.start_sec){
continue;
}else if(traj.timestamp <= duration.end_sec){
durationsTrajs.push_back(traj);
}else{
break;
}
}
if(durationsTrajs.size() > 1){
ret.push_back(durationsTrajs);
}
}
return ret;
}
vector<TrajPoint> Trajectory::getDurationsTraj(
const Time_Duration &duration, size_t &guessTrajIndex) const
{
vector<TrajPoint> ret;
bool isSkip; bool isSkip;
int32_t traj_index = findFloorTrajPoint(duration.start_sec, guessTrajIndex, isSkip); if (!findFloorTrajPoint(duration.start_sec, guessTrajIndex, isSkip)) {
if(isSkip) return ret; LOG(INFO) << setprecision(15)
if(traj_index < 0){ << "findFloorTrajPoint fail:"
LOG(INFO) << setprecision(15) "duration.start_sec: "
<< "getDurationsTrajs findFloorTrajPoint fail, error code = " << traj_index << duration.start_sec << " guessTrajIndex: " << guessTrajIndex;
<< " duration.start_sec: " << duration.start_sec; guessTrajIndex = 0;
traj_index = 0;
} }
for(uint32_t index = traj_index; index < trajectory_.size(); index++){ int32_t traj_index = guessTrajIndex;
auto &traj = trajectory_.at(index); for (uint32_t index = traj_index; index < trajectory_.size(); index++) {
if(traj.timestamp < duration.start_sec){ auto &traj = trajectory_.at(index);
continue; if (traj.timestamp < duration.start_sec) {
}else if(traj.timestamp <= duration.end_sec){ continue;
ret.push_back(traj); } else if (traj.timestamp <= duration.end_sec) {
}else{ durationsTrajs.push_back(traj);
break; } else {
} break;
}
} }
return ret; if (durationsTrajs.size() > 1) {
ret.push_back(durationsTrajs);
}
}
return ret;
} }
TrajPoint Trajectory::getTrajPointByIndex(const uint32_t &index) const vector<TrajPoint> Trajectory::getDurationsTraj(const Time_Duration &duration,
{ size_t &guessTrajIndex) const {
if(index < trajectory_.size()){ vector<TrajPoint> ret;
return trajectory_.at(index); bool isSkip;
}else{ int32_t traj_index =
return TrajPoint(); findFloorTrajPoint(duration.start_sec, guessTrajIndex, isSkip);
if (isSkip) return ret;
if (traj_index < 0) {
LOG(INFO) << setprecision(15)
<< "getDurationsTrajs findFloorTrajPoint fail, error code = "
<< traj_index << " duration.start_sec: " << duration.start_sec;
traj_index = 0;
}
for (uint32_t index = traj_index; index < trajectory_.size(); index++) {
auto &traj = trajectory_.at(index);
if (traj.timestamp < duration.start_sec) {
continue;
} else if (traj.timestamp <= duration.end_sec) {
ret.push_back(traj);
} else {
break;
} }
}
return ret;
} }
TrajPoint Trajectory::getTrajPointByNodeId(const uint32_t &nodeId) const TrajPoint Trajectory::getTrajPointByIndex(const uint32_t &index) const {
{ if (index < trajectory_.size()) {
for(const TrajPoint &point : fullTraj_){ return trajectory_.at(index);
if(point.nodeId == nodeId){ } else {
return point;
}
}
return TrajPoint(); return TrajPoint();
}
} }
vector<TrajPoint> Trajectory::getTrajectory() const TrajPoint Trajectory::getTrajPointByNodeId(const uint32_t &nodeId) const {
{ for (const TrajPoint &point : fullTraj_) {
return trajectory_; if (point.nodeId == nodeId) {
return point;
}
}
return TrajPoint();
} }
boost::shared_ptr<LocalCartesian> Trajectory::getProj() const vector<TrajPoint> Trajectory::getTrajectory() const { return trajectory_; }
{
return proj_;
}
void Trajectory::insertRelativeTaskInfo( boost::shared_ptr<LocalCartesian> Trajectory::getProj() const { return proj_; }
const string &trajPath, const Isometry3d &taskPoseDiff)
{ void Trajectory::insertRelativeTaskInfo(const string &trajPath,
taskTrajInfo_.insert(make_pair(trajPath, taskPoseDiff)); const Isometry3d &taskPoseDiff) {
taskTrajInfo_.insert(make_pair(trajPath, taskPoseDiff));
} }
bool Trajectory::checkSatisfied(const int32_t &supposed_floor_index, const double &timestamp) const bool Trajectory::checkSatisfied(const int32_t &supposed_floor_index,
{ const double &timestamp) const {
if(supposed_floor_index < 0){ if (supposed_floor_index < 0) {
return false; return false;
} }
if((uint32_t)supposed_floor_index >= trajectory_.size() - 2){ if ((uint32_t)supposed_floor_index >= trajectory_.size() - 2) {
return false; return false;
} }
auto currTime = trajectory_[supposed_floor_index].timestamp; auto currTime = trajectory_[supposed_floor_index].timestamp;
auto nextTime = trajectory_[supposed_floor_index + 1].timestamp; auto nextTime = trajectory_[supposed_floor_index + 1].timestamp;
if(currTime <= timestamp && nextTime >= timestamp && if (currTime <= timestamp && nextTime >= timestamp &&
(nextTime - currTime) * frequency_ < 3){ (nextTime - currTime) * frequency_ < 3) {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
double gpsToUtc(const uint32_t &gps_week, const double &gps_sec) { double gpsToUtc(const uint32_t &gps_week, const double &gps_sec) {
return (315936000 + gps_week*7*24*3600 + gps_sec - 18); return (315936000 + gps_week * 7 * 24 * 3600 + gps_sec - 18);
} }
void Trajectory::parseAndPush(const vector<string> &vec) void Trajectory::parseAndPush(const vector<string> &vec) {
{ switch (trajType_) {
switch(trajType_){ case PPK: {
case PPK: if (vec.size() < MIN_PPK_LINE_ITEM_CNT) {
{ LOG_EVERY_N(WARNING, 99999)
if(vec.size() < MIN_PPK_LINE_ITEM_CNT){ << io_->getPath() << " line item size < " << MIN_PPK_LINE_ITEM_CNT;
LOG_EVERY_N(WARNING, 99999) return;
<< io_->getPath() << " line item size < " << MIN_PPK_LINE_ITEM_CNT; }
return; PPK_Raw_Info ppk_raw_info;
ppk_raw_info.gps_week = stoi(vec[1]);
ppk_raw_info.gps_sec = stod(vec[2]);
ppk_raw_info.lat = stod(vec[3]);
ppk_raw_info.lng = stod(vec[4]);
ppk_raw_info.height = stod(vec[5]);
ppk_raw_info.roll = stod(vec[9]);
ppk_raw_info.pitch = stod(vec[10]);
ppk_raw_info.yaw =
-stod(vec[11]); // ppk yaw take minus!!!!!!!!!!!!!!!!!!!!
{
if (!proj_) {
boost::unique_lock<boost::mutex> lock(Mtx_);
if (!proj_) {
proj_.reset(new LocalCartesian(ppk_raw_info.lat, ppk_raw_info.lng,
ppk_raw_info.height));
LOG(INFO) << setprecision(15) << "LocalCartesian center: "
<< Vector3d(ppk_raw_info.lat, ppk_raw_info.lng,
ppk_raw_info.height)
.transpose();
}
} }
PPK_Raw_Info ppk_raw_info; }
ppk_raw_info.gps_week = stoi(vec[1]);
ppk_raw_info.gps_sec = stod(vec[2]); TrajPoint trajPoint;
ppk_raw_info.lat = stod(vec[3]); Vector3d translation;
ppk_raw_info.lng = stod(vec[4]); proj_->Forward(ppk_raw_info.lat, ppk_raw_info.lng, ppk_raw_info.height,
ppk_raw_info.height = stod(vec[5]); translation.x(), translation.y(), translation.z());
ppk_raw_info.roll = stod(vec[9]); trajPoint.translation = translation;
ppk_raw_info.pitch = stod(vec[10]); trajPoint.rotation = EulerToMatrix3d(
ppk_raw_info.yaw = - stod(vec[11]); //ppk yaw take minus!!!!!!!!!!!!!!!!!!!! Vector3d(ppk_raw_info.pitch, ppk_raw_info.roll, ppk_raw_info.yaw), 1,
0, 2);
{ if (preTransform_ != Matrix4d::Identity()) {
if(!proj_){ trajPoint.rotation =
boost::unique_lock<boost::mutex> lock(Mtx_); trajPoint.rotation * preTransform_.block(0, 0, 3, 3).inverse();
if(!proj_){ }
proj_.reset(new LocalCartesian(ppk_raw_info.lat, // trajPoint.rotation = trajPoint.rotation *
ppk_raw_info.lng, // Eigen::AngleAxisd(M_PI/2, Eigen::Vector3d::UnitZ());
ppk_raw_info.height)); trajPoint.nodeId = trajectory_.size();
LOG(INFO) << setprecision(15) << "LocalCartesian center: " trajPoint.timestamp =
<< Vector3d(ppk_raw_info.lat, ppk_raw_info.lng, ppk_raw_info.height).transpose(); gpsToUtc(ppk_raw_info.gps_week, ppk_raw_info.gps_sec);
} if (onRelativeTraj_) {
} trajPoint.rotation = taskTrajPoseDiff_.linear() * trajPoint.rotation *
} taskTrajPoseDiff_.inverse().linear();
}
TrajPoint trajPoint; boost::unique_lock<boost::mutex> lock_ppk(Mtx_);
Vector3d translation; trajectory_.push_back(trajPoint);
proj_->Forward(ppk_raw_info.lat, ppk_raw_info.lng, ppk_raw_info.height,
translation.x(), break;
translation.y(),
translation.z());
trajPoint.translation = translation;
trajPoint.rotation = EulerToMatrix3d(Vector3d(ppk_raw_info.pitch, ppk_raw_info.roll, ppk_raw_info.yaw),
1, 0, 2);
if(preTransform_ != Matrix4d::Identity()){
trajPoint.rotation = trajPoint.rotation * preTransform_.block(0, 0, 3, 3).inverse();
}
// trajPoint.rotation = trajPoint.rotation * Eigen::AngleAxisd(M_PI/2, Eigen::Vector3d::UnitZ());
trajPoint.nodeId = trajectory_.size();
trajPoint.timestamp = gpsToUtc(ppk_raw_info.gps_week, ppk_raw_info.gps_sec);
if(onRelativeTraj_){
trajPoint.rotation = taskTrajPoseDiff_.linear() * trajPoint.rotation * taskTrajPoseDiff_.inverse().linear();
}
boost::unique_lock<boost::mutex> lock_ppk(Mtx_);
trajectory_.push_back(trajPoint);
break;
} }
case NODE: case NODE: {
{ if (vec.size() < MIN_NODE_LINE_ITEM_CNT) {
if(vec.size() < MIN_NODE_LINE_ITEM_CNT){ LOG_EVERY_N(WARNING, 99999)
LOG_EVERY_N(WARNING, 99999) << io_->getPath() << " line item size < " << MIN_NODE_LINE_ITEM_CNT;
<< io_->getPath() << " line item size < " << MIN_NODE_LINE_ITEM_CNT; return;
return; }
}
NODE_Raw_Info node_raw_info;
NODE_Raw_Info node_raw_info; node_raw_info.node_id = stoi(vec[1]);
node_raw_info.node_id = stoi(vec[1]); node_raw_info.time = stod(vec[2]);
node_raw_info.time = stod(vec[2]); node_raw_info.x = stod(vec[3]);
node_raw_info.x = stod(vec[3]); node_raw_info.y = stod(vec[4]);
node_raw_info.y = stod(vec[4]); node_raw_info.z = stod(vec[5]);
node_raw_info.z = stod(vec[5]); node_raw_info.w = stod(vec[9]);
node_raw_info.w = stod(vec[6]); node_raw_info.qx = stod(vec[6]);
node_raw_info.qx = stod(vec[7]); node_raw_info.qy = stod(vec[7]);
node_raw_info.qy = stod(vec[8]); node_raw_info.qz = stod(vec[8]);
node_raw_info.qz = stod(vec[9]);
// if(node_raw_info.node_id > 82000 && node_raw_info.node_id <
// if(node_raw_info.node_id > 82000 && node_raw_info.node_id < 82100){ // 82100){
// return; // return;
// } // }
// if(node_raw_info.node_id > 91552 && node_raw_info.node_id < 91744){ // if(node_raw_info.node_id > 91552 && node_raw_info.node_id <
// return; // 91744){
// } // return;
// if(node_raw_info.node_id > 72192 && node_raw_info.node_id < 72256){ // }
// return; // if(node_raw_info.node_id > 72192 && node_raw_info.node_id <
// } // 72256){
// bool skip = (node_raw_info.node_id > 10907 && node_raw_info.node_id < 13417) || // return;
// (node_raw_info.node_id > 86905 && node_raw_info.node_id < 89253) || // }
// (node_raw_info.node_id > 3076 && node_raw_info.node_id < 5752) ; // bool skip = (node_raw_info.node_id > 10907 &&
// node_raw_info.node_id < 13417) ||
// skip = !skip; // (node_raw_info.node_id > 86905 && node_raw_info.node_id
// < 89253) || (node_raw_info.node_id > 3076 &&
// if(skip){ // node_raw_info.node_id < 5752) ;
// return;
// } // skip = !skip;
if(trajectory_.size() == 0){ // if(skip){
trajId_ = stoi(vec[0]); // return;
// }
if (trajectory_.size() == 0) {
trajId_ = stoi(vec[0]);
}
TrajPoint trajPoint;
trajPoint.nodeId = node_raw_info.node_id;
trajPoint.timestamp = node_raw_info.time;
trajPoint.translation = {node_raw_info.x, node_raw_info.y,
node_raw_info.z};
trajPoint.rotation = {node_raw_info.w, node_raw_info.qx, node_raw_info.qy,
node_raw_info.qz};
if (onRelativeTraj_) {
trajPoint.translation =
taskTrajPoseDiff_.linear() * trajPoint.translation +
taskTrajPoseDiff_.translation();
int result_index;
float sqr_distance;
pcl::PointXYZ query;
query.x = trajPoint.translation.x();
query.y = trajPoint.translation.y();
query.z = trajPoint.translation.z();
octree->approxNearestSearch(query, result_index, sqr_distance);
if (sqr_distance < SquaredMinDis) {
return;
} }
TrajPoint trajPoint; trajPoint.rotation = taskTrajPoseDiff_.linear() * trajPoint.rotation *
trajPoint.nodeId = node_raw_info.node_id; taskTrajPoseDiff_.inverse().linear();
trajPoint.timestamp = node_raw_info.time; }
trajPoint.translation = {node_raw_info.x, node_raw_info.y, node_raw_info.z};
trajPoint.rotation = {node_raw_info.w, node_raw_info.qx, node_raw_info.qy, node_raw_info.qz};
if(onRelativeTraj_){
trajPoint.translation = taskTrajPoseDiff_.linear() * trajPoint.translation
+ taskTrajPoseDiff_.translation();
int result_index;
float sqr_distance;
pcl::PointXYZ query;
query.x = trajPoint.translation.x();
query.y = trajPoint.translation.y();
query.z = trajPoint.translation.z();
octree->approxNearestSearch(query, result_index, sqr_distance);
if(sqr_distance < SquaredMinDis){
return;
}
trajPoint.rotation = taskTrajPoseDiff_.linear() * trajPoint.rotation * taskTrajPoseDiff_.inverse().linear();
}
//pose yaw take -M_PI/2!!!!!!!!!!!!!!!!!! // pose yaw take -M_PI/2!!!!!!!!!!!!!!!!!!
// trajPoint.rotation = trajPoint.rotation * Eigen::AngleAxisd(-M_PI/2, Eigen::Vector3d::UnitZ()); // trajPoint.rotation = trajPoint.rotation *
// Eigen::AngleAxisd(-M_PI/2, Eigen::Vector3d::UnitZ());
// Matrix3d tempRot = Matrix3d::Identity() * Eigen::AngleAxisd(-2.032297, Vector3d::UnitZ()); // Matrix3d tempRot = Matrix3d::Identity() *
// Vector3d tempTrans(-3.7193, 9.0219, 15.2070); // Eigen::AngleAxisd(-2.032297, Vector3d::UnitZ()); Vector3d
// trajPoint.translation = tempRot * trajPoint.translation + (-tempTrans); // tempTrans(-3.7193, 9.0219, 15.2070); trajPoint.translation =
// trajPoint.rotation = tempRot * trajPoint.rotation; // tempRot * trajPoint.translation + (-tempTrans);
// trajPoint.rotation = tempRot * trajPoint.rotation;
boost::unique_lock<boost::mutex> lock_node(Mtx_); boost::unique_lock<boost::mutex> lock_node(Mtx_);
trajectory_.push_back(trajPoint); trajectory_.push_back(trajPoint);
break; break;
}
} }
}
} }
void Trajectory::setupBaseTrajOctree() void Trajectory::setupBaseTrajOctree() {
{ octree.reset(new pcl::octree::OctreePointCloudSearch<pcl::PointXYZ>(5));
octree.reset(new pcl::octree::OctreePointCloudSearch<pcl::PointXYZ>(5)); pcl::PointCloud<pcl::PointXYZ> trajCloud;
pcl::PointCloud<pcl::PointXYZ> trajCloud; for (const auto &trajPoint : trajectory_) {
for(const auto& trajPoint : trajectory_){ pcl::PointXYZ point;
pcl::PointXYZ point; point.x = trajPoint.translation.x();
point.x = trajPoint.translation.x(); point.y = trajPoint.translation.y();
point.y = trajPoint.translation.y(); point.z = trajPoint.translation.z();
point.z = trajPoint.translation.z(); trajCloud.push_back(point);
trajCloud.push_back(point); }
} octree->setInputCloud(
octree->setInputCloud(boost::make_shared<pcl::PointCloud<pcl::PointXYZ>>(trajCloud)); boost::make_shared<pcl::PointCloud<pcl::PointXYZ>>(trajCloud));
octree->addPointsFromInputCloud(); octree->addPointsFromInputCloud();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment