|
@@ -70,8 +70,27 @@ bool failureDetection(const gtsam::Vector3& velCur, const gtsam::imuBias::Consta
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-gtsam::Pose3 OdometryOpt::update(gtsam::Pose3 lidarPose,gtsam::noiseModel::Diagonal::shared_ptr priorPoseNoise,
|
|
|
- std::deque<ImuData>& imuQueue) {
|
|
|
+gtsam::Pose3 OdometryOpt::Preintegration(std::deque<ImuData>& imuQueue){
|
|
|
+ int queue_size=imuQueue.size();
|
|
|
+ double lastTime = -1;
|
|
|
+ while (!imuQueue.empty()) {
|
|
|
+ ImuData imu = imuQueue.front();
|
|
|
+ double dt = (lastTime < 0) ? 1.0 / imu_freq_ : imu.time - lastTime;
|
|
|
+ imu_preint_->integrateMeasurement(imu.acc, imu.angular, dt);
|
|
|
+ lastTime = imu.time;
|
|
|
+ imuQueue.pop_front();
|
|
|
+ /*printf("imu_preint_->integrateMeasurement(gtsam::Vector3(%f,%f,%f),gtsam::Vector3(%f,%f,%f),%f);\n",
|
|
|
+ imu.acc[0],imu.acc[1],imu.acc[2], imu.angular[0],imu.angular[1],imu.angular[2],dt);*/
|
|
|
+ if(dt<1e-6){
|
|
|
+ printf("error >>>>>>>> dt === %f\n",dt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ gtsam::NavState prevState(prevPose_,prevVel_);
|
|
|
+ imuIntegrateState_ = imu_preint_->predict(prevState, prevBias_);
|
|
|
+ return imuIntegrateState_.pose().compose(lidar2Imu_.inverse());
|
|
|
+}
|
|
|
+
|
|
|
+gtsam::Pose3 OdometryOpt::update(gtsam::Pose3 lidarPose,double ldMatchScore) {
|
|
|
static int N=0;
|
|
|
printf(" frame : %d , Key :%d >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n",N++,key_);
|
|
|
if (inited_ == false) { //第一帧
|
|
@@ -105,6 +124,7 @@ gtsam::Pose3 OdometryOpt::update(gtsam::Pose3 lidarPose,gtsam::noiseModel::Diago
|
|
|
prevVel_.x(),prevVel_.y(),prevVel_.z(),
|
|
|
prevBias_.vector()[0],prevBias_.vector()[1],prevBias_.vector()[2],
|
|
|
prevBias_.vector()[3],prevBias_.vector()[4],prevBias_.vector()[5]);
|
|
|
+
|
|
|
graph_.resize(0);
|
|
|
values_.clear();
|
|
|
key_ = 1;
|
|
@@ -139,31 +159,64 @@ gtsam::Pose3 OdometryOpt::update(gtsam::Pose3 lidarPose,gtsam::noiseModel::Diago
|
|
|
key_ = 1;
|
|
|
|
|
|
}
|
|
|
- int queue_size=imuQueue.size();
|
|
|
- double lastTime = -1;
|
|
|
- while (!imuQueue.empty()) {
|
|
|
- ImuData imu = imuQueue.front();
|
|
|
- double dt = (lastTime < 0) ? 1.0 / imu_freq_ : imu.time - lastTime;
|
|
|
- imu_preint_->integrateMeasurement(imu.acc, imu.angular, dt);
|
|
|
- lastTime = imu.time;
|
|
|
- imuQueue.pop_front();
|
|
|
- /*printf("imu_preint_->integrateMeasurement(gtsam::Vector3(%f,%f,%f),gtsam::Vector3(%f,%f,%f),%f);\n",
|
|
|
- imu.acc[0],imu.acc[1],imu.acc[2], imu.angular[0],imu.angular[1],imu.angular[2],dt);*/
|
|
|
- if(dt<1e-6){
|
|
|
- printf("error >>>>>>>> dt === %f\n",dt);
|
|
|
+
|
|
|
+
|
|
|
+ double lidarScore=0.02;
|
|
|
+ // insert predicted values
|
|
|
+ gtsam::Pose3 curPose = lidarPose.compose(lidar2Imu_);
|
|
|
+ double RAD=180.0/M_PI;
|
|
|
+ gtsam::Pose3 diff_lidar(gtsam::Rot3::RzRyRx(gtsam::Vector3(curPose.rotation().roll()-prevPose_.rotation().roll(),
|
|
|
+ curPose.rotation().pitch()-prevPose_.rotation().pitch(),
|
|
|
+ curPose.rotation().yaw()-prevPose_.rotation().yaw())),
|
|
|
+ gtsam::Point3(curPose.x()-prevPose_.x(),curPose.y()-prevPose_.y(),curPose.z()-prevPose_.z()));
|
|
|
+
|
|
|
+ printf(" lidar diff: %.4f %.4f %.4f,%.4f %.4f %.4f, Last Vel: %.3f %.3f %.3f\n",diff_lidar.x(),diff_lidar.y(),diff_lidar.z(),
|
|
|
+ diff_lidar.rotation().roll()*RAD,diff_lidar.rotation().pitch()*RAD,diff_lidar.rotation().yaw()*RAD,
|
|
|
+ prevVel_.x(),prevVel_.y(),prevVel_.z());
|
|
|
+
|
|
|
+ gtsam::Pose3 diff_imu(gtsam::Rot3::RzRyRx(gtsam::Vector3(imuIntegrateState_.pose().rotation().roll()-prevPose_.rotation().roll(),
|
|
|
+ imuIntegrateState_.pose().rotation().pitch()-prevPose_.rotation().pitch(),
|
|
|
+ imuIntegrateState_.pose().rotation().yaw()-prevPose_.rotation().yaw())),
|
|
|
+ gtsam::Point3(imuIntegrateState_.pose().x()-prevPose_.x(),imuIntegrateState_.pose().y()-prevPose_.y(),imuIntegrateState_.pose().z()-prevPose_.z()));
|
|
|
+
|
|
|
+ printf(" imuPr diff: %.4f %.4f %.4f,%.4f %.4f %.4f\n",diff_imu.x(),diff_imu.y(),diff_imu.z(),
|
|
|
+ diff_imu.rotation().roll()*RAD,diff_imu.rotation().pitch()*RAD,diff_imu.rotation().yaw()*RAD);
|
|
|
+
|
|
|
+ gtsam::Pose3 liadr2imu(gtsam::Rot3::RzRyRx(gtsam::Vector3(imuIntegrateState_.pose().rotation().roll()-curPose.rotation().roll(),
|
|
|
+ imuIntegrateState_.pose().rotation().pitch()-curPose.rotation().pitch(),
|
|
|
+ imuIntegrateState_.pose().rotation().yaw()-curPose.rotation().yaw())),
|
|
|
+ gtsam::Point3(imuIntegrateState_.pose().x()-curPose.x(),imuIntegrateState_.pose().y()-curPose.y(),imuIntegrateState_.pose().z()-curPose.z()));
|
|
|
+
|
|
|
+
|
|
|
+ double threshxy=0.1,threshR=5*M_PI/180.0;
|
|
|
+ bool ldimuCorrect=(fabs(liadr2imu.x())>threshxy || fabs(liadr2imu.y())>threshxy || fabs(liadr2imu.z())>threshxy ||
|
|
|
+ fabs(liadr2imu.rotation().roll())>threshR || fabs(liadr2imu.rotation().pitch())>threshR||fabs(liadr2imu.rotation().yaw())>threshR);
|
|
|
+ if(ldMatchScore>0.1){ //雷达数据匹配较差
|
|
|
+ if(ldimuCorrect){ //雷达 imu数据接近
|
|
|
+ lidarScore=0.05;
|
|
|
+ }else{
|
|
|
+ lidarScore=0.2;
|
|
|
+ }
|
|
|
+ }else{ //雷达数据较好
|
|
|
+ if(ldimuCorrect){ //雷达 imu数据接近
|
|
|
+ lidarScore=0.005;
|
|
|
+ }else{
|
|
|
+ lidarScore=0.01;
|
|
|
}
|
|
|
}
|
|
|
+ lidarScore=0.01;
|
|
|
+ printf(" imu2l diff: %.4f %.4f %.4f,%.4f %.4f %.4f --ldScore: %f----\n",liadr2imu.x(),liadr2imu.y(),liadr2imu.z(),
|
|
|
+ liadr2imu.rotation().roll()*RAD,liadr2imu.rotation().pitch()*RAD,liadr2imu.rotation().yaw()*RAD,lidarScore);
|
|
|
|
|
|
- // insert predicted values
|
|
|
- gtsam::NavState prevState(prevPose_,prevVel_);
|
|
|
- gtsam::NavState propState = imu_preint_->predict(prevState, prevBias_);
|
|
|
+
|
|
|
+ gtsam::noiseModel::Diagonal::shared_ptr lidarPoseNoise = gtsam::noiseModel::Diagonal::Sigmas(
|
|
|
+ (gtsam::Vector(6) << lidarScore, lidarScore,lidarScore,lidarScore, lidarScore, lidarScore).finished());
|
|
|
// add pose factor
|
|
|
- gtsam::Pose3 curPose = lidarPose.compose(lidar2Imu_);
|
|
|
- gtsam::PriorFactor<gtsam::Pose3> pose_factor(X(key_), curPose, priorPoseNoise);
|
|
|
+ gtsam::PriorFactor<gtsam::Pose3> pose_factor(X(key_), curPose, lidarPoseNoise);
|
|
|
graph_.add(pose_factor);
|
|
|
|
|
|
gtsam::noiseModel::Diagonal::shared_ptr priorVelNoise = gtsam::noiseModel::Isotropic::Sigma(3, 0.1); // m/s
|
|
|
- gtsam::PriorFactor<gtsam::Vector3> velFactor(V(key_),propState.v(),priorVelNoise);
|
|
|
+ gtsam::PriorFactor<gtsam::Vector3> velFactor(V(key_),imuIntegrateState_.v(),priorVelNoise);
|
|
|
graph_.add(velFactor);
|
|
|
|
|
|
gtsam::Vector noiseModelBetweenBias = (gtsam::Vector(6)
|
|
@@ -173,21 +226,22 @@ gtsam::Pose3 OdometryOpt::update(gtsam::Pose3 lidarPose,gtsam::noiseModel::Diago
|
|
|
gtsam::noiseModel::Diagonal::Sigmas(
|
|
|
imu_preint_->deltaTij() * noiseModelBetweenBias)));
|
|
|
|
|
|
+ /*gtsam::Vector noiseModelBetweenVel = (gtsam::Vector(3)
|
|
|
+ << 0.5,0.1,0.1).finished();
|
|
|
+ graph_.add(gtsam::BetweenFactor<gtsam::Vector3>(V(key_ - 1), V(key_), gtsam::Vector3(0,0,0) ,
|
|
|
+ gtsam::noiseModel::Diagonal::Sigmas(
|
|
|
+ imu_preint_->deltaTij() * noiseModelBetweenVel)));*/
|
|
|
+
|
|
|
// add imu factor to graph
|
|
|
const gtsam::PreintegratedImuMeasurements &preint_imu = dynamic_cast<const gtsam::PreintegratedImuMeasurements &>(*imu_preint_);
|
|
|
gtsam::ImuFactor imu_factor(X(key_ - 1), V(key_ - 1), X(key_), V(key_), B(key_ - 1), preint_imu);
|
|
|
graph_.add(imu_factor);
|
|
|
|
|
|
- gtsam::Pose3 lidar_preint=propState.pose().compose(lidar2Imu_.inverse());
|
|
|
+ gtsam::Pose3 lidar_preint=imuIntegrateState_.pose().compose(lidar2Imu_.inverse());
|
|
|
|
|
|
- printf(" frame %d init pose:%f %f %f,%f %f %f, V:%f %f %f, \nBias : %f %f %f,%f %f %f\n",N,
|
|
|
- propState.pose().x(),propState.pose().y(),propState.pose().z(),
|
|
|
- propState.pose().rotation().roll(), propState.pose().rotation().pitch(), propState.pose().rotation().yaw(),
|
|
|
- propState.v().x(),propState.v().y(),propState.v().z(),
|
|
|
- prevBias_.vector()[0],prevBias_.vector()[1],prevBias_.vector()[2],
|
|
|
- prevBias_.vector()[3],prevBias_.vector()[4],prevBias_.vector()[5]);
|
|
|
- values_.insert(X(key_), propState.pose());
|
|
|
- values_.insert(V(key_), propState.v());
|
|
|
+
|
|
|
+ values_.insert(X(key_), imuIntegrateState_.pose());
|
|
|
+ values_.insert(V(key_), imuIntegrateState_.v());
|
|
|
values_.insert(B(key_), prevBias_);
|
|
|
|
|
|
// optimize
|