MotionModelStaticObject.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
25 
26 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
27 
29 
30 
31 namespace memoryx
32 {
34  {
35  }
36 
37 
38 
39  // predicted pose that is constant in the world coordinate frame
41  {
42  // // get old and new transformation to robot root frame
43  // armarx::PosePtr oldGlobalPoseOfFrame = armarx::PosePtr::dynamicCast(poseAtLastLocalization->referenceRobot->getRobotNode(poseAtLastLocalization->frame)->getPoseInRootFrame());
44  // Eigen::Matrix4f oldTrafoToRootCS = oldGlobalPoseOfFrame->toEigen();
45 
46  // armarx::SharedRobotInterfacePrx currentRobotSnapshot = robotStateProxy->getRobotSnapshot(robotStateProxy->getSynchronizedRobot()->getName());
47  // armarx::PosePtr newGlobalPoseOfFrame = armarx::PosePtr::dynamicCast(currentRobotSnapshot->getRobotNode(poseAtLastLocalization->frame)->getPoseInRootFrame());
48  // Eigen::Matrix4f newTrafoToRootCS = newGlobalPoseOfFrame->toEigen();
49 
50  // // get robot pose in world coordinates, if available
51  // Eigen::Matrix4f oldRobotPose, newRobotPose;
52  // getOldAndNewRobotPose(oldRobotPose, newRobotPose);
53 
54  // Eigen::Matrix4f predictedPose = newTrafoToRootCS.inverse()*newRobotPose.inverse()*oldRobotPose*oldTrafoToRootCS*armarx::LinkedPosePtr::dynamicCast(poseAtLastLocalization)->toEigen();
55 
56  // armarx::LinkedPosePtr ret = new armarx::LinkedPose(predictedPose, poseAtLastLocalization->frame, currentRobotSnapshot);
57  // return ret;
58 
59  armarx::LinkedPosePtr pose = armarx::LinkedPosePtr::dynamicCast(poseAtLastLocalization);
60  std::string oldFrameName = pose->frame;
61  armarx::FramedPosePtr newPose = pose->toGlobal();
62  // newPose->changeFrame(currentRobotSnapshot, poseAtLastLocalization->frame);
63 
64  armarx::SharedRobotInterfacePrx currentRobotSnapshot = robotStateProxy->getRobotSnapshot(robotStateProxy->getRobotName());
65  armarx::LinkedPosePtr ret = new armarx::LinkedPose(newPose->toEigen(), newPose->frame, currentRobotSnapshot);
66  ret->changeFrame(oldFrameName);
67  return ret;
68  }
69 
70 
71 
72  memoryx::MultivariateNormalDistributionBasePtr MotionModelStaticObject::getUncertaintyInternal()
73  {
75 
76  ARMARX_DEBUG_S << "MotionModelStaticObject::getUncertaintyInternal()";
77 
78  if (uncertaintyAtLastLocalization)
79  {
80  // uncertainty is increased proportionally to robot motion in the world
81  Eigen::Matrix4f oldRobotPose, newRobotPose;
82  getOldAndNewRobotPose(oldRobotPose, newRobotPose);
83  const float positionDistance = (oldRobotPose.block<3, 1>(0, 3) - newRobotPose.block<3, 1>(0, 3)).norm();
84  const float positionChangeUncertaintyFactor = 0.1 * positionDistance;
85  float additionalUncertaintyFactor = positionChangeUncertaintyFactor;
86  ARMARX_DEBUG_S << "positionChangeUncertaintyFactor: " << positionChangeUncertaintyFactor;
87 
88  // uncertainty also increases slowly over time
89  IceUtil::Time timeAtLastLocalization = armarx::TimestampVariantPtr::dynamicCast(timeOfLastSuccessfulLocalization)->toTime();
90  IceUtil::Time timeSinceLastLocalization = IceUtil::Time::now() - timeAtLastLocalization;
91  const float timeUncertaintyFactor = 0.0005 * abs(timeSinceLastLocalization.toMilliSeconds()); // 0.5mm per second
92  additionalUncertaintyFactor += timeUncertaintyFactor;
93  ARMARX_DEBUG_S << "timeUncertaintyFactor: " << timeUncertaintyFactor;
94 
95  Eigen::Matrix3f additionalUncertainty = additionalUncertaintyFactor * additionalUncertaintyFactor * Eigen::Matrix3f::Identity();
96  Eigen::Matrix3f oldUncertainty = MultivariateNormalDistributionPtr::dynamicCast(uncertaintyAtLastLocalization)->toEigenCovariance();
97  Eigen::Matrix3f newUncertainty = oldUncertainty + additionalUncertainty;
98 
99  ARMARX_DEBUG_S << "oldUncertainty: " << oldUncertainty;
100  ARMARX_DEBUG_S << "additionalUncertainty: " << additionalUncertainty;
101  ARMARX_DEBUG_S << "newUncertainty: " << newUncertainty;
102 
103  result = new MultivariateNormalDistribution(armarx::Vector3Ptr::dynamicCast(poseAtLastLocalization->position)->toEigen(), newUncertainty);
104  }
105 
106  return result;
107  }
108 
109 
110 
112  {
113  oldRobotPose = Eigen::Matrix4f::Identity();
114  newRobotPose = Eigen::Matrix4f::Identity();
115 
116  if (globalRobotPoseAtLastLocalization)
117  {
118  oldRobotPose = armarx::PosePtr::dynamicCast(globalRobotPoseAtLastLocalization)->toEigen();
119  newRobotPose = armarx::PosePtr::dynamicCast(robotStateProxy->getSynchronizedRobot()->getGlobalPose())->toEigen();
120  }
121  }
122 
123 }
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
memoryx::MotionModelStaticObject::getOldAndNewRobotPose
void getOldAndNewRobotPose(Eigen::Matrix4f &oldRobotPose, Eigen::Matrix4f &newRobotPose)
Definition: MotionModelStaticObject.cpp:111
memoryx::MotionModelStaticObject::MotionModelStaticObject
MotionModelStaticObject()
Definition: MotionModelStaticObject.h:57
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
IceInternal::Handle
Definition: forward_declarations.h:8
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::VariantType::LinkedPose
const VariantTypeId LinkedPose
Definition: LinkedPose.h:43
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:198
MotionModelStaticObject.h
memoryx::AbstractMotionModel
Definition: AbstractMotionModel.h:39
memoryx::MotionModelStaticObject::getUncertaintyInternal
MultivariateNormalDistributionBasePtr getUncertaintyInternal() override
Definition: MotionModelStaticObject.cpp:72
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
Logging.h
memoryx::MotionModelStaticObject::getPredictedPoseInternal
armarx::LinkedPosePtr getPredictedPoseInternal() override
Definition: MotionModelStaticObject.cpp:40
armarx::VariantType::MultivariateNormalDistribution
const armarx::VariantTypeId MultivariateNormalDistribution
Definition: ProbabilityMeasures.h:36
norm
double norm(const Point &a)
Definition: point.hpp:94