26 #ifndef ODOMETRY_MOTION_MODEL_HPP
27 #define ODOMETRY_MOTION_MODEL_HPP
31 #include <boost/shared_ptr.hpp>
32 #include <base-logging/Logging.hpp>
33 #include <Eigen/Geometry>
35 #include <Eigen/Dense>
36 #include <Eigen/Cholesky>
92 template <
typename _Scalar,
int _RobotTrees,
int _RobotJo
intDoF,
int _SlipDoF,
int _ContactDoF>
96 static const unsigned int MAX_CHAIN_DOF = _RobotJointDoF+_SlipDoF+_ContactDoF;
99 static const unsigned int MODEL_DOF = _RobotJointDoF+_RobotTrees*(_SlipDoF+_ContactDoF);
106 typedef boost::shared_ptr< KinematicModel <_Scalar, _RobotTrees, _RobotJointDoF, _SlipDoF, _ContactDoF> >
kinematics_ptr;
151 if ((*it).number > 1)
153 double zdistance = 0.00;
154 for (
register unsigned int i=0; i<(*it).number; ++i)
156 if (zdistance >
fkRobot[j+i].translation()[2])
158 zdistance =
fkRobot[j+i].translation()[2];
163 else if ((*it).number == 1)
175 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
176 std::cout<<
"[MOTION_MODEL] Selected Points in Contact:";
179 std::cout<<
" "<<(*it).contactId;
213 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
214 std::cout<<
"[MOTION_MODEL SelectPoints] Lowest Points method\n";
220 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
221 std::cout<<
"[MOTION_MODEL SelectPoints] Combinatorics Points method\n";
252 inline void navEquations(
const Eigen::Matrix <_Scalar, 6, 1> &cartesianVelocities,
253 const Eigen::Matrix <_Scalar, MODEL_DOF, 1> &modelVelocities,
254 const Eigen::Matrix <_Scalar, 6*_RobotTrees, MODEL_DOF> &J,
255 const Eigen::Matrix <_Scalar, 6, 6> &cartesianVelCov,
256 const Eigen::Matrix <_Scalar, MODEL_DOF, MODEL_DOF> &modelVelCov,
257 Eigen::Matrix <_Scalar, 6*_RobotTrees, 3+_RobotTrees+(_RobotTrees*_ContactDoF)> &unknownA,
258 Eigen::Matrix <_Scalar, 3+_RobotTrees+(_RobotTrees*_ContactDoF), 1> &unknownx,
259 Eigen::Matrix <_Scalar, 6*_RobotTrees, 3+_RobotJointDoF> &knownB,
260 Eigen::Matrix <_Scalar, 3+_RobotJointDoF, 1> &knowny,
261 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6*_RobotTrees> &Weight)
263 Eigen::Matrix<_Scalar, 6*_RobotTrees, 6> spareI;
265 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
266 std::cout<<
"[MOTION_MODEL] navEquations\n";
270 for (
register int i=0; i<_RobotTrees; ++i)
271 spareI.template block<6, 6>(i*6, 0) = Eigen::Matrix <_Scalar, 6, 6>::Identity();
274 unknownA.template block<6*_RobotTrees, 3> (0,0) = spareI.template block<6*_RobotTrees, 3> (0,0);
277 unknownx.template block<3, 1> (0,0) = cartesianVelocities.template block<3, 1> (0,0);
280 for (
register int i=0; i<_RobotTrees; ++i)
282 unknownA.col(3+i) = -J.col(_RobotJointDoF+(_SlipDoF*(i+1)-1));
283 unknownx[3+i] = modelVelocities[_RobotJointDoF+(_SlipDoF*(i+1)-1)];
287 for (
register int i=0; i<(_RobotTrees*_ContactDoF); ++i)
289 unknownA.col(3+_RobotTrees+i) = -J.col(_RobotJointDoF+(_RobotTrees*_SlipDoF)+i);
290 unknownx[3+_RobotTrees+i] = modelVelocities[_RobotJointDoF+(_RobotTrees*_SlipDoF)+i];
294 knownB.template block< (6* _RobotTrees), 3> (0,0) = -spareI.template block<6*_RobotTrees, 3> (0,3);
295 knownB.template block< (6* _RobotTrees), _RobotJointDoF> (0,3) = J.template block<6*_RobotTrees, _RobotJointDoF> (0,0);
298 knowny.template block<3, 1> (0,0) = cartesianVelocities.template block<3, 1> (3,0);
299 knowny.template block<_RobotJointDoF, 1> (3,0) = modelVelocities.template block<_RobotJointDoF, 1> (0,0);
301 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
302 std::cout<<
"[MOTION_MODEL] spareI is of size "<<spareI.rows()<<
"x"<<spareI.cols()<<
"\n";
303 std::cout<<
"[MOTION_MODEL] The spareI matrix:\n" << spareI << std::endl;
304 std::cout<<
"[MOTION_MODEL] unknownA is of size "<<unknownA.rows()<<
"x"<<unknownA.cols()<<
"\n";
305 std::cout<<
"[MOTION_MODEL] The unknownA matrix:\n" << unknownA << std::endl;
306 std::cout<<
"[MOTION_MODEL] knownB is of size "<<knownB.rows()<<
"x"<<knownB.cols()<<
"\n";
307 std::cout<<
"[MOTION_MODEL] The knownB matrix:\n" << knownB << std::endl;
308 std::cout<<
"[MOTION_MODEL] Weight is of size "<<Weight.rows()<<
"x"<<Weight.cols()<<
"\n";
309 std::cout<<
"[MOTION_MODEL] The Weight matrix:\n" << Weight << std::endl;
338 const Eigen::Matrix <_Scalar, MODEL_DOF, 1> &modelVelocities,
339 const Eigen::Matrix <_Scalar, 6*_RobotTrees, MODEL_DOF> &J,
340 const Eigen::Matrix <_Scalar, 6, 6> &cartesianVelCov,
341 const Eigen::Matrix <_Scalar, MODEL_DOF, MODEL_DOF> &modelVelCov,
342 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6+_RobotTrees+(_RobotTrees*_ContactDoF)> &unknownA,
343 Eigen::Matrix <_Scalar, 6+_RobotTrees+(_RobotTrees*_ContactDoF), 1> &unknownx,
344 Eigen::Matrix <_Scalar, 6*_RobotTrees, _RobotJointDoF> &knownB,
345 Eigen::Matrix <_Scalar, _RobotJointDoF, 1> &knowny,
346 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6*_RobotTrees> &Weight)
348 Eigen::Matrix<_Scalar, 6*_RobotTrees, 6> spareI;
350 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
351 std::cout<<
"[MOTION_MODEL] navEquations\n";
355 for (
register int i=0; i<_RobotTrees; ++i)
356 spareI.template block<6, 6>(i*6, 0) = Eigen::Matrix <_Scalar, 6, 6>::Identity();
359 unknownA.template block<6*_RobotTrees, 6> (0,0) = spareI;
362 unknownx.template block<6, 1> (0,0) = cartesianVelocities;
365 for (
register int i=0; i<_RobotTrees; ++i)
367 unknownA.col(6+i) = -J.col(_RobotJointDoF+(_SlipDoF*(i+1)-1));
368 unknownx[6+i] = modelVelocities[_RobotJointDoF+(_SlipDoF*(i+1)-1)];
372 for (
register int i=0; i<(_RobotTrees*_ContactDoF); ++i)
374 unknownA.col(6+_RobotTrees+i) = -J.col(_RobotJointDoF+(_RobotTrees*_SlipDoF)+i);
375 unknownx[6+_RobotTrees+i] = modelVelocities[_RobotJointDoF+(_RobotTrees*_SlipDoF)+i];
379 knownB.template block< (6*_RobotTrees), _RobotJointDoF> (0,0) = J.template block<6*_RobotTrees, _RobotJointDoF> (0,0);
382 knowny.template block<_RobotJointDoF, 1> (0,0) = modelVelocities.template block<_RobotJointDoF, 1> (0,0);
384 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
385 std::cout<<
"[MOTION_MODEL] spareI is of size "<<spareI.rows()<<
"x"<<spareI.cols()<<
"\n";
386 std::cout<<
"[MOTION_MODEL] The spareI matrix:\n" << spareI << std::endl;
387 std::cout<<
"[MOTION_MODEL] unknownA is of size "<<unknownA.rows()<<
"x"<<unknownA.cols()<<
"\n";
388 std::cout<<
"[MOTION_MODEL] The unknownA matrix:\n" << unknownA << std::endl;
389 std::cout<<
"[MOTION_MODEL] knownB is of size "<<knownB.rows()<<
"x"<<knownB.cols()<<
"\n";
390 std::cout<<
"[MOTION_MODEL] The knownB matrix:\n" << knownB << std::endl;
391 std::cout<<
"[MOTION_MODEL] Weight is of size "<<Weight.rows()<<
"x"<<Weight.cols()<<
"\n";
392 std::cout<<
"[MOTION_MODEL] The Weight matrix:\n" << Weight << std::endl;
416 std::vector<unsigned int> numberContactPoints (_RobotTrees, 0);
423 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
424 std::cout<<
"[MOTION_MODEL] Constructor\n";
428 robotModel->contactPointsPerTree(numberContactPoints);
433 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
434 std::cout<<
"[MOTION_MODEL] Get number of trees "<<robotModel->getNumberOfTrees()<<
"\n";
437 if ((robotModel->getNumberOfTrees() ==
static_cast<int>(numberContactPoints.size())) &&(numberContactPoints.size() == _RobotTrees))
440 for (
register unsigned int i=0; i<numberContactPoints.size(); ++i)
447 LOG_INFO(
"[MOTION_MODEL] Created Motion Model using %s Robot Kinematics implementation\n", this->robotModel->name().c_str());
448 LOG_INFO(
"[MOTION_MODEL] %s has %d independent kinematic trees.\n", this->robotModel->name().c_str(), this->robotModel->getNumberOfTrees());
453 LOG_ERROR(
"[MOTION_MODEL] Malfunction of the MotionModel. WRONG number of template parameters\n");
457 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
458 std::cout<<
"[MOTION_MODEL] contactPoints contains: ";
461 std::cout<<
" number: "<<(*it).number<<
" contactId: "<<(*it).contactId;
464 std::cout<<
"\n[MOTION_MODEL] **** END ****\n";
485 std::vector<_Scalar> vectorPositions(
MODEL_DOF, 0);
486 std::vector<int> contactId (_RobotTrees, 0);
489 Eigen::Map <Eigen::Matrix <_Scalar, MODEL_DOF, 1> > (&(vectorPositions[0]),
MODEL_DOF) = modelPositions;
500 contactId[i] = (*it).contactId;
514 inline virtual void getKinematics (std::vector<Eigen::Affine3d> ¤tFkRobot, std::vector<base::Matrix6d> ¤tFkCov)
516 currentFkRobot = this->
fkRobot;
517 currentFkCov = this->
fkCov;
530 std::vector<int> contactId (_RobotTrees, 0);
534 contactId[i] = (*it).contactId;
559 virtual double navSolver(
const Eigen::Matrix <_Scalar, MODEL_DOF, 1> &modelPositions,
560 Eigen::Matrix <_Scalar, 6, 1> &cartesianVelocities,
561 Eigen::Matrix <_Scalar, MODEL_DOF, 1> &modelVelocities,
562 Eigen::Matrix <_Scalar, 6, 6> &cartesianVelCov,
563 Eigen::Matrix <_Scalar, MODEL_DOF, MODEL_DOF> &modelVelCov,
564 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6*_RobotTrees> Weight)
566 double normalizedError = std::numeric_limits<double>::quiet_NaN();
567 std::vector<_Scalar> vectorPositions(
MODEL_DOF, 0);
568 Eigen::Matrix <_Scalar, 6*_RobotTrees, MODEL_DOF> J;
569 Eigen::Matrix <_Scalar, 6*_RobotTrees, 3+_RobotTrees+(_RobotTrees*_ContactDoF)> unknownA;
570 Eigen::Matrix <_Scalar, 3+_RobotTrees+(_RobotTrees*_ContactDoF), 1> unknownx;
571 Eigen::Matrix <_Scalar, 6*_RobotTrees, 3+_RobotJointDoF> knownB;
572 Eigen::Matrix <_Scalar, 3+_RobotJointDoF, 1> knowny;
575 unknownA.setZero(); unknownx.setZero();
576 knownB.setZero(); knowny.setZero();
578 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
579 std::cout <<
"[MOTION_MODEL] cartesianVelocities is of size "<<cartesianVelocities.rows()<<
"x"<<cartesianVelocities.cols()<<
"\n";
580 std::cout <<
"[MOTION_MODEL] cartesianVelocities is \n" << cartesianVelocities<< std::endl;
582 std::cout <<
"[MOTION_MODEL] modelVelocities is of size "<<modelVelocities.rows()<<
"x"<<modelVelocities.cols()<<
"\n";
583 std::cout <<
"[MOTION_MODEL] modelVelocities is \n" << modelVelocities<< std::endl;
587 Eigen::Map <Eigen::Matrix <_Scalar, MODEL_DOF, 1> > (&(vectorPositions[0]),
MODEL_DOF) = modelPositions;
590 J =
robotModel->jacobianSolver (vectorPositions);
592 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
593 std::cout<<
"[MOTION_MODEL] J is of size "<<J.rows()<<
"x"<<J.cols()<<
"\n";
594 std::cout<<
"[MOTION_MODEL] The J matrix \n" << J << std::endl;
598 this->
navEquations (cartesianVelocities, modelVelocities, J,
599 cartesianVelCov, modelVelCov, unknownA, unknownx, knownB, knowny, Weight);
603 Eigen::Matrix <_Scalar, 6*_RobotTrees, 1> knownb = knownB*knowny;
605 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
607 typedef Eigen::Matrix <_Scalar, 6*_RobotTrees, 3+_RobotTrees+(_RobotTrees*_ContactDoF)> matrixAType;
608 typedef Eigen::Matrix <_Scalar, 6*_RobotTrees, 3+_RobotJointDoF> matrixBType;
609 typedef Eigen::Matrix <_Scalar, 6*_RobotTrees, 3+_RobotTrees+(_RobotTrees*_ContactDoF)+1> matrixConjType;
613 Eigen::FullPivLU<matrixAType> lu_decompA(unknownA);
614 std::cout <<
"[MOTION_MODEL] The rank of A is " << lu_decompA.rank() << std::endl;
616 Eigen::FullPivLU<matrixBType> lu_decompB(knownB);
617 std::cout <<
"[MOTION_MODEL] The rank of B is " << lu_decompB.rank() << std::endl;
619 Conj.template block<6*_RobotTrees,3+_RobotTrees+(_RobotTrees*_ContactDoF)>(0,0) = unknownA;
620 Conj.template block<6*_RobotTrees, 1>(0,3+_RobotTrees+(_RobotTrees*_ContactDoF)) = knownb;
621 Eigen::FullPivLU<matrixConjType> lu_decompConj(Conj);
622 std::cout <<
"[MOTION_MODEL] The rank of A|B*y is " << lu_decompConj.rank() << std::endl;
623 std::cout <<
"[MOTION_MODEL] Pseudoinverse of A\n" << (unknownA.transpose() * Weight * unknownA).inverse() << std::endl;
627 unknownx = (unknownA.transpose() * Weight * unknownA).ldlt().solve(unknownA.transpose() * Weight * knownb);
630 Eigen::Matrix<double, 1,1> squaredError = (((unknownA*unknownx - knownb).transpose() * Weight * (unknownA*unknownx - knownb)));
631 if (knownb.norm() != 0.00)
632 normalizedError = sqrt(squaredError[0]) / knownb.norm();
636 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6*_RobotTrees> errorCov = (unknownA*unknownx - knownb).asDiagonal(); errorCov *= errorCov;
637 Eigen::Matrix <_Scalar, 3+_RobotTrees+(_RobotTrees*_ContactDoF), 3+_RobotTrees+(_RobotTrees*_ContactDoF)> uncertaintyCov;
638 uncertaintyCov = (unknownA.transpose() * errorCov.inverse() * unknownA).inverse();
639 uncertaintyCov = 0.5*(uncertaintyCov + uncertaintyCov.transpose());
642 cartesianVelocities.template block<3, 1>(0,0) = unknownx.template block<3, 1>(0,0);
643 cartesianVelCov.template block<3, 3> (0,0) = uncertaintyCov.template block<3,3>(0,0);
646 if (cartesianVelCov.template block<3, 3> (3,3) == Eigen::Matrix3d::Zero())
649 for (
register size_t i=0; i<_RobotTrees; ++i)
651 cartesianVelCov.template block<3, 3> (3,3) += Weight.template block<3,3> (3+(6*i), 3+(6*i)) * errorCov.template block<3,3> (3+(6*i),3+(6*i));
656 for (
register int i=0; i<_RobotTrees; ++i)
658 modelVelocities[_RobotJointDoF+(_SlipDoF*(i+1)-1)] = unknownx[3+i];
659 modelVelCov.col(_RobotJointDoF+(_SlipDoF*(i+1)-1))[_RobotJointDoF+(_SlipDoF*(i+1)-1)] = uncertaintyCov.col(3+i)[3+i];
663 for (
register int i=0; i<(_RobotTrees*_ContactDoF); ++i)
665 modelVelocities[_RobotJointDoF+(_RobotTrees*_SlipDoF)+i] = unknownx[3+_RobotTrees+i];
666 modelVelCov.col(_RobotJointDoF+(_RobotTrees*_SlipDoF)+i)[_RobotJointDoF+(_RobotTrees*_SlipDoF)+i] = uncertaintyCov.col(3+_RobotTrees+i)[3+_RobotTrees+i];
669 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
670 std::cout <<
"[MOTION_MODEL] L-S solution:\n"<<unknownx<<std::endl;
672 std::cout <<
"[MOTION_MODEL] RESULT errorCov is of size "<<errorCov.rows()<<
"x"<<errorCov.cols()<<
"\n";
673 std::cout <<
"[MOTION_MODEL] RESULT errorCov is \n" << errorCov << std::endl;
675 std::cout <<
"[MOTION_MODEL] RESULT uncertaintyCov is of size "<<uncertaintyCov.rows()<<
"x"<<uncertaintyCov.cols()<<
"\n";
676 std::cout <<
"[MOTION_MODEL] RESULT uncertaintyCov is \n" << uncertaintyCov << std::endl;
678 std::cout <<
"[MOTION_MODEL] RESULT cartesianVelocities is of size "<<cartesianVelocities.rows()<<
"x"<<cartesianVelocities.cols()<<
"\n";
679 std::cout <<
"[MOTION_MODEL] RESULT cartesianVelocities is \n" << cartesianVelocities<< std::endl;
681 std::cout <<
"[MOTION_MODEL] RESULT cartesianVelCov is of size "<<cartesianVelCov.rows()<<
"x"<<cartesianVelCov.cols()<<
"\n";
682 std::cout <<
"[MOTION_MODEL] RESULT cartesianVelCov is \n" << cartesianVelCov<< std::endl;
684 std::cout <<
"[MOTION_MODEL] RESULT modelVelocities is of size "<<modelVelocities.rows()<<
"x"<<modelVelocities.cols()<<
"\n";
685 std::cout <<
"[MOTION_MODEL] RESULT modelVelocities is \n" << modelVelocities<< std::endl;
687 std::cout <<
"[MOTION_MODEL] RESULT modelVelCov is of size "<<modelVelCov.rows()<<
"x"<<modelVelCov.cols()<<
"\n";
688 std::cout <<
"[MOTION_MODEL] RESULT modelVelCov is \n" << modelVelCov<< std::endl;
690 std::cout <<
"[MOTION_MODEL] RESULT The absolute least squared error is:\n" << squaredError << std::endl;
691 std::cout <<
"[MOTION_MODEL] RESULT The relative error is:\n" << normalizedError << std::endl;
692 std::cout <<
"[MOTION_MODEL] RESULT The error vector is \n"<<(unknownA*unknownx - knownb)<<
"\n";
693 std::cout <<
"[MOTION_MODEL] RESULT The error variance is \n"<<errorCov<<
"\n";
694 std::cout <<
"[MOTION_MODEL] RESULT The error variance.inverse() is \n"<<errorCov.inverse()<<
"\n";
695 std::cout <<
"[MOTION_MODEL] RESULT The solution covariance is \n"<<cartesianVelCov<<
"\n";
699 return normalizedError;
720 Eigen::Matrix <_Scalar, 6, 1> &cartesianVelocities,
721 Eigen::Matrix <_Scalar, MODEL_DOF, 1> &modelVelocities,
722 Eigen::Matrix <_Scalar, 6, 6> &cartesianVelCov,
723 Eigen::Matrix <_Scalar, MODEL_DOF, MODEL_DOF> &modelVelCov,
724 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6*_RobotTrees> Weight)
726 double normalizedError = std::numeric_limits<double>::quiet_NaN();
727 std::vector<_Scalar> vectorPositions(
MODEL_DOF, 0);
728 Eigen::Matrix <_Scalar, 6*_RobotTrees, MODEL_DOF> J;
729 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6+_RobotTrees+(_RobotTrees*_ContactDoF)> unknownA;
730 Eigen::Matrix <_Scalar, 6+_RobotTrees+(_RobotTrees*_ContactDoF), 1> unknownx;
731 Eigen::Matrix <_Scalar, 6*_RobotTrees, _RobotJointDoF> knownB;
732 Eigen::Matrix <_Scalar, _RobotJointDoF, 1> knowny;
735 unknownA.setZero(); unknownx.setZero();
736 knownB.setZero(); knowny.setZero();
738 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
739 std::cout <<
"[MOTION_MODEL] cartesianVelocities is of size "<<cartesianVelocities.rows()<<
"x"<<cartesianVelocities.cols()<<
"\n";
740 std::cout <<
"[MOTION_MODEL] cartesianVelocities is \n" << cartesianVelocities<< std::endl;
742 std::cout <<
"[MOTION_MODEL] modelVelocities is of size "<<modelVelocities.rows()<<
"x"<<modelVelocities.cols()<<
"\n";
743 std::cout <<
"[MOTION_MODEL] modelVelocities is \n" << modelVelocities<< std::endl;
747 Eigen::Map <Eigen::Matrix <_Scalar, MODEL_DOF, 1> > (&(vectorPositions[0]),
MODEL_DOF) = modelPositions;
750 J =
robotModel->jacobianSolver (vectorPositions);
752 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
753 std::cout<<
"[MOTION_MODEL] J is of size "<<J.rows()<<
"x"<<J.cols()<<
"\n";
754 std::cout<<
"[MOTION_MODEL] The J matrix \n" << J << std::endl;
759 cartesianVelCov, modelVelCov, unknownA, unknownx, knownB, knowny, Weight);
763 Eigen::Matrix <_Scalar, 6*_RobotTrees, 1> knownb = knownB*knowny;
765 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
767 typedef Eigen::Matrix <_Scalar, 6*_RobotTrees, 6+_RobotTrees+(_RobotTrees*_ContactDoF)> matrixAType;
768 typedef Eigen::Matrix <_Scalar, 6*_RobotTrees, _RobotJointDoF> matrixBType;
769 typedef Eigen::Matrix <_Scalar, 6*_RobotTrees, 6+_RobotTrees+(_RobotTrees*_ContactDoF)+1> matrixConjType;
773 Eigen::FullPivLU<matrixAType> lu_decompA(unknownA);
774 std::cout <<
"[MOTION_MODEL] The rank of A is " << lu_decompA.rank() << std::endl;
776 Eigen::FullPivLU<matrixBType> lu_decompB(knownB);
777 std::cout <<
"[MOTION_MODEL] The rank of B is " << lu_decompB.rank() << std::endl;
779 Conj.template block<6*_RobotTrees,6+_RobotTrees+(_RobotTrees*_ContactDoF)>(0,0) = unknownA;
780 Conj.template block<6*_RobotTrees, 1>(0,_RobotTrees+(_RobotTrees*_ContactDoF)) = knownb;
781 Eigen::FullPivLU<matrixConjType> lu_decompConj(Conj);
782 std::cout <<
"[MOTION_MODEL] The rank of A|B*y is " << lu_decompConj.rank() << std::endl;
783 std::cout <<
"[MOTION_MODEL] Pseudoinverse of A\n" << (unknownA.transpose() * Weight * unknownA).inverse() << std::endl;
787 unknownx = (unknownA.transpose() * Weight * unknownA).ldlt().solve(unknownA.transpose() * Weight * knownb);
790 Eigen::Matrix<double, 1,1> squaredError = (((unknownA*unknownx - knownb).transpose() * Weight * (unknownA*unknownx - knownb)));
791 if (knownb.norm() != 0.00)
792 normalizedError = sqrt(squaredError[0]) / knownb.norm();
795 Eigen::Matrix <_Scalar, 6*_RobotTrees, 6*_RobotTrees> errorCov;
796 Eigen::Matrix <_Scalar, 6+_RobotTrees+(_RobotTrees*_ContactDoF), 6+_RobotTrees+(_RobotTrees*_ContactDoF)> uncertaintyCov;
797 errorCov = 0.6827 * squaredError[0] * Eigen::Matrix <_Scalar, 6*_RobotTrees, 6*_RobotTrees>::Identity();
798 uncertaintyCov = (unknownA.transpose() * errorCov.inverse() * unknownA).inverse();
801 cartesianVelocities.template block<3, 1>(0,0) = unknownx.template block<3, 1>(0,0);
802 cartesianVelocities.template block<3, 1>(3,0) = unknownx.template block<3, 1>(3,0);
803 cartesianVelCov = uncertaintyCov.template block<6,6>(0,0);
806 for (
register int i=0; i<_RobotTrees; ++i)
808 modelVelocities[_RobotJointDoF+(_SlipDoF*(i+1)-1)] = unknownx[6+i];
809 modelVelCov.col(_RobotJointDoF+(_SlipDoF*(i+1)-1))[_RobotJointDoF+(_SlipDoF*(i+1)-1)] = uncertaintyCov.col(6+i)[6+i];
813 for (
register int i=0; i<(_RobotTrees*_ContactDoF); ++i)
815 modelVelocities[_RobotJointDoF+(_RobotTrees*_SlipDoF)+i] = unknownx[6+_RobotTrees+i];
816 modelVelCov.col(_RobotJointDoF+(_RobotTrees*_SlipDoF)+i)[_RobotJointDoF+(_RobotTrees*_SlipDoF)+i] = uncertaintyCov.col(6+_RobotTrees+i)[6+_RobotTrees+i];
819 #ifdef DEBUG_PRINTS_ODOMETRY_MOTION_MODEL
820 std::cout <<
"[MOTION_MODEL] L-S solution:\n"<<unknownx<<std::endl;
822 std::cout <<
"[MOTION_MODEL] cartesianVelocities is of size "<<cartesianVelocities.rows()<<
"x"<<cartesianVelocities.cols()<<
"\n";
823 std::cout <<
"[MOTION_MODEL] cartesianVelocities is \n" << cartesianVelocities<< std::endl;
825 std::cout <<
"[MOTION_MODEL] cartesianVelCov is of size "<<cartesianVelCov.rows()<<
"x"<<cartesianVelCov.cols()<<
"\n";
826 std::cout <<
"[MOTION_MODEL] cartesianVelCov is \n" << cartesianVelCov<< std::endl;
828 std::cout <<
"[MOTION_MODEL] modelVelocities is of size "<<modelVelocities.rows()<<
"x"<<modelVelocities.cols()<<
"\n";
829 std::cout <<
"[MOTION_MODEL] modelVelocities is \n" << modelVelocities<< std::endl;
831 std::cout <<
"[MOTION_MODEL] modelVelCov is of size "<<modelVelCov.rows()<<
"x"<<modelVelCov.cols()<<
"\n";
832 std::cout <<
"[MOTION_MODEL] modelVelCov is \n" << modelVelCov<< std::endl;
834 std::cout <<
"[MOTION_MODEL] The absolute least squared error is:\n" << squaredError << std::endl;
835 std::cout <<
"[MOTION_MODEL] The relative error is:\n" << normalizedError << std::endl;
839 return normalizedError;
855 template<
typename _Derived>
856 static inline bool isnotnan(
const Eigen::MatrixBase<_Derived>& x)
858 return ((x.array() == x.array())).all();
863 #endif //ODOMETRY_MOTION_MODEL_HPP
void navEquationsNoAngVelo(const Eigen::Matrix< _Scalar, 6, 1 > &cartesianVelocities, const Eigen::Matrix< _Scalar, MODEL_DOF, 1 > &modelVelocities, const Eigen::Matrix< _Scalar, 6 *_RobotTrees, MODEL_DOF > &J, const Eigen::Matrix< _Scalar, 6, 6 > &cartesianVelCov, const Eigen::Matrix< _Scalar, MODEL_DOF, MODEL_DOF > &modelVelCov, Eigen::Matrix< _Scalar, 6 *_RobotTrees, 6+_RobotTrees+(_RobotTrees *_ContactDoF)> &unknownA, Eigen::Matrix< _Scalar, 6+_RobotTrees+(_RobotTrees *_ContactDoF), 1 > &unknownx, Eigen::Matrix< _Scalar, 6 *_RobotTrees, _RobotJointDoF > &knownB, Eigen::Matrix< _Scalar, _RobotJointDoF, 1 > &knowny, Eigen::Matrix< _Scalar, 6 *_RobotTrees, 6 *_RobotTrees > &Weight)
Forms the Navigation Equations for the navigation kinematics(angular velocities are unknow variables)...
Definition: MotionModel.hpp:337
std::vector< base::Matrix6d > fkCov
Definition: MotionModel.hpp:124
MotionModel(bool &status, MotionModel::methodContactPoint method, kinematics_ptr robotModel)
Constructor.
Definition: MotionModel.hpp:414
methodContactPoint contactSelection
Definition: MotionModel.hpp:121
methodContactPoint
Definition: MotionModel.hpp:115
void selectPointsInContact(MotionModel::methodContactPoint method)
this method computes the point in contact depending on the method.
Definition: MotionModel.hpp:207
static const int NO_CONTACT
Definition: MotionModel.hpp:102
void updateKinematics(const Eigen::Matrix< _Scalar, MODEL_DOF, 1 > &modelPositions)
Updates the Kinematic Model of the robot.
Definition: MotionModel.hpp:482
std::vector< Eigen::Affine3d > fkRobot
Definition: MotionModel.hpp:123
virtual std::vector< int > getPointsInContact()
Return the current points in contact.
Definition: MotionModel.hpp:527
virtual void getKinematics(std::vector< Eigen::Affine3d > ¤tFkRobot, std::vector< base::Matrix6d > ¤tFkCov)
Returns the kinematic of the robot.
Definition: MotionModel.hpp:514
static const unsigned int MODEL_DOF
Definition: MotionModel.hpp:99
Kinematic Model Abstract class.
static const unsigned int MAX_CHAIN_DOF
Definition: MotionModel.hpp:96
Definition: MotionModel.hpp:118
virtual base::Vector6d slipSolver(void)
Solver for the Slip equations TO-DO.
Definition: MotionModel.hpp:844
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: ContactOdometry.hpp:15
Definition: MotionModel.hpp:93
MotionModel()
Default constructor.
Definition: MotionModel.hpp:401
Definition: MotionModel.hpp:117
void lowestPointInContact()
computes the current set of points in contact choosing the lowest point.
Definition: MotionModel.hpp:143
void navEquations(const Eigen::Matrix< _Scalar, 6, 1 > &cartesianVelocities, const Eigen::Matrix< _Scalar, MODEL_DOF, 1 > &modelVelocities, const Eigen::Matrix< _Scalar, 6 *_RobotTrees, MODEL_DOF > &J, const Eigen::Matrix< _Scalar, 6, 6 > &cartesianVelCov, const Eigen::Matrix< _Scalar, MODEL_DOF, MODEL_DOF > &modelVelCov, Eigen::Matrix< _Scalar, 6 *_RobotTrees, 3+_RobotTrees+(_RobotTrees *_ContactDoF)> &unknownA, Eigen::Matrix< _Scalar, 3+_RobotTrees+(_RobotTrees *_ContactDoF), 1 > &unknownx, Eigen::Matrix< _Scalar, 6 *_RobotTrees, 3+_RobotJointDoF > &knownB, Eigen::Matrix< _Scalar, 3+_RobotJointDoF, 1 > &knowny, Eigen::Matrix< _Scalar, 6 *_RobotTrees, 6 *_RobotTrees > &Weight)
Forms the Navigation Equations for the navigation kinematics.
Definition: MotionModel.hpp:252
void combinatoricsPointInContact()
Computes the points in contact using combinatorics.
Definition: MotionModel.hpp:197
boost::shared_ptr< KinematicModel< _Scalar, _RobotTrees, _RobotJointDoF, _SlipDoF, _ContactDoF > > kinematics_ptr
Definition: MotionModel.hpp:106
std::vector< TreeContactPoint > contactPoints
Definition: MotionModel.hpp:125
kinematics_ptr robotModel
Definition: MotionModel.hpp:122
~MotionModel()
Default destructor.
Definition: MotionModel.hpp:472
virtual double navSolverNoAngVelo(const Eigen::Matrix< _Scalar, MODEL_DOF, 1 > &modelPositions, Eigen::Matrix< _Scalar, 6, 1 > &cartesianVelocities, Eigen::Matrix< _Scalar, MODEL_DOF, 1 > &modelVelocities, Eigen::Matrix< _Scalar, 6, 6 > &cartesianVelCov, Eigen::Matrix< _Scalar, MODEL_DOF, MODEL_DOF > &modelVelCov, Eigen::Matrix< _Scalar, 6 *_RobotTrees, 6 *_RobotTrees > Weight)
Definition: MotionModel.hpp:719
virtual double navSolver(const Eigen::Matrix< _Scalar, MODEL_DOF, 1 > &modelPositions, Eigen::Matrix< _Scalar, 6, 1 > &cartesianVelocities, Eigen::Matrix< _Scalar, MODEL_DOF, 1 > &modelVelocities, Eigen::Matrix< _Scalar, 6, 6 > &cartesianVelCov, Eigen::Matrix< _Scalar, MODEL_DOF, MODEL_DOF > &modelVelCov, Eigen::Matrix< _Scalar, 6 *_RobotTrees, 6 *_RobotTrees > Weight)
Definition: MotionModel.hpp:559