MotionModelAttachedToOtherObject.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 
29 
31 
33 
34 namespace memoryx
35 {
38  armarx::ChannelRefPtr channelRefToObjectToWhichThisIsAttached) :
39  AbstractMotionModel(robotStateProxy)
40  {
41  this->channelRefToObjectToWhichThisIsAttached = channelRefToObjectToWhichThisIsAttached;
42  channelRefIsValid = true;
43 
44  armarx::FramedPositionPtr positionOfAtObj =
45  channelRefToObjectToWhichThisIsAttached->get<armarx::FramedPosition>("position");
46  armarx::FramedOrientationPtr orientationOfAtObj =
47  channelRefToObjectToWhichThisIsAttached->get<armarx::FramedOrientation>("orientation");
48  armarx::LinkedPosePtr poseOfAtObj =
49  new armarx::LinkedPose(orientationOfAtObj->toEigen(),
50  positionOfAtObj->toEigen(),
51  positionOfAtObj->frame,
52  robotStateProxy->getSynchronizedRobot());
53  // ARMARX_INFO_S << VAROUT(*positionOfAtObj);
54  // ARMARX_INFO_S << VAROUT(*poseOfAtObj);
55  Eigen::Matrix4f globalPoseOfAtObj = poseOfAtObj->toGlobal()->toEigen();
56  // ARMARX_INFO_S << VAROUT(globalPoseOfAtObj);
57  initialGlobalPoseOfObjectToWhichThisIsAttached = new armarx::Variant();
58  armarx::VariantPtr::dynamicCast(initialGlobalPoseOfObjectToWhichThisIsAttached)
59  ->setClass(new armarx::MatrixFloat(globalPoseOfAtObj));
60  globalPoseOfObjectToWhichThisIsAttachedAtLocalizationStart = new armarx::Variant();
61  armarx::VariantPtr::dynamicCast(globalPoseOfObjectToWhichThisIsAttachedAtLocalizationStart)
62  ->setClass(new armarx::MatrixFloat(globalPoseOfAtObj));
63  }
64 
67  {
68  if (channelRefIsValid)
69  {
70  try
71  {
72  // ARMARX_INFO_S << VAROUT(*poseAtLastLocalization);
73  armarx::LinkedPosePtr oldPoseGlobal =
74  armarx::LinkedPosePtr::dynamicCast(poseAtLastLocalization)->toGlobal();
75 
76  armarx::SharedRobotInterfacePrx currentRobotSnapshot =
77  robotStateProxy->getRobotSnapshot(
78  robotStateProxy->getSynchronizedRobot()->getName());
79 
80  // determine transformation of the object to which this one is attached in global coordinates
81  armarx::FramedPositionPtr positionOfAtObj =
82  armarx::ChannelRefPtr::dynamicCast(channelRefToObjectToWhichThisIsAttached)
83  ->get<armarx::FramedPosition>("position");
84  armarx::FramedOrientationPtr orientationOfAtObj =
85  armarx::ChannelRefPtr::dynamicCast(channelRefToObjectToWhichThisIsAttached)
86  ->get<armarx::FramedOrientation>("orientation");
87  armarx::LinkedPosePtr poseOfAtObj =
88  new armarx::LinkedPose(orientationOfAtObj->toEigen(),
89  positionOfAtObj->toEigen(),
90  positionOfAtObj->frame,
91  currentRobotSnapshot);
92  armarx::LinkedPosePtr globalPoseOfAtObj = poseOfAtObj->toGlobal();
93  Eigen::Matrix4f initPoseOfAtObj =
94  armarx::VariantPtr::dynamicCast(initialGlobalPoseOfObjectToWhichThisIsAttached)
95  ->getClass<armarx::MatrixFloat>()
96  ->toEigen();
97  Eigen::Matrix4f trafoOfObjectToWhichThisIsAttached =
98  globalPoseOfAtObj->toEigen() * initPoseOfAtObj.inverse();
99 
100  // ARMARX_VERBOSE_S << "new pose: " << globalPoseOfAtObj->toEigen() * initPoseOfAtObj.inverse() * oldPoseGlobal->toEigen();
101 
102  Eigen::Matrix4f predictedPose =
103  trafoOfObjectToWhichThisIsAttached * oldPoseGlobal->toEigen();
104 
106  predictedPose, armarx::GlobalFrame, currentRobotSnapshot);
107 
108  return ret;
109  }
110  catch (...)
111  {
113  channelRefIsValid = false;
114  ARMARX_ERROR_S << "The ChannelRef of the object to which this is attached is not "
115  "valid (anymore). Did you release that object?";
116  }
117  }
118  return armarx::LinkedPosePtr::dynamicCast(poseAtLastLocalization);
119  }
120 
121  void
123  const armarx::LinkedPoseBasePtr& poseAtLastLocalization,
124  const armarx::PoseBasePtr& globalRobotPoseAtLastLocalization,
125  const MultivariateNormalDistributionBasePtr& uncertaintyAtLastLocalization,
126  const Ice::Current& c)
127  {
128  if (channelRefIsValid)
129  {
130  try
131  {
132 
133  std::unique_lock lock(motionPredictionLock);
134  // ARMARX_WARNING_S << "setpose attached: " << VAROUT(*poseAtLastLocalization);
135  this->poseAtLastLocalization = poseAtLastLocalization;
136 
137  // this one is probably unnecessary now
138  this->globalRobotPoseAtLastLocalization = globalRobotPoseAtLastLocalization;
139 
140  initialGlobalPoseOfObjectToWhichThisIsAttached =
141  armarx::VariantPtr::dynamicCast(
142  globalPoseOfObjectToWhichThisIsAttachedAtLocalizationStart)
143  ->clone();
144 
145  if (uncertaintyAtLastLocalization)
146  {
147  this->uncertaintyAtLastLocalization = uncertaintyAtLastLocalization;
148  }
149  }
150  catch (...)
151  {
153  channelRefIsValid = false;
154  ARMARX_ERROR_S << "The ChannelRef of the object to which this is attached is not "
155  "valid (anymore). Did you release that object?";
156  }
157  }
158  }
159 
160  memoryx::MultivariateNormalDistributionBasePtr
162  {
163  if (uncertaintyAtLastLocalization)
164  {
165  return uncertaintyAtLastLocalization;
166  }
167  else
168  {
169  return NULL;
170  }
171  }
172 
173  void
175  const Ice::Current& c)
176  {
178 
179  armarx::FramedPositionPtr positionOfAtObj =
180  armarx::ChannelRefPtr::dynamicCast(channelRefToObjectToWhichThisIsAttached)
181  ->get<armarx::FramedPosition>("position");
182  armarx::FramedOrientationPtr orientationOfAtObj =
183  armarx::ChannelRefPtr::dynamicCast(channelRefToObjectToWhichThisIsAttached)
184  ->get<armarx::FramedOrientation>("orientation");
185  armarx::LinkedPosePtr poseOfAtObj =
186  new armarx::LinkedPose(orientationOfAtObj->toEigen(),
187  positionOfAtObj->toEigen(),
188  positionOfAtObj->frame,
189  poseAtLastLocalization->referenceRobot);
190  armarx::LinkedPosePtr globalPoseOfAtObj = poseOfAtObj->toGlobal();
191  armarx::VariantPtr::dynamicCast(globalPoseOfObjectToWhichThisIsAttachedAtLocalizationStart)
192  ->setClass(new armarx::MatrixFloat(globalPoseOfAtObj->toEigen()));
193  }
194 
195 } // namespace memoryx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
memoryx::MotionModelAttachedToOtherObject::setPoseAtLastLocalisation
void setPoseAtLastLocalisation(const armarx::LinkedPoseBasePtr &poseAtLastLocalization, const armarx::PoseBasePtr &globalRobotPoseAtLastLocalization, const MultivariateNormalDistributionBasePtr &uncertaintyAtLastLocalization, const Ice::Current &c=Ice::emptyCurrent) override
Definition: MotionModelAttachedToOtherObject.cpp:122
LocalException.h
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:48
memoryx::AbstractMotionModel::savePredictedPoseAtStartOfCurrentLocalization
void savePredictedPoseAtStartOfCurrentLocalization(const Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractMotionModel.cpp:63
MatrixVariant.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
Pose.h
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:65
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
memoryx::MotionModelAttachedToOtherObject::getUncertaintyInternal
MultivariateNormalDistributionBasePtr getUncertaintyInternal() override
Definition: MotionModelAttachedToOtherObject.cpp:161
memoryx::MotionModelAttachedToOtherObject::savePredictedPoseAtStartOfCurrentLocalization
void savePredictedPoseAtStartOfCurrentLocalization(const Ice::Current &c=Ice::emptyCurrent) override
Definition: MotionModelAttachedToOtherObject.cpp:174
IceInternal::Handle< ChannelRef >
armarx::VariantType::LinkedPose
const VariantTypeId LinkedPose
Definition: LinkedPose.h:43
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:216
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:157
armarx::MatrixFloat
The MatrixFloat class.
Definition: MatrixVariant.h:48
memoryx::AbstractMotionModel
Definition: AbstractMotionModel.h:39
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:215
MotionModelAttachedToOtherObject.h
memoryx::AbstractMotionModel::motionPredictionLock
std::recursive_mutex motionPredictionLock
Definition: AbstractMotionModel.h:100
memoryx::MotionModelAttachedToOtherObject::MotionModelAttachedToOtherObject
MotionModelAttachedToOtherObject()
Definition: MotionModelAttachedToOtherObject.h:64
ProbabilityMeasures.h
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
Logging.h
armarx::handleExceptions
void handleExceptions()
Definition: Exception.cpp:157
memoryx::MotionModelAttachedToOtherObject::getPredictedPoseInternal
armarx::LinkedPosePtr getPredictedPoseInternal() override
Definition: MotionModelAttachedToOtherObject.cpp:66