26 #include <Eigen/Geometry>
28 #include <Ice/ObjectAdapter.h>
30 #include <VirtualRobot/Nodes/RobotNode.h>
31 #include <VirtualRobot/Nodes/RobotNodePrismatic.h>
32 #include <VirtualRobot/Nodes/RobotNodeRevolute.h>
33 #include <VirtualRobot/Robot.h>
34 #include <VirtualRobot/RobotConfig.h>
35 #include <VirtualRobot/RobotNodeSet.h>
36 #include <VirtualRobot/VirtualRobot.h>
42 using namespace Eigen;
54 using NodeCache = std::map<std::string, SharedRobotNodeInterfacePrx>;
60 SharedObjectBase::SharedObjectBase()
62 this->_referenceCount = 0;
69 SharedObjectBase::ref(
const Current& current)
71 std::unique_lock lock(this->_counterMutex);
81 SharedObjectBase::unref(
const Current& current)
83 std::unique_lock lock(this->_counterMutex);
90 if (_referenceCount == 0)
92 this->destroy(current);
97 SharedObjectBase::destroy(
const Current& current)
101 current.adapter->remove(current.id);
104 <<
" " <<
this <<
flush;
107 catch (
const NotRegisteredException& e)
110 throw ObjectNotExistException(__FILE__, __LINE__);
118 SharedRobotNodeServant::SharedRobotNodeServant(RobotNodePtr node) : _node(node)
122 <<
" " <<
this <<
flush;
130 <<
" " <<
this <<
flush;
137 ReadLockPtr lock =
_node->getRobot()->getReadLock();
138 return _node->getJointValue();
144 ReadLockPtr lock =
_node->getRobot()->getReadLock();
145 return _node->getName();
151 ReadLockPtr lock =
_node->getRobot()->getReadLock();
152 return new Pose(
_node->getLocalTransformation());
158 ReadLockPtr lock =
_node->getRobot()->getReadLock();
165 ReadLockPtr lock =
_node->getRobot()->getReadLock();
167 _node->getRobot()->getRootNode()->getName(),
168 _node->getRobot()->getName());
174 ReadLockPtr lock =
_node->getRobot()->getReadLock();
176 if (
_node->isRotationalJoint())
180 else if (
_node->isTranslationalJoint())
193 ReadLockPtr lock =
_node->getRobot()->getReadLock();
194 RobotNodePrismatic* prismatic =
dynamic_cast<RobotNodePrismatic*
>(
_node.get());
198 return new Vector3(prismatic->getJointTranslationDirection());
209 ReadLockPtr lock =
_node->getRobot()->getReadLock();
210 RobotNodeRevolute* revolute =
dynamic_cast<RobotNodeRevolute*
>(
_node.get());
214 return new Vector3(revolute->getJointRotationAxis());
225 const Current& current)
const
227 ReadLockPtr lock =
_node->getRobot()->getReadLock();
235 ReadLockPtr lock =
_node->getRobot()->getReadLock();
240 throw UserException(
"This RobotNode has no parent.");
243 return parent->getName();
249 ReadLockPtr lock =
_node->getRobot()->getReadLock();
250 std::vector<SceneObjectPtr> children =
_node->getChildren();
254 names.push_back(node->getName());
261 const Ice::Current& current)
const
263 ReadLockPtr lock =
_node->getRobot()->getReadLock();
264 std::vector<RobotNodePtr> parents =
265 _node->getAllParents(
_node->getRobot()->getRobotNodeSet(name));
267 for (RobotNodePtr
const& node : parents)
269 names.push_back(node->getName());
277 ReadLockPtr lock =
_node->getRobot()->getReadLock();
278 return _node->getJointValueOffset();
284 ReadLockPtr lock =
_node->getRobot()->getReadLock();
285 return _node->getJointLimitHigh();
291 ReadLockPtr lock =
_node->getRobot()->getReadLock();
292 return _node->getJointLimitLow();
298 ReadLockPtr lock =
_node->getRobot()->getReadLock();
305 ReadLockPtr lock =
_node->getRobot()->getReadLock();
308 for (
int i = 0; i < 3; i++)
309 for (
int j = 0; j < 3; j++)
311 result.push_back(
_node->getInertiaMatrix()(i, j));
320 ReadLockPtr lock =
_node->getRobot()->getReadLock();
321 return _node->getMass();
330 RobotStateListenerInterfacePrx robotStateListenerPrx) :
332 robotStateComponent(robotStateComponent),
333 robotStateListenerPrx(robotStateListenerPrx)
345 std::unique_lock cloneLock(
m);
351 value.second->unref();
365 SharedRobotNodeInterfacePrx
370 std::unique_lock cloneLock(
m);
371 SharedRobotNodeInterfacePrx prx;
373 if (this->
_cachedNodes.find(name) == this->_cachedNodes.end())
375 RobotNodePtr robotNode =
_robot->getRobotNode(name);
380 throw UserException(
"RobotNode \"" + name +
"\" not defined.");
383 SharedRobotNodeInterfacePtr servant =
386 prx = SharedRobotNodeInterfacePrx::uncheckedCast(current.adapter->addWithUUID(servant));
395 SharedRobotNodeInterfacePrx
399 std::unique_lock cloneLock(
m);
400 std::string name =
_robot->getRootNode() ->getName();
407 return _robot->hasRobotNode(name);
413 std::vector<RobotNodePtr> robotNodes =
_robot->getRobotNodes();
415 for (RobotNodePtr
const& node : robotNodes)
417 names.push_back(node->getName());
425 RobotNodeSetPtr robotNodeSet =
_robot->getRobotNodeSet(name);
429 throw UserException(
"RobotNodeSet \"" + name +
"\" not defined");
432 std::vector<RobotNodePtr> robotNodes = robotNodeSet->getAllRobotNodes();
434 for (RobotNodePtr
const& node : robotNodes)
436 names.push_back(node->getName());
439 RobotNodeSetInfoPtr info =
new RobotNodeSetInfo;
442 info->tcpName = robotNodeSet->getTCP()->getName();
443 info->rootName = robotNodeSet->getKinematicRoot()->getName();
451 std::vector<RobotNodeSetPtr> robotNodeSets =
_robot->getRobotNodeSets();
453 for (RobotNodeSetPtr
const&
set : robotNodeSets)
464 return _robot->hasRobotNodeSet(name);
489 ReadLockPtr lock =
_robot->getReadLock();
502 ReadLockPtr lock =
_robot->getReadLock();
503 std::map<std::string, float>
values =
_robot->getConfig()->getRobotNodeJointValueMap();
530 WriteLockPtr lock =
_robot->getWriteLock();
538 !oldPose.isApprox(newPose));
540 _robot->setGlobalPose(newPose,
true);
546 return _robot->getScaling();