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
30namespace memoryx
31{
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 *
103 Eigen::Matrix3f::Identity();
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
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
The LinkedPose class.
Definition LinkedPose.h:61
AbstractMotionModel(armarx::RobotStateComponentInterfacePrx robotStateProxy)
armarx::LinkedPosePtr getPredictedPoseInternal() override
void getOldAndNewRobotPose(Eigen::Matrix4f &oldRobotPose, Eigen::Matrix4f &newRobotPose)
MultivariateNormalDistributionBasePtr getUncertaintyInternal() override
The MultivariateNormalDistribution class.
#define ARMARX_DEBUG_S
The logging level for output that is only interesting while debugging.
Definition Logging.h:205
IceInternal::Handle< LinkedPose > LinkedPosePtr
Definition LinkedPose.h:52
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272
VirtualRobot headers.
IceInternal::Handle< MultivariateNormalDistribution > MultivariateNormalDistributionPtr
double norm(const Point &a)
Definition point.hpp:102