RemoteRobotNode.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 <VirtualRobot/RobotNodeSet.h>
25 #include <VirtualRobot/VirtualRobot.h>
26 
29 #include <ArmarXCore/interface/core/BasicTypes.h>
30 
32 
33 #include "RemoteRobot.h"
34 
35 namespace armarx
36 {
37 
38  using namespace std;
39  using namespace VirtualRobot;
40  using namespace Eigen;
41 
42  RobotNodePtr
43  RemoteRobot::createRemoteRobotNode(SharedRobotNodeInterfacePrx node, RobotPtr robot)
44  {
45  switch (node->getType())
46  {
47  case ePrismatic:
48  return RobotNodePtr(new RemoteRobotNode<RobotNodePrismatic>(node, robot));
49 
50  case eRevolute:
51  return RobotNodePtr(new RemoteRobotNode<RobotNodeRevolute>(node, robot));
52 
53  case eFixed:
54  return RobotNodePtr(new RemoteRobotNode<RobotNodeFixed>(node, robot));
55 
56  default:
57  break; // thow an exception
58  }
59 
60  return RobotNodePtr();
61  }
62 
63  template <>
64  void
67  {
68  // set rotation axis
69  remoteNode->jointRotationAxis =
70  remoteNode->getGlobalPose().block<3, 3>(0, 0).inverse() *
71  Vector3Ptr::dynamicCast(remoteNode->_node->getJointRotationAxis())->toEigen();
72  }
73 
74  template <>
75  void
78  {
79  // set translation direction
80  remoteNode->jointTranslationDirection =
81  remoteNode->getGlobalPose().block<3, 3>(0, 0).inverse() *
82  Vector3Ptr::dynamicCast(remoteNode->_node->getJointTranslationDirection())->toEigen();
83  }
84 
85  template <>
86  void
89  {
90  // nothing to do for fixed joints
91  }
92 
93  template <class RobotNodeType>
95  {
96  try
97  {
98  _node->unref();
99  }
100  catch (std::exception& e)
101  {
102  ARMARX_DEBUG_S << "Unref of SharedRobotNode failed: " << e.what();
103  }
104  catch (...)
105  {
106  ARMARX_DEBUG_S << "Unref of SharedRobotNode failed: reason unknown";
107  }
108  }
109 
110  template <class RobotNodeType>
111  float
113  {
114  return _node->getJointValue();
115  }
116 
117  template <class RobotNodeType>
118  float
120  {
121  return _node->getJointLimitHigh();
122  }
123 
124  template <class RobotNodeType>
125  float
127  {
128  return _node->getJointLimitLow();
129  }
130 
131  /*
132  template<class RobotNodeType>
133  Eigen::Matrix4f RemoteRobotNode<RobotNodeType>::getPostJointTransformation(){
134  return PosePtr::dynamicCast(_node->getPostJointTransformation())->toEigen();
135  }*/
136 
137  template <class RobotNodeType>
140  {
141  return PosePtr::dynamicCast(_node->getLocalTransformation())->toEigen();
142  }
143 
144  template <class RobotNodeType>
147  {
148  return FramedPosePtr::dynamicCast(_node->getGlobalPose())->toEigen();
149  }
150 
151  template <class RobotNodeType>
154  {
155  return FramedPosePtr::dynamicCast(_node->getPoseInRootFrame())->toEigen();
156  }
157 
158  template <class RobotNodeType>
159  Eigen::Vector3f
161  {
162  Vector3Ptr pos = Vector3Ptr::dynamicCast(_node->getPoseInRootFrame()->position);
164  return pos->toEigen();
165  }
166 
167  template <class RobotNodeType>
168  bool
169  RemoteRobotNode<RobotNodeType>::hasChildNode(const RobotNodePtr child, bool recursive) const
170  {
171  return false;
172  }
173 
174  template <class RobotNodeType>
175  bool
176  RemoteRobotNode<RobotNodeType>::hasChildNode(const std::string& child, bool recursive) const
177  {
178  return _node->hasChild(child, recursive);
179  }
180 
181  template <class RobotNodeType>
182  void
184  {
185  }
186 
187  template <class RobotNodeType>
188  vector<RobotNodePtr>
190  {
191  NameList nodes = _node->getAllParents(rns->getName());
192  vector<RobotNodePtr> result;
193  RobotPtr robot = this->robot.lock();
194 
195  for (std::string const& name : nodes)
196  {
197  result.push_back(robot->getRobotNode(name));
198  }
199  return result;
200  }
201 
202  template <class RobotNodeType>
205  {
206  return this->robot.lock()->getRobotNode(_node->getParent());
207  }
208 
209  /*
210  template<class RobotNodeType>
211  void RemoteRobotNode<RobotNodeType>::setPostJointTransformation(const Eigen::Matrix4f &trafo){
212  }*/
213  template <class RobotNodeType>
214  void
216  {
217  }
218 
219  template <class RobotNodeType>
220  std::vector<std::string>
222  {
223  return _node->getChildren();
224  }
225 
226  template <class RobotNodeType>
227  std::string
229  {
230  return _node->getParent();
231  }
232 
233  template <class RobotNodeType>
234  std::vector<SceneObjectPtr>
236  {
237  NameList nodes = _node->getChildren();
238  vector<SceneObjectPtr> result;
239  for (string const& name : nodes)
240  {
241  result.push_back(this->robot.lock()->getRobotNode(name));
242  }
243  return result;
244  }
245 
246  template <class RobotNodeType>
247  void
249  {
250  }
251 
252  template <class RobotNodeType>
253  void
255  {
256  }
257 
258  template <class RobotNodeType>
259  void
261  {
262  }
263 
264  template <class RobotNodeType>
265  bool
266  RemoteRobotNode<RobotNodeType>::initialize(RobotNodePtr parent, bool initializeChildren)
267  {
268  return false;
269  }
270 
271  template <class RobotNodeType>
272  void
274  {
275  }
276 
277  template <class RobotNodeType>
278  void
280  {
281  }
282 
283  template <class RobotNodeType>
284  void
286  bool updateTransformations,
287  bool clampToLimits)
288  {
289  }
290 
291 } // namespace armarx
armarx::RemoteRobotNode::getJointLimitLo
virtual float getJointLimitLo() const
Definition: RemoteRobotNode.cpp:126
armarx::RemoteRobotNode::reset
virtual void reset()
Definition: RemoteRobotNode.cpp:273
RemoteRobot.h
armarx::RemoteRobot::createRemoteRobotNode
static VirtualRobot::RobotNodePtr createRemoteRobotNode(SharedRobotNodeInterfacePrx, VirtualRobot::RobotPtr)
Definition: RemoteRobotNode.cpp:43
Eigen
Definition: Elements.h:32
VirtualRobot
Definition: FramedPose.h:42
armarx::RemoteRobotNode::hasChildNode
virtual bool hasChildNode(const std::string &child, bool recursive=false) const
Definition: RemoteRobotNode.cpp:176
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::RemoteRobotNodeInitializer::initialize
static void initialize(RemoteRobotNode< VirtualRobotNodeType > *remoteNode)
armarx::RemoteRobotNode::getJointLimitHi
virtual float getJointLimitHi() const
Definition: RemoteRobotNode.cpp:119
armarx::RemoteRobotNode::setLocalTransformation
virtual void setLocalTransformation(const Eigen::Matrix4f &trafo)
Definition: RemoteRobotNode.cpp:215
armarx::RemoteRobotNode::getJointValue
float getJointValue() const override
Definition: RemoteRobotNode.cpp:112
armarx::RemoteRobotNode::getGlobalPose
Eigen::Matrix4f getGlobalPose() const override
Definition: RemoteRobotNode.cpp:146
lo
#define lo(x)
Definition: AbstractInterface.h:47
armarx::RemoteRobotNode::getChildren
std::vector< VirtualRobot::SceneObjectPtr > getChildren() const override
Definition: RemoteRobotNode.cpp:235
IceInternal::Handle< Vector3 >
armarx::RemoteRobotNode::getPoseInRootFrame
Eigen::Matrix4f getPoseInRootFrame() const override
Definition: RemoteRobotNode.cpp:153
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:205
armarx::RemoteRobotNode::_node
SharedRobotNodeInterfacePrx _node
Definition: RemoteRobot.h:137
FramedPose.h
armarx::RemoteRobotNode::setJointLimits
void setJointLimits(float lo, float hi) override
Definition: RemoteRobotNode.cpp:183
armarx::RemoteRobotNode::setGlobalPose
void setGlobalPose(const Eigen::Matrix4f &pose) override
Definition: RemoteRobotNode.cpp:279
armarx::RemoteRobotNode::getAllParents
std::vector< VirtualRobot::RobotNodePtr > getAllParents(VirtualRobot::RobotNodeSetPtr rns) override
Definition: RemoteRobotNode.cpp:189
armarx::RemoteRobotNode::updateTransformationMatrices
void updateTransformationMatrices() override
Definition: RemoteRobotNode.cpp:248
q
#define q
armarx::RemoteRobotNode::addChildNode
virtual void addChildNode(VirtualRobot::RobotNodePtr child)
Definition: RemoteRobotNode.cpp:260
ExpressionException.h
armarx::RemoteRobotNode::getLocalTransformation
Eigen::Matrix4f getLocalTransformation() override
Definition: RemoteRobotNode.cpp:139
armarx::RemoteRobotNode::getParent
virtual VirtualRobot::SceneObjectPtr getParent()
Definition: RemoteRobotNode.cpp:204
armarx::RemoteRobotNode
Mimics the behaviour of robot nodes while redirecting everything to Ice proxies.
Definition: RemoteRobot.h:41
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
std
Definition: Application.h:66
hi
#define hi(x)
Definition: AbstractInterface.h:46
scene3D::SceneObjectPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr
Definition: PointerDefinitions.h:40
armarx::RemoteRobotNode::getParentName
virtual std::string getParentName() const
Definition: RemoteRobotNode.cpp:228
armarx::RemoteRobotNode::getChildrenNames
virtual std::vector< std::string > getChildrenNames() const
Definition: RemoteRobotNode.cpp:221
armarx::RemoteRobotNode::initialize
virtual bool initialize(VirtualRobot::RobotNodePtr parent, bool initializeChildren=false)
Definition: RemoteRobotNode.cpp:266
armarx::RemoteRobotNode::~RemoteRobotNode
~RemoteRobotNode() override
Definition: RemoteRobotNode.cpp:94
armarx::RemoteRobotNode::setJointValue
virtual void setJointValue(float q, bool updateTransformations=true, bool clampToLimits=true)
Definition: RemoteRobotNode.cpp:285
Logging.h
armarx::RemoteRobotNode::getPositionInRootFrame
Eigen::Vector3f getPositionInRootFrame() const override
Definition: RemoteRobotNode.cpp:160
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19