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
37namespace armarx
38{
39 // forward declaration of RemoteRobotNode
40 template <class VirtualRobotNodeType>
41 class RemoteRobotNode;
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>
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
96 Eigen::Matrix4f getLocalTransformation() override;
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;
105 virtual VirtualRobot::SceneObjectPtr getParent();
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 */
144 class RemoteRobot : public VirtualRobot::Robot
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 */
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 */
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 */
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
#define lo(x)
#define hi(x)
std::string timestamp()
Mimics the behaviour of robot nodes while redirecting everything to Ice proxies.
Definition RemoteRobot.h:73
virtual bool hasChildNode(const VirtualRobot::RobotNodePtr child, bool recursive=false) const
Eigen::Matrix4f getPoseInRootFrame() const override
SharedRobotNodeInterfacePrx _node
Eigen::Vector3f getPositionInRootFrame() const override
void setJointLimits(float lo, float hi) override
void setGlobalPose(const Eigen::Matrix4f &pose) override
virtual float getJointLimitHi() const
SharedRobotNodeInterfacePrx getSharedRobotNode()
virtual std::vector< std::string > getChildrenNames() const
virtual void setLocalTransformation(const Eigen::Matrix4f &trafo)
virtual void addChildNode(VirtualRobot::RobotNodePtr child)
virtual bool initialize(VirtualRobot::RobotNodePtr parent, bool initializeChildren=false)
virtual void setJointValue(float q, bool updateTransformations=true, bool clampToLimits=true)
virtual bool hasChildNode(const std::string &child, bool recursive=false) const
std::vector< VirtualRobot::RobotNodePtr > getAllParents(VirtualRobot::RobotNodeSetPtr rns) override
virtual std::string getParentName() const
virtual VirtualRobot::SceneObjectPtr getParent()
float getJointValue() const override
RemoteRobotNode(SharedRobotNodeInterfacePrx node, VirtualRobot::RobotPtr vr)
Definition RemoteRobot.h:77
std::vector< VirtualRobot::SceneObjectPtr > getChildren() const override
void updateTransformationMatrices() override
virtual float getJointLimitLo() const
Eigen::Matrix4f getGlobalPose() const override
Eigen::Matrix4f getLocalTransformation() override
void registerRobotNodeSet(VirtualRobot::RobotNodeSetPtr nodeSet) override
Not implemented yet.
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
std::map< std::string, VirtualRobot::RobotNodePtr > _cachedNodes
VirtualRobot::EndEffectorPtr getEndEffector(const std::string &endEffectorName) const override
Not implemented yet.
bool hasRobotNode(VirtualRobot::RobotNodePtr) const override
std::string getName() const override
void getEndEffectors(std::vector< VirtualRobot::EndEffectorPtr > &storeEEF) const override
Not implemented yet.
SharedRobotInterfacePrx getSharedRobot() const
Use this method to share the robot instance over Ice.
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...
SharedRobotInterfacePrx _robot
void setGlobalPose(const Eigen::Matrix4f &globalPose, bool applyValues=true) override
Sets the global pose of the robot.
~RemoteRobot() override
bool hasRobotNodeSet(const std::string &name) const override
bool hasEndEffector(const std::string &endEffectorName) const override
Not implemented yet.
void deregisterRobotNode(VirtualRobot::RobotNodePtr node) override
Not implemented yet.
void deregisterRobotNodeSet(VirtualRobot::RobotNodeSetPtr nodeSet) override
Not implemented yet.
static bool synchronizeLocalCloneToState(VirtualRobot::RobotPtr robot, RobotStateConfig const &state)
VirtualRobot::RobotNodePtr getRootNode() const override
void setRootNode(VirtualRobot::RobotNodePtr node) override
Not implemented yet.
void registerRobotNode(VirtualRobot::RobotNodePtr node) override
Not implemented yet.
Eigen::Matrix4f getGlobalPose() const override
VirtualRobot::RobotNodePtr createLocalNode(SharedRobotNodeInterfacePrx remoteNode, std::vector< VirtualRobot::RobotNodePtr > &allNodes, std::map< VirtualRobot::RobotNodePtr, std::vector< std::string > > &childrenMap, VirtualRobot::RobotPtr robo)
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
static VirtualRobot::RobotNodePtr createRemoteRobotNode(SharedRobotNodeInterfacePrx, VirtualRobot::RobotPtr)
VirtualRobot::RobotNodePtr getRobotNode(const std::string &robotNodeName) const override
static bool synchronizeLocalCloneToTimestamp(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx, Ice::Long timestamp)
Synchronizes a local robot to a robot state at timestamp.
RemoteRobot(SharedRobotInterfacePrx robot)
void getRobotNodeSets(std::vector< VirtualRobot::RobotNodeSetPtr > &storeNodeSet) const override
void getRobotNodes(std::vector< VirtualRobot::RobotNodePtr > &storeNodes, bool clearVector=true) const override
VirtualRobot::RobotNodeSetPtr getRobotNodeSet(const std::string &nodeSetName) const override
VirtualRobot::RobotNodePtr _root
void registerEndEffector(VirtualRobot::EndEffectorPtr endEffector) override
Not implemented yet.
static std::recursive_mutex m
bool hasRobotNode(const std::string &robotNodeName) const override
#define q
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
CollisionCheckerPtr RemoteRobotNode_getGlobalCollisionChecker()
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
std::shared_ptr< RemoteRobot > RemoteRobotPtr
RemoteRobotNodeInitializer is used to initialize the robot node for a given node type.
Definition RemoteRobot.h:50
static void initialize(RemoteRobotNode< VirtualRobotNodeType > *remoteNode)