40 if (!oldInstance->getMotionModel())
45 armarx::LinkedPoseBasePtr oldPoseBase = oldInstance->getMotionModel()->getPredictedPoseAtStartOfCurrentLocalization();
52 ARMARX_DEBUG_S <<
"Pose of update " << newInstance->getPose()->output();
54 oldPose->changeFrame(newInstance->getPosition()->frame);
59 fusedInstance = oldInstance->clone();
64 float oldExistenceCertainty =
std::max(oldInstance->getExistenceCertainty(), 0.1f);
65 float newExistenceCertainty =
std::max(newInstance->getExistenceCertainty(), 0.1f);
66 float fusedExistenceCertainty = (oldExistenceCertainty * newExistenceCertainty) / ((oldExistenceCertainty * newExistenceCertainty) + (1 - oldExistenceCertainty) * (1 - newExistenceCertainty));
67 fusedInstance->setExistenceCertainty(fusedExistenceCertainty);
74 Eigen::MatrixXd i(3, 3);
77 MultivariateNormalDistributionBasePtr newUncertainty = newInstance->getPositionUncertainty();
78 MultivariateNormalDistributionBasePtr oldUncertainty = oldInstance->getPositionUncertainty();
82 ARMARX_ERROR_S <<
"new instance's position uncertainty is zero! - instance name: " << newInstance->getName();
83 return newInstance->clone();
88 ARMARX_ERROR_S <<
"old instance's position uncertainty is zero! - instance name: " << oldInstance->getName();
89 return newInstance->clone();
99 const float meanRadiusOfMeasurementEllipsoid = pow(measurement.
getCovariance().determinant(), 0.5 / measurement.
getDimensions());
101 ARMARX_DEBUG_S <<
"Std dev of old believe: " << meanRadiusOfOldBelieveEllipsoid <<
", std dev of measurement: " << meanRadiusOfMeasurementEllipsoid;
102 const float interpolationFactor = 0.01f + 0.99f * meanRadiusOfOldBelieveEllipsoid / (meanRadiusOfMeasurementEllipsoid + meanRadiusOfOldBelieveEllipsoid);
103 Eigen::Vector3f fusedPosition = interpolationFactor * newInstance->getPosition()->toEigen() + (1.0f - interpolationFactor) * oldPose->toEigen().block<3, 1>(0, 3);
105 fusedInstance->setPosition(pos);
107 Eigen::Quaternionf measurementOrientation(newInstance->getOrientation()->qw, newInstance->getOrientation()->qx, newInstance->getOrientation()->qy, newInstance->getOrientation()->qz);
108 Eigen::Quaternionf oldBelieveOrientation(oldPose->orientation->qw, oldPose->orientation->qx, oldPose->orientation->qy, oldPose->orientation->qz);
109 Eigen::Quaternionf fusedOrientation = oldBelieveOrientation.
slerp(interpolationFactor, measurementOrientation);
110 fusedOrientation.normalize();
112 fusedInstance->setOrientation(ori);
117 ARMARX_DEBUG_S <<
"Position after fusion: " << fusedInstance->getPosition()->output();
118 ARMARX_DEBUG_S <<
"Orientation after fusion: " << fusedInstance->getOrientation()->output();
122 ARMARX_VERBOSE_S <<
"No old pose estimation available, using new measurement.";
123 fusedInstance = newInstance->clone();
126 return fusedInstance;