OptimizerG2O: add XYZ/SE3 and XY/SE2 priors depending on the angular covariances

This commit is contained in:
TSC21
2018-12-26 16:30:40 +00:00
parent 97f956f138
commit b7f2eb8df9

View File

@@ -397,45 +397,92 @@ std::map<int, Transform> OptimizerG2O::optimize(
{ {
if(isSlam2d()) if(isSlam2d())
{ {
g2o::EdgeSE2Prior * priorEdge = new g2o::EdgeSE2Prior(); if (iter->second.infMatrix().at<double>(3,3) <= 9999 && iter->second.infMatrix().at<double>(4,4) <= 9999 && iter->second.infMatrix().at<double>(5,5) <= 9999)
g2o::VertexSE2* v1 = (g2o::VertexSE2*)optimizer.vertex(id1); {
priorEdge->setVertex(0, v1); g2o::EdgeSE2Prior * priorEdge = new g2o::EdgeSE2Prior();
priorEdge->setMeasurement(g2o::SE2(iter->second.transform().x(), iter->second.transform().y(), iter->second.transform().theta())); g2o::VertexSE2* v1 = (g2o::VertexSE2*)optimizer.vertex(id1);
priorEdge->setParameterId(0, PARAM_OFFSET); priorEdge->setVertex(0, v1);
Eigen::Matrix<double, 3, 3> information = Eigen::Matrix<double, 3, 3>::Identity(); priorEdge->setMeasurement(g2o::SE2(iter->second.transform().x(), iter->second.transform().y(), iter->second.transform().theta()));
if(!isCovarianceIgnored()) priorEdge->setParameterId(0, PARAM_OFFSET);
{ Eigen::Matrix<double, 3, 3> information = Eigen::Matrix<double, 3, 3>::Identity();
information(0,0) = iter->second.infMatrix().at<double>(0,0); // x-x if(!isCovarianceIgnored())
information(0,1) = iter->second.infMatrix().at<double>(0,1); // x-y {
information(0,2) = iter->second.infMatrix().at<double>(0,5); // x-theta information(0,0) = iter->second.infMatrix().at<double>(0,0); // x-x
information(1,0) = iter->second.infMatrix().at<double>(1,0); // y-x information(0,1) = iter->second.infMatrix().at<double>(0,1); // x-y
information(1,1) = iter->second.infMatrix().at<double>(1,1); // y-y information(0,2) = iter->second.infMatrix().at<double>(0,5); // x-theta
information(1,2) = iter->second.infMatrix().at<double>(1,5); // y-theta information(1,0) = iter->second.infMatrix().at<double>(1,0); // y-x
information(2,0) = iter->second.infMatrix().at<double>(5,0); // theta-x information(1,1) = iter->second.infMatrix().at<double>(1,1); // y-y
information(2,1) = iter->second.infMatrix().at<double>(5,1); // theta-y information(1,2) = iter->second.infMatrix().at<double>(1,5); // y-theta
information(2,2) = iter->second.infMatrix().at<double>(5,5); // theta-theta information(2,0) = iter->second.infMatrix().at<double>(5,0); // theta-x
} information(2,1) = iter->second.infMatrix().at<double>(5,1); // theta-y
priorEdge->setInformation(information); information(2,2) = iter->second.infMatrix().at<double>(5,5); // theta-theta
edge = priorEdge; }
} priorEdge->setInformation(information);
else edge = priorEdge;
}
else
{
g2o::EdgeXYPrior * priorEdge = new g2o::EdgeXYPrior();
g2o::VertexPointXY* v1 = (g2o::VertexPointXY*)optimizer.vertex(id1);
priorEdge->setVertex(0, v1);
priorEdge->setMeasurement(g2o::Vector2(iter->second.transform().x(), iter->second.transform().y()));
priorEdge->setParameterId(0, PARAM_OFFSET);
Eigen::Matrix<double, 2, 2> information = Eigen::Matrix<double, 2, 2>::Identity();
if(!isCovarianceIgnored())
{
information(0,0) = iter->second.infMatrix().at<double>(0,0); // x-x
information(0,1) = iter->second.infMatrix().at<double>(0,1); // x-y
information(1,0) = iter->second.infMatrix().at<double>(1,0); // y-x
information(1,1) = iter->second.infMatrix().at<double>(1,1); // y-y
}
priorEdge->setInformation(information);
edge = priorEdge;
}
}
else
{ {
g2o::EdgeSE3Prior * priorEdge = new g2o::EdgeSE3Prior(); if (iter->second.infMatrix().at<double>(3,3) <= 9999 && iter->second.infMatrix().at<double>(4,4) <= 9999 && iter->second.infMatrix().at<double>(5,5) <= 9999)
g2o::VertexSE3* v1 = (g2o::VertexSE3*)optimizer.vertex(id1); {
priorEdge->setVertex(0, v1); g2o::EdgeSE3Prior * priorEdge = new g2o::EdgeSE3Prior();
Eigen::Affine3d a = iter->second.transform().toEigen3d(); g2o::VertexSE3* v1 = (g2o::VertexSE3*)optimizer.vertex(id1);
Eigen::Isometry3d pose; priorEdge->setVertex(0, v1);
pose = a.linear(); Eigen::Affine3d a = iter->second.transform().toEigen3d();
pose.translation() = a.translation(); Eigen::Isometry3d pose;
priorEdge->setMeasurement(pose); pose = a.linear();
priorEdge->setParameterId(0, PARAM_OFFSET); pose.translation() = a.translation();
Eigen::Matrix<double, 6, 6> information = Eigen::Matrix<double, 6, 6>::Identity(); priorEdge->setMeasurement(pose);
if(!isCovarianceIgnored()) priorEdge->setParameterId(0, PARAM_OFFSET);
{ Eigen::Matrix<double, 6, 6> information = Eigen::Matrix<double, 6, 6>::Identity();
memcpy(information.data(), iter->second.infMatrix().data, iter->second.infMatrix().total()*sizeof(double)); if(!isCovarianceIgnored())
} {
priorEdge->setInformation(information); memcpy(information.data(), iter->second.infMatrix().data, iter->second.infMatrix().total()*sizeof(double));
edge = priorEdge; }
priorEdge->setInformation(information);
edge = priorEdge;
}
else
{
g2o::EdgeXYZPrior * priorEdge = new g2o::EdgeXYZPrior();
g2o::VertexPointXYZ* v1 = (g2o::VertexPointXYZ*)optimizer.vertex(id1);
priorEdge->setVertex(0, v1);
priorEdge->setMeasurement(g2o::Vector3(iter->second.transform().x(), iter->second.transform().y(), iter->second.transform().z()));
priorEdge->setParameterId(0, PARAM_OFFSET);
Eigen::Matrix<double, 3, 3> information = Eigen::Matrix<double, 3, 3>::Identity();
if(!isCovarianceIgnored())
{
information(0,0) = iter->second.infMatrix().at<double>(0,0); // x-x
information(0,1) = iter->second.infMatrix().at<double>(0,1); // x-y
information(0,2) = iter->second.infMatrix().at<double>(0,2); // x-z
information(1,0) = iter->second.infMatrix().at<double>(1,0); // y-x
information(1,1) = iter->second.infMatrix().at<double>(1,1); // y-y
information(1,2) = iter->second.infMatrix().at<double>(1,2); // y-z
information(2,0) = iter->second.infMatrix().at<double>(2,0); // z-x
information(2,1) = iter->second.infMatrix().at<double>(2,1); // z-y
information(2,2) = iter->second.infMatrix().at<double>(2,2); // z-z
}
priorEdge->setInformation(information);
edge = priorEdge;
}
} }
} }
} }