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 
27 
28 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
29 
30 namespace memoryx
31 {
34  AbstractMotionModel(robotStateProxy)
35  {
36  }
37 
38  // 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 =
65  robotStateProxy->getRobotSnapshot(robotStateProxy->getRobotName());
67  new armarx::LinkedPose(newPose->toEigen(), newPose->frame, currentRobotSnapshot);
68  ret->changeFrame(oldFrameName);
69  return ret;
70  }
71 
72  memoryx::MultivariateNormalDistributionBasePtr
74  {
76 
77  ARMARX_DEBUG_S << "MotionModelStaticObject::getUncertaintyInternal()";
78 
79  if (uncertaintyAtLastLocalization)
80  {
81  // uncertainty is increased proportionally to robot motion in the world
82  Eigen::Matrix4f oldRobotPose, newRobotPose;
83  getOldAndNewRobotPose(oldRobotPose, newRobotPose);
84  const float positionDistance =
85  (oldRobotPose.block<3, 1>(0, 3) - newRobotPose.block<3, 1>(0, 3)).norm();
86  const float positionChangeUncertaintyFactor = 0.1 * positionDistance;
87  float additionalUncertaintyFactor = positionChangeUncertaintyFactor;
88  ARMARX_DEBUG_S << "positionChangeUncertaintyFactor: "
89  << positionChangeUncertaintyFactor;
90 
91  // uncertainty also increases slowly over time
92  IceUtil::Time timeAtLastLocalization =
93  armarx::TimestampVariantPtr::dynamicCast(timeOfLastSuccessfulLocalization)
94  ->toTime();
95  IceUtil::Time timeSinceLastLocalization = IceUtil::Time::now() - timeAtLastLocalization;
96  const float timeUncertaintyFactor =
97  0.0005 * abs(timeSinceLastLocalization.toMilliSeconds()); // 0.5mm per second
98  additionalUncertaintyFactor += timeUncertaintyFactor;
99  ARMARX_DEBUG_S << "timeUncertaintyFactor: " << timeUncertaintyFactor;
100 
101  Eigen::Matrix3f additionalUncertainty = additionalUncertaintyFactor *
102  additionalUncertaintyFactor *
104  Eigen::Matrix3f oldUncertainty =
105  MultivariateNormalDistributionPtr::dynamicCast(uncertaintyAtLastLocalization)
106  ->toEigenCovariance();
107  Eigen::Matrix3f newUncertainty = oldUncertainty + additionalUncertainty;
108 
109  ARMARX_DEBUG_S << "oldUncertainty: " << oldUncertainty;
110  ARMARX_DEBUG_S << "additionalUncertainty: " << additionalUncertainty;
111  ARMARX_DEBUG_S << "newUncertainty: " << newUncertainty;
112 
113  result = new MultivariateNormalDistribution(
114  armarx::Vector3Ptr::dynamicCast(poseAtLastLocalization->position)->toEigen(),
115  newUncertainty);
116  }
117 
118  return result;
119  }
120 
121  void
123  Eigen::Matrix4f& newRobotPose)
124  {
125  oldRobotPose = Eigen::Matrix4f::Identity();
126  newRobotPose = Eigen::Matrix4f::Identity();
127 
128  if (globalRobotPoseAtLastLocalization)
129  {
130  oldRobotPose =
131  armarx::PosePtr::dynamicCast(globalRobotPoseAtLastLocalization)->toEigen();
132  newRobotPose = armarx::PosePtr::dynamicCast(
133  robotStateProxy->getSynchronizedRobot()->getGlobalPose())
134  ->toEigen();
135  }
136  }
137 
138 } // namespace memoryx
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
memoryx::MotionModelStaticObject::getOldAndNewRobotPose
void getOldAndNewRobotPose(Eigen::Matrix4f &oldRobotPose, Eigen::Matrix4f &newRobotPose)
Definition: MotionModelStaticObject.cpp:122
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
memoryx::MotionModelStaticObject::MotionModelStaticObject
MotionModelStaticObject()
Definition: MotionModelStaticObject.h:55
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:570
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:281
armarx::VariantType::LinkedPose
const VariantTypeId LinkedPose
Definition: LinkedPose.h:43
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:205
MotionModelStaticObject.h
memoryx::AbstractMotionModel
Definition: AbstractMotionModel.h:39
memoryx::MotionModelStaticObject::getUncertaintyInternal
MultivariateNormalDistributionBasePtr getUncertaintyInternal() override
Definition: MotionModelStaticObject.cpp:73
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
Logging.h
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
memoryx::MotionModelStaticObject::getPredictedPoseInternal
armarx::LinkedPosePtr getPredictedPoseInternal() override
Definition: MotionModelStaticObject.cpp:40
armarx::VariantType::MultivariateNormalDistribution
const armarx::VariantTypeId MultivariateNormalDistribution
Definition: ProbabilityMeasures.h:40
norm
double norm(const Point &a)
Definition: point.hpp:102