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
34namespace 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
constexpr T c
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPosition class.
Definition FramedPose.h:158
The LinkedPose class.
Definition LinkedPose.h:61
The MatrixFloat class.
The Variant class is described here: Variants.
Definition Variant.h:224
std::recursive_mutex motionPredictionLock
void savePredictedPoseAtStartOfCurrentLocalization(const Ice::Current &=Ice::emptyCurrent) override
AbstractMotionModel(armarx::RobotStateComponentInterfacePrx robotStateProxy)
void setPoseAtLastLocalisation(const armarx::LinkedPoseBasePtr &poseAtLastLocalization, const armarx::PoseBasePtr &globalRobotPoseAtLastLocalization, const MultivariateNormalDistributionBasePtr &uncertaintyAtLastLocalization, const Ice::Current &c=Ice::emptyCurrent) override
MultivariateNormalDistributionBasePtr getUncertaintyInternal() override
void savePredictedPoseAtStartOfCurrentLocalization(const Ice::Current &c=Ice::emptyCurrent) override
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:216
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
void handleExceptions()
IceInternal::Handle< LinkedPose > LinkedPosePtr
Definition LinkedPose.h:52
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
VirtualRobot headers.