MotionModelBodySchema.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 "MotionModelBodySchema.h"
25 
26 #include <boost/foreach.hpp>
27 
29 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
30 
31 namespace memoryx
32 {
35  std::string handNodeName,
36  LongtermMemoryInterfacePrx longtermMemory) :
37  AbstractMotionModel(robotStateProxy)
38  {
39  armarx::SharedRobotInterfacePrx currentRobotSnapshot =
40  robotStateProxy->getRobotSnapshot("MotionModelBodySchemaPrediction");
41  armarx::SharedRobotNodeInterfacePrx handNode =
42  currentRobotSnapshot->getRobotNode(handNodeName);
43 
44  this->longtermMemory = longtermMemory;
45  // obtain the kinematic chain
46 
47  //TODO: how to get the desired frame?? probably only possible in SetPoseAtLastLocalisation()?
48  std::string parentName = handNode->getParent();
49 
50  while (!parentName.empty())
51  {
52  armarx::SharedRobotNodeInterfacePrx node =
53  currentRobotSnapshot->getRobotNode(parentName);
54 
55  if (node->getType() == armarx::eRevolute)
56  {
57  this->parentNodeNames.push_back(parentName);
58  }
59 
60  parentName = node->getParent();
61  }
62 
63  this->model.reset(new KBM(parentNodeNames.size(), 16, 3.14 / 4.0));
64 
65  // Load from longterm memory
66  }
67 
69  {
70  // Store to Longtermmemory
71  }
72 
75  {
76  armarx::PosePtr oldHandNodePose = armarx::PosePtr::dynamicCast(
77  poseAtLastLocalization->referenceRobot->getRobotNode(handNodeName)->getGlobalPose());
78  armarx::PosePtr oldGlobalPoseOfFrame = armarx::PosePtr::dynamicCast(
79  poseAtLastLocalization->referenceRobot->getRobotNode(poseAtLastLocalization->frame)
80  ->getGlobalPose());
81 
82  armarx::SharedRobotInterfacePrx currentRobotSnapshot =
83  robotStateProxy->getRobotSnapshot("MotionModelBodySchemaPrediction");
84 
85  // set the proprioception vector
86  Eigen::VectorXf proprioception(this->parentNodeNames.size());
87  unsigned int index = 0;
88  BOOST_FOREACH (std::string nodeName, this->parentNodeNames)
89  {
90  proprioception(index) = currentRobotSnapshot->getRobotNode(nodeName)->getJointValue();
91  index++;
92  }
93 
94  Eigen::VectorXf predictionXf = this->model->predict(proprioception);
95  Eigen::Matrix4f prediction = Eigen::Matrix4f::Map(predictionXf.data());
96 
98  prediction, currentRobotSnapshot->getRootNode()->getName(), currentRobotSnapshot);
99  return ret;
100  }
101 
102  void
104  const armarx::LinkedPoseBasePtr& poseAtLastLocalization,
105  const armarx::PoseBasePtr& globalRobotPoseAtLastLocalization,
106  const Ice::Current& c)
107  {
108  boost::mutex::scoped_lock lock(motionPredictionLock);
109 
110  // get the shape|extereoception|input vector
111  this->poseAtLastLocalization = poseAtLastLocalization;
112  this->globalRobotPoseAtLastLocalization = globalRobotPoseAtLastLocalization;
113 
114  Eigen::Matrix4f mat =
115  armarx::LinkedPosePtr::dynamicCast(this->poseAtLastLocalization)->toEigen();
116 
117  // Transform matrix to column vector
118  Eigen::VectorXf shape = Eigen::VectorXf::Map(mat.data(), mat.rows() * mat.cols());
119 
120  armarx::SharedRobotNodeInterfacePrx handNode =
121  poseAtLastLocalization->referenceRobot->getRobotNode(handNodeName);
122 
123  // set the proprioception vector
124  Eigen::VectorXf proprioception(this->parentNodeNames.size());
125  unsigned int index = 0;
126  BOOST_FOREACH (std::string nodeName, this->parentNodeNames)
127  {
128  proprioception(index) =
129  poseAtLastLocalization->referenceRobot->getRobotNode(nodeName)->getJointValue();
130  index++;
131  }
132 
133  this->model->online(proprioception, shape);
134  }
135 
136  memoryx::MultivariateNormalDistributionBasePtr
138  {
139  if (uncertaintyAtLastLocalization)
140  {
141  return uncertaintyAtLastLocalization;
142  }
143  else
144  {
145  return NULL;
146  }
147  }
148 
149 } // namespace memoryx
memoryx::MotionModelBodySchema::GetPredictedPoseInternal
virtual armarx::LinkedPosePtr GetPredictedPoseInternal()
Definition: MotionModelBodySchema.cpp:74
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
memoryx::MotionModelBodySchema::SetPoseAtLastLocalisation
virtual void SetPoseAtLastLocalisation(const armarx::LinkedPoseBasePtr &poseAtLastLocalization, const armarx::PoseBasePtr &globalRobotPoseAtLastLocalization, const Ice::Current &c=Ice::emptyCurrent)
Definition: MotionModelBodySchema.cpp:103
memoryx::MotionModelBodySchema::parentNodeNames
armarx::NameList parentNodeNames
Definition: MotionModelBodySchema.h:59
index
uint8_t index
Definition: EtherCATFrame.h:59
memoryx::MotionModelBodySchema::handNodeName
std::string handNodeName
Definition: MotionModelBodySchema.h:57
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::VariantType::Map
const VariantContainerType Map
Definition: StringValueMap.h:263
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
memoryx::MotionModelBodySchema::~MotionModelBodySchema
~MotionModelBodySchema()
Definition: MotionModelBodySchema.cpp:68
IceInternal::Handle
Definition: forward_declarations.h:8
MotionModelBodySchema.h
armarx::VariantType::LinkedPose
const VariantTypeId LinkedPose
Definition: LinkedPose.h:43
memoryx::MotionModelBodySchema::longtermMemory
LongtermMemoryInterfacePrx longtermMemory
Definition: MotionModelBodySchema.h:60
memoryx::AbstractMotionModel
Definition: AbstractMotionModel.h:39
memoryx::MotionModelBodySchema::model
std::shared_ptr< memoryx::KBM > model
Definition: MotionModelBodySchema.h:52
memoryx::MotionModelBodySchema::getUncertaintyInternal
virtual MultivariateNormalDistributionBasePtr getUncertaintyInternal()
Definition: MotionModelBodySchema.cpp:137
memoryx::AbstractMotionModel::motionPredictionLock
std::recursive_mutex motionPredictionLock
Definition: AbstractMotionModel.h:100
ProbabilityMeasures.h
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
memoryx::MotionModelBodySchema::MotionModelBodySchema
MotionModelBodySchema(armarx::RobotStateComponentInterfacePrx robotStateProxy, std::string handNodeName, LongtermMemoryInterfacePrx longtermMemory)
Definition: MotionModelBodySchema.cpp:33