RemoteRobot.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-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 RobotAPI::
19  * @author (stefan dot ulbrich at kit dot edu)
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <mutex>
27 
28 #include <VirtualRobot/Nodes/RobotNodeFixed.h>
29 #include <VirtualRobot/Nodes/RobotNodePrismatic.h>
30 #include <VirtualRobot/Nodes/RobotNodeRevolute.h>
31 #include <VirtualRobot/Robot.h>
32 #include <VirtualRobot/VirtualRobot.h>
33 #include <VirtualRobot/XML/RobotIO.h>
34 
35 #include <RobotAPI/interface/core/RobotState.h>
36 
37 namespace armarx
38 {
39  // forward declaration of RemoteRobotNode
40  template <class VirtualRobotNodeType>
42 
43  /** @brief RemoteRobotNodeInitializer is used to initialize the robot node for a given node type.
44  * For each robot type to be supported make a specialization of the initialize function.
45  * Currently supports: RobotNodeRevolute, RobotNodePrismatic, RobotNodeFixed. Node type specific
46  * initializations go here.
47  */
48  template <typename VirtualRobotNodeType>
50  {
51  static void initialize(RemoteRobotNode<VirtualRobotNodeType>* remoteNode);
52  };
53 
54  // specializations
55  template <>
58  template <>
61  template <>
64 
65  VirtualRobot::CollisionCheckerPtr RemoteRobotNode_getGlobalCollisionChecker();
66 
67  /** @brief Mimics the behaviour of robot nodes while redirecting everything to Ice proxies.
68  * @tparam VirtualRobotNodeType Must be a descendant of VirtualRobot::RobotNode
69  * @details This class is for <b> internal use only</b> as classes cannot be referenced!
70  */
71  template <class VirtualRobotNodeType>
72  class RemoteRobotNode : public VirtualRobotNodeType
73  {
74  friend struct RemoteRobotNodeInitializer<VirtualRobotNodeType>;
75 
76  public:
77  RemoteRobotNode(SharedRobotNodeInterfacePrx node, VirtualRobot::RobotPtr vr) : _node(node)
78  {
79  _node->ref();
80  this->name = _node->getName();
81  this->robot = vr;
82  _node->getJointValueOffest();
83  setJointLimits(_node->getJointLimitLow(), _node->getJointLimitHigh());
84 
85  this->collisionChecker = RemoteRobotNode_getGlobalCollisionChecker();
86 
88  }
89 
90  ~RemoteRobotNode() override;
91 
92  float getJointValue() const override;
93  virtual float getJointLimitHi() const;
94  virtual float getJointLimitLo() const;
95 
97 
98  Eigen::Matrix4f getGlobalPose() const override;
99  Eigen::Matrix4f getPoseInRootFrame() const override;
100  Eigen::Vector3f getPositionInRootFrame() const override;
101  virtual bool hasChildNode(const std::string& child, bool recursive = false) const;
102 
103  std::vector<VirtualRobot::RobotNodePtr>
104  getAllParents(VirtualRobot::RobotNodeSetPtr rns) override;
106 
107  inline SharedRobotNodeInterfacePrx
109  {
110  return _node;
111  }
112 
113  virtual std::vector<std::string> getChildrenNames() const;
114 
115  protected:
116  ///////////////////////// SETUP ////////////////////////////////////
117  void setJointLimits(float lo, float hi) override;
118  //virtual void setPostJointTransformation(const Eigen::Matrix4f &trafo);
119  virtual void setLocalTransformation(const Eigen::Matrix4f& trafo);
120 
121  virtual std::string getParentName() const;
122  std::vector<VirtualRobot::SceneObjectPtr> getChildren() const override;
123 
124  void updateTransformationMatrices() override;
125  void updateTransformationMatrices(const Eigen::Matrix4f& globalPose) override;
126 
127 
128  virtual bool hasChildNode(const VirtualRobot::RobotNodePtr child,
129  bool recursive = false) const;
130  virtual void addChildNode(VirtualRobot::RobotNodePtr child);
131  virtual bool initialize(VirtualRobot::RobotNodePtr parent, bool initializeChildren = false);
132  virtual void reset();
133  void setGlobalPose(const Eigen::Matrix4f& pose) override;
134  virtual void
135  setJointValue(float q, bool updateTransformations = true, bool clampToLimits = true);
136 
137  SharedRobotNodeInterfacePrx _node;
138  };
139 
140  /** @brief Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
141  * @details For a description of the members please refer to the Simox documentation (VirtualRobot::Robot).
142  * Note that not the complete interface has been made available yet. These functions are marked as protected.
143  */
145  {
146  public:
148 
149  ~RemoteRobot() override;
150 
151  VirtualRobot::RobotNodePtr getRootNode() const override;
152 
153  bool hasRobotNode(const std::string& robotNodeName) const override;
154  bool hasRobotNode(VirtualRobot::RobotNodePtr) const override;
155 
156  VirtualRobot::RobotNodePtr getRobotNode(const std::string& robotNodeName) const override;
157  void getRobotNodes(std::vector<VirtualRobot::RobotNodePtr>& storeNodes,
158  bool clearVector = true) const override;
159 
160  bool hasRobotNodeSet(const std::string& name) const override;
161  VirtualRobot::RobotNodeSetPtr
162  getRobotNodeSet(const std::string& nodeSetName) const override;
163  void
164  getRobotNodeSets(std::vector<VirtualRobot::RobotNodeSetPtr>& storeNodeSet) const override;
165 
166  /**
167  *
168  * @return Global pose of the robot
169  */
170  Eigen::Matrix4f getGlobalPose() const override;
171 
172  float getScaling();
173 
174 
175  /// Use this method to share the robot instance over Ice.
177 
178  std::string getName() const override;
179 
180  /*!
181  Creates a local robot that is synchronized once but not updated any more. You can use the synchronizeLocalClone method to update the joint values.
182  Note that only the kinematic structure is cloned, but the visualization files, collision models, end effectors, etc are not copied.
183  This means you can use this model for kinematic computations (e.g. coordinate transformations) but not for advanced features like collision detection.
184  In order to get a fully featured robot model you can pass a filename to VirtualRobot::Robot,
185  but then you need to make sure that the loaded model is identical to the model of the remote robot (otherwise errors will occur).
186  In the packages parameter you can pass in ArmarX packages, in which the robot file model might be in.
187  The loadMode specifies in which mode the model should be loaded. Refer to simox for more information (only matters if filename was passed in).
188  @see createLocalCloneFromFile(), synchronizeLocalClone()
189  */
191  RobotStateComponentInterfacePrx robotStatePrx,
192  const std::string& filename = std::string(),
193  const Ice::StringSeq packages = Ice::StringSeq(),
194  VirtualRobot::RobotIO::RobotDescription loadMode = VirtualRobot::RobotIO::eFull);
195 
197  SharedRobotInterfacePrx sharedRobotPrx,
198  std::string filename = std::string(),
199  float scaling = 1.0f,
200  const Ice::StringSeq packages = Ice::StringSeq(),
201  VirtualRobot::RobotIO::RobotDescription loadMode = VirtualRobot::RobotIO::eFull);
202 
203  /**
204  * @brief This is a convenience function for createLocalClone, which automatically gets the filename from the RobotStateComponent,
205  * loads robot from the file and syncs it once.
206  * @param robotStatePrx Proxy to the RobotStateComponent
207  * @param loadMode The loadMode specifies in which mode the model should be loaded. Refer to simox for more information.
208  * @return new robot clone
209  * @see createLocalClone(), synchronizeLocalClone()
210  */
212  RobotStateComponentInterfacePrx robotStatePrx,
213  VirtualRobot::RobotIO::RobotDescription loadMode = VirtualRobot::RobotIO::eFull);
214 
215 
216  /*!
217  Use this method to synchronize (i.e. copy the joint values) from the remote robot to the local clone.
218  The local clone must have the identical structure as the remote robot model, otherwise an error will be reported.
219  This is the fastest way to get update a local robot.
220  */
222  RobotStateComponentInterfacePrx robotStatePrx);
223 
225  SharedRobotInterfacePrx sharedRobotPrx);
226 
227  /**
228  * @brief Synchronizes a local robot to a robot state at timestamp.
229  * @param robot Local robot that should be updated
230  * @param robotStatePrx Proxy to the RobotStateComponent
231  * @param timestamp Timestamp to which the local robot should be sychronized. Must be in range of the state history of the RobotStateComponent.
232  * @return True if successfully synced.
233  */
235  RobotStateComponentInterfacePrx robotStatePrx,
236  Ice::Long timestamp);
237 
239  RobotStateConfig const& state);
240 
241  // VirtualRobot::RobotPtr getRobotPtr() { return shared_from_this();} // only for debugging
242 
243  //! Clones the structure of this remote robot to a local instance
245 
246  protected:
247  /// Not implemented yet
248  bool hasEndEffector(const std::string& endEffectorName) const override;
249  /// Not implemented yet
250  VirtualRobot::EndEffectorPtr
251  getEndEffector(const std::string& endEffectorName) const override;
252  /// Not implemented yet
253  void getEndEffectors(std::vector<VirtualRobot::EndEffectorPtr>& storeEEF) const override;
254 
255  /// Not implemented yet
256  void setRootNode(VirtualRobot::RobotNodePtr node) override;
257  /// Not implemented yet
258  void registerRobotNode(VirtualRobot::RobotNodePtr node) override;
259  /// Not implemented yet
260  void deregisterRobotNode(VirtualRobot::RobotNodePtr node) override;
261  /// Not implemented yet
262  void registerRobotNodeSet(VirtualRobot::RobotNodeSetPtr nodeSet) override;
263  /// Not implemented yet
264  void deregisterRobotNodeSet(VirtualRobot::RobotNodeSetPtr nodeSet) override;
265  /// Not implemented yet
266  void registerEndEffector(VirtualRobot::EndEffectorPtr endEffector) override;
267  /**
268  * @brief Sets the global pose of the robot.
269  * @param globalPose new global pose
270  * @param applyValues No effect. Will be always applied.
271  */
272  void setGlobalPose(const Eigen::Matrix4f& globalPose, bool applyValues = true) override;
273 
274  VirtualRobot::RobotNodePtr
275  createLocalNode(SharedRobotNodeInterfacePrx remoteNode,
276  std::vector<VirtualRobot::RobotNodePtr>& allNodes,
277  std::map<VirtualRobot::RobotNodePtr, std::vector<std::string>>& childrenMap,
279 
280  protected:
282  mutable std::map<std::string, VirtualRobot::RobotNodePtr> _cachedNodes;
283  mutable VirtualRobot::RobotNodePtr _root;
284 
285  static std::recursive_mutex m;
286 
287  static VirtualRobot::RobotNodePtr createRemoteRobotNode(SharedRobotNodeInterfacePrx,
289  };
290 
291  using RemoteRobotPtr = std::shared_ptr<RemoteRobot>;
292 } // namespace armarx
armarx::RemoteRobotNode::getJointLimitLo
virtual float getJointLimitLo() const
Definition: RemoteRobotNode.cpp:126
armarx::RemoteRobotNode::reset
virtual void reset()
Definition: RemoteRobotNode.cpp:273
armarx::RemoteRobot::m
static std::recursive_mutex m
Definition: RemoteRobot.h:285
armarx::RemoteRobot::getGlobalPose
Eigen::Matrix4f getGlobalPose() const override
Definition: RemoteRobot.cpp:193
armarx::RemoteRobot::createRemoteRobotNode
static VirtualRobot::RobotNodePtr createRemoteRobotNode(SharedRobotNodeInterfacePrx, VirtualRobot::RobotPtr)
Definition: RemoteRobotNode.cpp:43
armarx::eFull
@ eFull
Definition: MorphingItem.h:35
armarx::RemoteRobot::hasRobotNode
bool hasRobotNode(const std::string &robotNodeName) const override
Definition: RemoteRobot.cpp:96
armarx::RemoteRobot::_robot
SharedRobotInterfacePrx _robot
Definition: RemoteRobot.h:281
armarx::RemoteRobot::deregisterRobotNode
void deregisterRobotNode(VirtualRobot::RobotNodePtr node) override
Not implemented yet.
Definition: RemoteRobot.cpp:640
armarx::RemoteRobot::synchronizeLocalClone
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
Definition: RemoteRobot.cpp:522
armarx::RemoteRobotNode::hasChildNode
virtual bool hasChildNode(const std::string &child, bool recursive=false) const
Definition: RemoteRobotNode.cpp:176
armarx::RemoteRobot::createLocalCloneFromFile
static VirtualRobot::RobotPtr createLocalCloneFromFile(RobotStateComponentInterfacePrx robotStatePrx, VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eFull)
This is a convenience function for createLocalClone, which automatically gets the filename from the R...
Definition: RemoteRobot.cpp:512
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::RemoteRobot::getRootNode
VirtualRobot::RobotNodePtr getRootNode() const override
Definition: RemoteRobot.cpp:85
armarx::RemoteRobotNodeInitializer::initialize
static void initialize(RemoteRobotNode< VirtualRobotNodeType > *remoteNode)
armarx::RemoteRobot::getRobotNodes
void getRobotNodes(std::vector< VirtualRobot::RobotNodePtr > &storeNodes, bool clearVector=true) const override
Definition: RemoteRobot.cpp:152
armarx::RemoteRobot::_root
VirtualRobot::RobotNodePtr _root
Definition: RemoteRobot.h:283
armarx::RemoteRobot::getEndEffectors
void getEndEffectors(std::vector< VirtualRobot::EndEffectorPtr > &storeEEF) const override
Not implemented yet.
Definition: RemoteRobot.cpp:625
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::RemoteRobotNodeInitializer
RemoteRobotNodeInitializer is used to initialize the robot node for a given node type.
Definition: RemoteRobot.h:49
armarx::RemoteRobotNode::getChildren
std::vector< VirtualRobot::SceneObjectPtr > getChildren() const override
Definition: RemoteRobotNode.cpp:235
armarx::RemoteRobot::getScaling
float getScaling()
Definition: RemoteRobot.cpp:200
armarx::RemoteRobot::getRobotNodeSet
VirtualRobot::RobotNodeSetPtr getRobotNodeSet(const std::string &nodeSetName) const override
Definition: RemoteRobot.cpp:173
armarx::RemoteRobot::getRobotNode
VirtualRobot::RobotNodePtr getRobotNode(const std::string &robotNodeName) const override
Definition: RemoteRobot.cpp:133
armarx::RemoteRobotNode::getPoseInRootFrame
Eigen::Matrix4f getPoseInRootFrame() const override
Definition: RemoteRobotNode.cpp:153
armarx::RemoteRobot::getName
std::string getName() const override
Definition: RemoteRobot.cpp:212
armarx::RemoteRobot::hasRobotNodeSet
bool hasRobotNodeSet(const std::string &name) const override
Definition: RemoteRobot.cpp:167
armarx::RemoteRobotNode::getSharedRobotNode
SharedRobotNodeInterfacePrx getSharedRobotNode()
Definition: RemoteRobot.h:108
armarx::RemoteRobotNode::_node
SharedRobotNodeInterfacePrx _node
Definition: RemoteRobot.h:137
armarx::RemoteRobot::getRobotNodeSets
void getRobotNodeSets(std::vector< VirtualRobot::RobotNodeSetPtr > &storeNodeSet) const override
Definition: RemoteRobot.cpp:182
armarx::RemoteRobotNode::setJointLimits
void setJointLimits(float lo, float hi) override
Definition: RemoteRobotNode.cpp:183
armarx::armem::human::Robot
@ Robot
Definition: util.h:17
armarx::RemoteRobotNode::setGlobalPose
void setGlobalPose(const Eigen::Matrix4f &pose) override
Definition: RemoteRobotNode.cpp:279
armarx::RemoteRobot::registerEndEffector
void registerEndEffector(VirtualRobot::EndEffectorPtr endEffector) override
Not implemented yet.
Definition: RemoteRobot.cpp:655
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::RemoteRobot::getSharedRobot
SharedRobotInterfacePrx getSharedRobot() const
Use this method to share the robot instance over Ice.
Definition: RemoteRobot.cpp:206
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
armarx::RemoteRobot::deregisterRobotNodeSet
void deregisterRobotNodeSet(VirtualRobot::RobotNodeSetPtr nodeSet) override
Not implemented yet.
Definition: RemoteRobot.cpp:650
q
#define q
armarx::RemoteRobotNode_getGlobalCollisionChecker
CollisionCheckerPtr RemoteRobotNode_getGlobalCollisionChecker()
Definition: RemoteRobot.cpp:669
armarx::RemoteRobotNode::addChildNode
virtual void addChildNode(VirtualRobot::RobotNodePtr child)
Definition: RemoteRobotNode.cpp:260
armarx::RemoteRobotNode::getLocalTransformation
Eigen::Matrix4f getLocalTransformation() override
Definition: RemoteRobotNode.cpp:139
armarx::RemoteRobotPtr
std::shared_ptr< RemoteRobot > RemoteRobotPtr
Definition: RemoteRobot.h:291
armarx::RemoteRobotNode::getParent
virtual VirtualRobot::SceneObjectPtr getParent()
Definition: RemoteRobotNode.cpp:204
armarx::RemoteRobot
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
Definition: RemoteRobot.h:144
armarx::RemoteRobotNode
Mimics the behaviour of robot nodes while redirecting everything to Ice proxies.
Definition: RemoteRobot.h:41
armarx::RemoteRobot::_cachedNodes
std::map< std::string, VirtualRobot::RobotNodePtr > _cachedNodes
Definition: RemoteRobot.h:282
armarx::RemoteRobot::~RemoteRobot
~RemoteRobot() override
Definition: RemoteRobot.cpp:68
armarx::RemoteRobot::registerRobotNodeSet
void registerRobotNodeSet(VirtualRobot::RobotNodeSetPtr nodeSet) override
Not implemented yet.
Definition: RemoteRobot.cpp:645
armarx::RemoteRobot::createLocalClone
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Definition: RemoteRobot.cpp:381
armarx::RemoteRobotNode::RemoteRobotNode
RemoteRobotNode(SharedRobotNodeInterfacePrx node, VirtualRobot::RobotPtr vr)
Definition: RemoteRobot.h:77
armarx::RemoteRobot::synchronizeLocalCloneToTimestamp
static bool synchronizeLocalCloneToTimestamp(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx, Ice::Long timestamp)
Synchronizes a local robot to a robot state at timestamp.
Definition: RemoteRobot.cpp:566
hi
#define hi(x)
Definition: AbstractInterface.h:46
IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface >
armarx::RemoteRobot::synchronizeLocalCloneToState
static bool synchronizeLocalCloneToState(VirtualRobot::RobotPtr robot, RobotStateConfig const &state)
Definition: RemoteRobot.cpp:579
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::RemoteRobot::getEndEffector
VirtualRobot::EndEffectorPtr getEndEffector(const std::string &endEffectorName) const override
Not implemented yet.
Definition: RemoteRobot.cpp:619
armarx::RemoteRobot::RemoteRobot
RemoteRobot(SharedRobotInterfacePrx robot)
Definition: RemoteRobot.cpp:63
armarx::RemoteRobotNode::setJointValue
virtual void setJointValue(float q, bool updateTransformations=true, bool clampToLimits=true)
Definition: RemoteRobotNode.cpp:285
armarx::RemoteRobot::createLocalNode
VirtualRobot::RobotNodePtr createLocalNode(SharedRobotNodeInterfacePrx remoteNode, std::vector< VirtualRobot::RobotNodePtr > &allNodes, std::map< VirtualRobot::RobotNodePtr, std::vector< std::string >> &childrenMap, VirtualRobot::RobotPtr robo)
Definition: RemoteRobot.cpp:218
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
armarx::RemoteRobot::setRootNode
void setRootNode(VirtualRobot::RobotNodePtr node) override
Not implemented yet.
Definition: RemoteRobot.cpp:630
armarx::RemoteRobot::setGlobalPose
void setGlobalPose(const Eigen::Matrix4f &globalPose, bool applyValues=true) override
Sets the global pose of the robot.
Definition: RemoteRobot.cpp:660
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::RemoteRobot::registerRobotNode
void registerRobotNode(VirtualRobot::RobotNodePtr node) override
Not implemented yet.
Definition: RemoteRobot.cpp:635
armarx::RemoteRobot::hasEndEffector
bool hasEndEffector(const std::string &endEffectorName) const override
Not implemented yet.
Definition: RemoteRobot.cpp:613