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