MotionModelRobotHand.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  */
24 #include "MotionModelRobotHand.h"
25 
27 
29 
30 
31 namespace memoryx
32 {
34  {
35  this->handNodeName = handNodeName;
36  syncedRobot = robotStateProxy->getSynchronizedRobot();
37  robotName = syncedRobot->getName();
38  }
39 
40 
42  {
43  ARMARX_DEBUG_S << "robot name of last pose: " << poseAtLastLocalization->referenceRobot->getName();
44  ARMARX_DEBUG_S << "robot name of internal proxy: " << robotStateProxy->getRobotName();
45  //armarx::PosePtr oldHandNodePose = armarx::PosePtr::dynamicCast(poseAtLastLocalization->referenceRobot->getRobotNode(handNodeName)->getPoseInRootFrame());
46  armarx::PosePtr oldHandNodePose = armarx::PosePtr::dynamicCast(poseAtLastLocalization->referenceRobot->getRobotNode(handNodeName)->getGlobalPose());
47 
48  armarx::SharedRobotInterfacePrx currentRobotSnapshot = robotStateProxy->getRobotSnapshot(robotName);
49  //armarx::PosePtr newHandNodePose = armarx::PosePtr::dynamicCast(currentRobotSnapshot->getRobotNode(handNodeName)->getPoseInRootFrame());
50  armarx::PosePtr newHandNodePose = armarx::PosePtr::dynamicCast(currentRobotSnapshot->getRobotNode(handNodeName)->getGlobalPose());
51 
52  Eigen::Matrix4f transformationOldToNewInRootFrame = newHandNodePose->toEigen() * oldHandNodePose->toEigen().inverse();
53  Eigen::Vector3f kinPosDelta = newHandNodePose->toEigen().block<3, 1>(0, 3) - oldHandNodePose->toEigen().block<3, 1>(0, 3);
54  //Eigen::Matrix4f lastLocalization = armarx::LinkedPosePtr::dynamicCast(poseAtLastLocalization)->toRootEigen(poseAtLastLocalization->referenceRobot);
55  Eigen::Matrix4f lastLocalization = armarx::LinkedPosePtr::dynamicCast(poseAtLastLocalization)->toGlobalEigen(poseAtLastLocalization->referenceRobot);
57 
58  predictedPose.block<3, 3>(0, 0) = transformationOldToNewInRootFrame.block<3, 3>(0, 0) * lastLocalization.block<3, 3>(0, 0);
59  predictedPose.block<3, 1>(0, 3) = kinPosDelta + lastLocalization.block<3, 1>(0, 3);
60 
61  if (poseAtLastLocalization->frame.empty())
62  {
63  ARMARX_INFO_S << "poseAtLastLocalization->frame is empty!";
64  }
65 
66  //armarx::LinkedPosePtr ret = new armarx::LinkedPose(predictedPose, poseAtLastLocalization->frame, currentRobotSnapshot);
67  //armarx::LinkedPosePtr ret = new armarx::LinkedPose(predictedPose, currentRobotSnapshot->getRootNode()->getName(), currentRobotSnapshot);
68  //ret->changeToGlobal();
69  armarx::LinkedPosePtr ret = new armarx::LinkedPose(predictedPose, armarx::GlobalFrame, currentRobotSnapshot);
70  return ret;
71  }
72 
73 
74 
75  MultivariateNormalDistributionBasePtr MotionModelRobotHand::getUncertaintyInternal()
76  {
77  if (uncertaintyAtLastLocalization)
78  {
79  armarx::PosePtr oldHandNodePose = armarx::PosePtr::dynamicCast(poseAtLastLocalization->referenceRobot->getRobotNode(handNodeName)->getPoseInRootFrame());
80  armarx::PosePtr newHandNodePose = armarx::PosePtr::dynamicCast(syncedRobot->getRobotNode(handNodeName)->getPoseInRootFrame());
81 
82  // additional uncertainty is 0.07 * the distance that the hand moved since the last localization
83  float dist = (oldHandNodePose->toEigen().block<3, 1>(0, 3) - newHandNodePose->toEigen().block<3, 1>(0, 3)).norm();
84  dist *= 0.07;
85  Eigen::Matrix3f additionalUncertainty = dist * dist * Eigen::Matrix3f::Identity();
86 
87  Eigen::Matrix3f oldUncertainty = MultivariateNormalDistributionPtr::dynamicCast(uncertaintyAtLastLocalization)->toEigenCovariance();
88  Eigen::Matrix3f newUncertainty = oldUncertainty + additionalUncertainty;
89 
90  return new MultivariateNormalDistribution(armarx::Vector3Ptr::dynamicCast(poseAtLastLocalization->position)->toEigen(), newUncertainty);
91  }
92  else
93  {
94  return NULL;
95  }
96  }
97 
98  void MotionModelRobotHand::setPoseAtLastLocalisation(const armarx::LinkedPoseBasePtr& poseAtLastLocalization, const armarx::PoseBasePtr& globalRobotPoseAtLastLocalization, const MultivariateNormalDistributionBasePtr& uncertaintyAtLastLocalization, const Ice::Current& c)
99  {
100  std::unique_lock lock(motionPredictionLock);
101  AbstractMotionModel::setPoseAtLastLocalisation(poseAtLastLocalization, globalRobotPoseAtLastLocalization,
102  uncertaintyAtLastLocalization, c);
103  ARMARX_DEBUG_S << "MotionModelRobotHand::setPoseAtLastLocalisation" << this->poseAtLastLocalization->referenceRobot->getName();
104  if (robotStateProxy->getRobotName() != this->poseAtLastLocalization->referenceRobot->getName())
105  {
106  ARMARX_DEBUG_S << "Setting robot state proxy from " << this->poseAtLastLocalization->agent << " to " << robotName;
107  this->poseAtLastLocalization = new armarx::LinkedPose(armarx::LinkedPosePtr::dynamicCast(this->poseAtLastLocalization)->toEigen(), armarx::GlobalFrame, robotStateProxy->getRobotSnapshot(robotName));
108  }
109  }
110 
111 }
MotionModelRobotHand.h
memoryx::MotionModelRobotHand::getPredictedPoseInternal
armarx::LinkedPosePtr getPredictedPoseInternal() override
Definition: MotionModelRobotHand.cpp:41
memoryx::MotionModelRobotHand::setPoseAtLastLocalisation
void setPoseAtLastLocalisation(const armarx::LinkedPoseBasePtr &poseAtLastLocalization, const armarx::PoseBasePtr &globalRobotPoseAtLastLocalization, const MultivariateNormalDistributionBasePtr &uncertaintyAtLastLocalization, const Ice::Current &c=Ice::emptyCurrent) override
Definition: MotionModelRobotHand.cpp:98
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
memoryx::MotionModelRobotHand::getUncertaintyInternal
MultivariateNormalDistributionBasePtr getUncertaintyInternal() override
Definition: MotionModelRobotHand.cpp:75
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:62
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::MotionModelRobotHand::MotionModelRobotHand
MotionModelRobotHand()
Definition: MotionModelRobotHand.h:53
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::VariantType::LinkedPose
const VariantTypeId LinkedPose
Definition: LinkedPose.h:43
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:198
memoryx::AbstractMotionModel
Definition: AbstractMotionModel.h:39
memoryx::AbstractMotionModel::setPoseAtLastLocalisation
void setPoseAtLastLocalisation(const armarx::LinkedPoseBasePtr &poseAtLastLocalization, const armarx::PoseBasePtr &globalRobotPoseAtLastLocalization, const MultivariateNormalDistributionBasePtr &uncertaintyAtLastLocalization, const Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractMotionModel.cpp:39
memoryx::AbstractMotionModel::motionPredictionLock
std::recursive_mutex motionPredictionLock
Definition: AbstractMotionModel.h:95
ProbabilityMeasures.h
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
memoryx::MotionModelRobotHand::syncedRobot
armarx::SharedRobotInterfacePrx syncedRobot
Definition: MotionModelRobotHand.h:49
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
Logging.h
memoryx::MotionModelRobotHand::robotName
std::string robotName
Definition: MotionModelRobotHand.h:48
armarx::VariantType::MultivariateNormalDistribution
const armarx::VariantTypeId MultivariateNormalDistribution
Definition: ProbabilityMeasures.h:36