28 #include <Eigen/Geometry>
30 #include <VirtualRobot/Nodes/RobotNode.h>
31 #include <VirtualRobot/Nodes/RobotNodeRevolute.h>
32 #include <VirtualRobot/Nodes/RobotNodePrismatic.h>
33 #include <VirtualRobot/RobotConfig.h>
34 #include <VirtualRobot/VirtualRobot.h>
35 #include <VirtualRobot/Robot.h>
36 #include <VirtualRobot/RobotNodeSet.h>
37 #include <Ice/ObjectAdapter.h>
41 using namespace Eigen;
52 using NodeCache = std::map<std::string, SharedRobotNodeInterfacePrx>;
58 SharedObjectBase::SharedObjectBase()
60 this-> _referenceCount = 0;
67 void SharedObjectBase::ref(
const Current& current)
69 std::unique_lock lock(this->_counterMutex);
78 void SharedObjectBase::unref(
const Current& current)
80 std::unique_lock lock(this->_counterMutex);
87 if (_referenceCount == 0)
89 this->destroy(current);
93 void SharedObjectBase::destroy(
const Current& current)
97 current.adapter->remove(current.id);
102 catch (
const NotRegisteredException& e)
105 throw ObjectNotExistException(__FILE__, __LINE__);
113 SharedRobotNodeServant::SharedRobotNodeServant(RobotNodePtr node) :
131 ReadLockPtr lock =
_node->getRobot()->getReadLock();
132 return _node->getJointValue();
137 ReadLockPtr lock =
_node->getRobot()->getReadLock();
138 return _node->getName();
143 ReadLockPtr lock =
_node->getRobot()->getReadLock();
144 return new Pose(
_node->getLocalTransformation());
149 ReadLockPtr lock =
_node->getRobot()->getReadLock();
157 ReadLockPtr lock =
_node->getRobot()->getReadLock();
159 _node->getRobot()->getRootNode()->getName(),
160 _node->getRobot()->getName());
166 ReadLockPtr lock =
_node->getRobot()->getReadLock();
168 if (
_node->isRotationalJoint())
172 else if (
_node->isTranslationalJoint())
184 ReadLockPtr lock =
_node->getRobot()->getReadLock();
185 RobotNodePrismatic* prismatic =
dynamic_cast<RobotNodePrismatic*
>(
_node.get());
189 return new Vector3(prismatic->getJointTranslationDirection());
199 ReadLockPtr lock =
_node->getRobot()->getReadLock();
200 RobotNodeRevolute* revolute =
dynamic_cast<RobotNodeRevolute*
>(
_node.get());
204 return new Vector3(revolute->getJointRotationAxis());
215 ReadLockPtr lock =
_node->getRobot()->getReadLock();
222 ReadLockPtr lock =
_node->getRobot()->getReadLock();
227 throw UserException(
"This RobotNode has no parent.");
230 return parent->getName();
235 ReadLockPtr lock =
_node->getRobot()->getReadLock();
236 std::vector<SceneObjectPtr> children =
_node->getChildren();
240 names.push_back(node->getName());
247 ReadLockPtr lock =
_node->getRobot()->getReadLock();
248 std::vector<RobotNodePtr> parents =
_node->getAllParents(
_node->getRobot()->getRobotNodeSet(name));
250 for (RobotNodePtr
const& node : parents)
252 names.push_back(node->getName());
259 ReadLockPtr lock =
_node->getRobot()->getReadLock();
260 return _node->getJointValueOffset();
265 ReadLockPtr lock =
_node->getRobot()->getReadLock();
266 return _node->getJointLimitHigh();
271 ReadLockPtr lock =
_node->getRobot()->getReadLock();
272 return _node->getJointLimitLow();
277 ReadLockPtr lock =
_node->getRobot()->getReadLock();
283 ReadLockPtr lock =
_node->getRobot()->getReadLock();
286 for (
int i = 0; i < 3; i++)
287 for (
int j = 0; j < 3; j++)
289 result.push_back(
_node->getInertiaMatrix()(i, j));
297 ReadLockPtr lock =
_node->getRobot()->getReadLock();
298 return _node->getMass();
308 robotStateComponent(robotStateComponent),
309 robotStateListenerPrx(robotStateListenerPrx)
321 std::unique_lock cloneLock(
m);
327 value.second->unref();
342 std::unique_lock cloneLock(
m);
343 SharedRobotNodeInterfacePrx prx;
345 if (this->
_cachedNodes.find(name) == this->_cachedNodes.end())
347 RobotNodePtr robotNode =
_robot->getRobotNode(name);
352 throw UserException(
"RobotNode \"" + name +
"\" not defined.");
356 _robot->getRobotNode(name));
358 prx = SharedRobotNodeInterfacePrx::uncheckedCast(current.adapter->addWithUUID(servant));
370 std::unique_lock cloneLock(
m);
371 std::string name =
_robot->getRootNode()->getName();
378 return _robot->hasRobotNode(name);
383 std::vector<RobotNodePtr> robotNodes =
_robot->getRobotNodes();
385 for (RobotNodePtr
const& node : robotNodes)
387 names.push_back(node->getName());
394 RobotNodeSetPtr robotNodeSet =
_robot->getRobotNodeSet(name);
398 throw UserException(
"RobotNodeSet \"" + name +
"\" not defined");
401 std::vector<RobotNodePtr> robotNodes = robotNodeSet->getAllRobotNodes();
403 for (RobotNodePtr
const& node : robotNodes)
405 names.push_back(node->getName());
408 RobotNodeSetInfoPtr info =
new RobotNodeSetInfo;
411 info->tcpName = robotNodeSet->getTCP()->getName();
412 info->rootName = robotNodeSet->getKinematicRoot()->getName();
420 std::vector<RobotNodeSetPtr> robotNodeSets =
_robot->getRobotNodeSets();
422 for (RobotNodeSetPtr
const&
set : robotNodeSets)
432 return _robot->hasRobotNodeSet(name);
453 ReadLockPtr lock =
_robot->getReadLock();
465 ReadLockPtr lock =
_robot->getReadLock();
466 std::map < std::string, float >
values =
_robot->getConfig()->getRobotNodeJointValueMap();
489 WriteLockPtr lock =
_robot->getWriteLock();
496 _robot->setGlobalPose(newPose,
true);
501 return _robot->getScaling();