LinkedPose.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 "LinkedPose.h"
25 
26 #include <Eigen/Core>
27 #include <Eigen/Geometry>
28 
29 #include <Ice/ObjectAdapter.h>
30 
31 #include <VirtualRobot/LinkedCoordinate.h>
32 #include <VirtualRobot/VirtualRobot.h>
33 
36 
38 
39 namespace armarx
40 {
41 
43  {
44  this->referenceRobot = nullptr;
45  }
46 
48  IceUtil::Shared(other),
49  armarx::Serializable(other),
50  armarx::VariantDataClass(other),
51  PoseBase(other),
52  FramedPoseBase(other),
53  LinkedPoseBase(other),
54  Pose(other),
55  FramedPose(other)
56  {
57  if (referenceRobot)
58  {
59  //ARMARX_WARNING_S << "Calling referenceRobot->ref() in cctor of LinkedPose";
60  referenceRobot->ref();
61  }
62  }
63 
64  LinkedPose::LinkedPose(const FramedPose& other, const SharedRobotInterfacePrx& referenceRobot) :
65  IceUtil::Shared(other),
66  PoseBase(other),
67  FramedPoseBase(other),
68  Pose(other),
69  FramedPose(other)
70  {
71  ARMARX_CHECK_EXPRESSION(referenceRobot) << "The robot proxy must not be zero";
72  this->referenceRobot = referenceRobot;
73 
74  if (referenceRobot)
75  {
76  //ARMARX_WARNING_S << "Calling referenceRobot->ref() in cctor of LinkedPose";
77  referenceRobot->ref();
78  }
79  }
80 
82  const Eigen::Vector3f& v,
83  const std::string& s,
84  const SharedRobotInterfacePrx& referenceRobot) :
85  Pose(m, v), FramedPose(m, v, s, referenceRobot->getName())
86  {
87  ARMARX_CHECK_EXPRESSION(referenceRobot) << "The robot proxy must not be zero";
88  referenceRobot->ref();
89  this->referenceRobot = referenceRobot;
90  }
91 
93  const std::string& s,
94  const SharedRobotInterfacePrx& referenceRobot) :
95  Pose(m), FramedPose(m, s, referenceRobot->getName())
96  {
97  ARMARX_CHECK_EXPRESSION(referenceRobot) << "The robot proxy must not be zero";
98  referenceRobot->ref();
99  this->referenceRobot = referenceRobot;
100  }
101 
103  {
104  try
105  {
106  if (referenceRobot)
107  {
108  referenceRobot->unref();
109  }
110  }
111  catch (...)
112  {
114  }
115  }
116 
117  VirtualRobot::LinkedCoordinate
119  {
120  VirtualRobot::RobotPtr sharedRobot(new RemoteRobot(referenceRobot));
121  VirtualRobot::LinkedCoordinate c(sharedRobot);
122  std::string frame = this->getFrame();
123 
125 
126  pose.block<3, 3>(0, 0) = QuaternionPtr::dynamicCast(orientation)->toEigen();
127  pose.block<3, 1>(0, 3) = Vector3Ptr::dynamicCast(position)->toEigen();
128 
129  c.set(frame, pose);
130 
131  return c;
132  }
133 
136  {
137  return this->clone();
138  }
139 
140  VariantDataClassPtr
141  LinkedPose::clone(const Ice::Current& c) const
142  {
143  return new LinkedPose(*this);
144  }
145 
146  std::string
147  LinkedPose::output(const Ice::Current& c) const
148  {
149  std::stringstream s;
150  s << FramedPose::output() << std::endl
151  << "reference robot: " << referenceRobot->ice_toString();
152  return s.str();
153  }
154 
156  LinkedPose::getType(const Ice::Current& c) const
157  {
159  }
160 
161  bool
162  LinkedPose::validate(const Ice::Current& c)
163  {
164  return true;
165  }
166 
167  void
168  LinkedPose::changeFrame(const std::string& newFrame, const Ice::Current& c)
169  {
170  FramedPose::changeFrame(referenceRobot, newFrame);
171  }
172 
173  void
175  {
176  FramedPose::changeToGlobal(referenceRobot);
177  }
178 
181  {
182  FramedPosePtr fp = this->FramedPose::toGlobal(referenceRobot);
183  LinkedPosePtr newPose = new LinkedPose(fp->toEigen(), fp->frame, referenceRobot);
184  return newPose;
185  }
186 
187  void
188  LinkedPose::serialize(const ObjectSerializerBasePtr& serializer, const ::Ice::Current& c) const
189  {
190  AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
191 
192  Pose::serialize(obj, c);
193  obj->setString("referenceRobot", "");
194  }
195 
196  void
197  LinkedPose::deserialize(const ObjectSerializerBasePtr& serializer, const ::Ice::Current& c)
198  {
199  AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
200 
202 
203  std::string remoteRobotId = obj->getString("referenceRobot");
204  referenceRobot = SharedRobotInterfacePrx::uncheckedCast(
205  c.adapter->getCommunicator()->stringToProxy(remoteRobotId));
206 
207  if (!referenceRobot)
208  {
209  ARMARX_ERROR_S << "ReferenceRobot for LinkedPose not registered: " << remoteRobotId
210  << flush;
211  }
212  }
213 
214  void
216  {
217  if (referenceRobot)
218  {
219  //ARMARX_WARNING_S << "Calling referenceRobot->ref() in __read(IceInternal::BasicStream *__is, bool __rid) of LinkedPose";
220  referenceRobot->ref();
221  }
222 
224  }
225 
227 
229  IceUtil::Shared(source),
230  armarx::Serializable(source),
231  Vector3Base(source),
232  FramedDirectionBase(source),
233  LinkedDirectionBase(source),
234  Vector3(source),
236  {
237  referenceRobot = source.referenceRobot;
238 
239  if (referenceRobot)
240  {
241  //ARMARX_WARNING_S << "Calling referenceRobot->ref() in cctor of LinkedPose";
242  referenceRobot->ref();
243  }
244  }
245 
246  LinkedDirection::LinkedDirection(const Eigen::Vector3f& v,
247  const std::string& frame,
248  const SharedRobotInterfacePrx& referenceRobot) :
249  FramedDirection(v, frame, referenceRobot->getName())
250  {
251  referenceRobot->ref();
252  this->referenceRobot = referenceRobot;
253  }
254 
256  {
257  try
258  {
259  if (referenceRobot)
260  {
261  referenceRobot->unref();
262  }
263  }
264  catch (...)
265  {
267  }
268  }
269 
270  void
271  LinkedDirection::changeFrame(const std::string& newFrame, const Ice::Current& c)
272  {
273  if (newFrame == frame)
274  {
275  return;
276  }
277 
278  VirtualRobot::RobotPtr sharedRobot(new RemoteRobot(referenceRobot));
279 
280  FramedDirectionPtr frVec = ChangeFrame(sharedRobot, *this, newFrame);
281  x = frVec->x;
282  y = frVec->y;
283  z = frVec->z;
284  frame = frVec->frame;
285  }
286 
287  void
288  LinkedDirection::serialize(const ObjectSerializerBasePtr& serializer, const Ice::Current&) const
289  {
290  throw LocalException("LinkedDirection cannot be serialized! Serialize FramedDirection");
291  }
292 
293  void
294  LinkedDirection::deserialize(const ObjectSerializerBasePtr& serializer, const Ice::Current&)
295  {
296  throw LocalException("LinkedDirection cannot be deserialized! Deserialize FramedDirection");
297  }
298 
299  void
301  {
302  if (referenceRobot)
303  {
304  // ARMARX_WARNING_S << "Calling referenceRobot->ref() in __read(IceInternal::BasicStream *__is, bool __rid) of LinkedPose";
305  referenceRobot->ref();
306  }
307 
308  FramedDirection::ice_postUnmarshal();
309  }
310 
311  void
313  {
316  }
317 
318 } // namespace armarx
armarx::LinkedPose::clone
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: LinkedPose.cpp:141
RemoteRobot.h
armarx::LinkedDirection::LinkedDirection
LinkedDirection()
LinkedPose.h
armarx::LinkedDirection::ice_postUnmarshal
void ice_postUnmarshal() override
Definition: LinkedPose.cpp:300
armarx::VariantType::suppressWarningUnusedVariableForLinkedPoseAndDirection
void suppressWarningUnusedVariableForLinkedPoseAndDirection()
Definition: LinkedPose.cpp:312
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:280
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::LinkedDirection
The LinkedDirection class.
Definition: LinkedPose.h:118
armarx::LinkedDirection::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: LinkedPose.cpp:288
armarx::LinkedPose::changeFrame
void changeFrame(const std::string &newFrame, const Ice::Current &c=Ice::emptyCurrent) override
Definition: LinkedPose.cpp:168
armarx::LinkedPose::createLinkedCoordinate
VirtualRobot::LinkedCoordinate createLinkedCoordinate()
Definition: LinkedPose.cpp:118
armarx::LinkedPose::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: LinkedPose.cpp:188
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::LinkedDirection::changeFrame
void changeFrame(const std::string &newFrame, const Ice::Current &c=Ice::emptyCurrent) override
Definition: LinkedPose.cpp:271
IceUtil
Definition: Instance.h:21
armarx::FramedPose::toGlobal
FramedPosePtr toGlobal(const SharedRobotInterfacePrx &referenceRobot) const
Definition: FramedPose.cpp:576
armarx::LinkedPose::LinkedPose
LinkedPose()
Definition: LinkedPose.cpp:42
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::FramedDirection::ChangeFrame
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
Definition: FramedPose.cpp:91
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::FramedPose::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: FramedPose.cpp:459
armarx::VariantType::LinkedPose
const VariantTypeId LinkedPose
Definition: LinkedPose.h:43
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:205
armarx::LinkedPose::~LinkedPose
~LinkedPose() override
Definition: LinkedPose.cpp:102
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:216
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::LinkedDirection::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LinkedPose.cpp:294
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::Pose::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: Pose.cpp:353
armarx::LinkedPose::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: LinkedPose.cpp:135
armarx::LinkedPose::changeToGlobal
void changeToGlobal()
Definition: LinkedPose.cpp:174
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:43
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
ExpressionException.h
armarx::Pose
The Pose class.
Definition: Pose.h:242
armarx::RemoteRobot
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
Definition: RemoteRobot.h:144
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:86
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:198
armarx::LinkedPose::getType
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: LinkedPose.cpp:156
IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface >
armarx::Pose::ice_postUnmarshal
void ice_postUnmarshal() override
Definition: Pose.cpp:376
armarx::LinkedPose::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: LinkedPose.cpp:197
armarx::LinkedPose::ice_postUnmarshal
void ice_postUnmarshal() override
Definition: LinkedPose.cpp:215
armarx::LinkedPose::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: LinkedPose.cpp:147
armarx::LinkedPose::toGlobal
LinkedPosePtr toGlobal() const
Definition: LinkedPose.cpp:180
armarx::LinkedPose
The LinkedPose class.
Definition: LinkedPose.h:60
armarx::LinkedPose::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: LinkedPose.cpp:162
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::FramedPose::getFrame
std::string getFrame() const
Definition: FramedPose.cpp:453
Logging.h
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::FramedPose::changeToGlobal
void changeToGlobal(const SharedRobotInterfacePrx &referenceRobot)
Definition: FramedPose.cpp:539
armarx::handleExceptions
void handleExceptions()
Definition: Exception.cpp:157
armarx::LinkedDirection::~LinkedDirection
~LinkedDirection() override
Definition: LinkedPose.cpp:255
armarx::FramedPose::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: FramedPose.cpp:690
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::FramedPose::changeFrame
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
Definition: FramedPose.cpp:469
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19