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>
54 using NodeCache = std::map<std::string, SharedRobotNodeInterfacePrx>;
62 this->_referenceCount = 0;
71 std::unique_lock lock(this->_counterMutex);
83 std::unique_lock lock(this->_counterMutex);
90 if (_referenceCount == 0)
101 current.adapter->remove(current.id);
104 <<
" " <<
this <<
flush;
107 catch (
const NotRegisteredException& e)
110 throw ObjectNotExistException(__FILE__, __LINE__);
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();
236 SceneObjectPtr parent =
_node->getParent();
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();
252 for (SceneObjectPtr
const& node : children)
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();
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)
455 names.push_back(set->getName());
464 return _robot->hasRobotNodeSet(name);
489 ReadLockPtr lock =
_robot->getReadLock();
499 return NameValueMap();
502 ReadLockPtr lock =
_robot->getReadLock();
503 std::map<std::string, float> values =
_robot->getConfig()->getRobotNodeJointValueMap();
504 NameValueMap result(values.begin(), values.end());
530 WriteLockPtr lock =
_robot->getWriteLock();
531 Eigen::Matrix4f newPose = PosePtr::dynamicCast(pose)->toEigen();
534 Eigen::Matrix4f oldPose =
_robot->getGlobalPose();
538 !oldPose.isApprox(newPose));
540 _robot->setGlobalPose(newPose,
true);
546 return _robot->getScaling();
void ref(const Ice::Current &c=Ice::emptyCurrent) override
void unref(const Ice::Current &c=Ice::emptyCurrent) override
void destroy(const Ice::Current &c=Ice::emptyCurrent) override
The SharedRobotNodeServant class is a remote representation of a Simox VirtualRobot::Robot.
FramedPoseBasePtr getGlobalPose(const Ice::Current ¤t=Ice::emptyCurrent) const override
VirtualRobot::RobotNodePtr _node
~SharedRobotNodeServant() override
float getMass(const Ice::Current ¤t=Ice::emptyCurrent) const override
JointType getType(const Ice::Current ¤t=Ice::emptyCurrent) const override
std::string getName(const Ice::Current ¤t=Ice::emptyCurrent) const override
float getJointValueOffest(const Ice::Current ¤t=Ice::emptyCurrent) const override
SharedRobotNodeServant(VirtualRobot::RobotNodePtr node)
Vector3BasePtr getCoM(const Ice::Current ¤t=Ice::emptyCurrent) const override
NameList getChildren(const Ice::Current ¤t=Ice::emptyCurrent) const override
float getJointLimitLow(const Ice::Current ¤t=Ice::emptyCurrent) const override
Ice::FloatSeq getInertia(const Ice::Current ¤t=Ice::emptyCurrent) const override
PoseBasePtr getLocalTransformation(const Ice::Current ¤t=Ice::emptyCurrent) const override
Vector3BasePtr getJointRotationAxis(const Ice::Current ¤t=Ice::emptyCurrent) const override
NameList getAllParents(const std::string &name, const Ice::Current ¤t=Ice::emptyCurrent) const override
float getJointLimitHigh(const Ice::Current ¤t=Ice::emptyCurrent) const override
FramedPoseBasePtr getPoseInRootFrame(const Ice::Current ¤t=Ice::emptyCurrent) const override
Vector3BasePtr getJointTranslationDirection(const Ice::Current ¤t=Ice::emptyCurrent) const override
bool hasChild(const std::string &name, bool recursive, const Ice::Current ¤t=Ice::emptyCurrent) const override
float getJointValue(const Ice::Current ¤t=Ice::emptyCurrent) const override
std::string getParent(const Ice::Current ¤t=Ice::emptyCurrent) const override
IceUtil::Time updateTimestamp
SharedRobotNodeInterfacePrx getRootNode(const Ice::Current ¤t=Ice::emptyCurrent) override
TimestampBasePtr getTimestamp(const Ice::Current &=Ice::emptyCurrent) const override
std::string getType(const Ice::Current ¤t=Ice::emptyCurrent) override
RobotStateComponentInterfacePrx robotStateComponent
float getScaling(const Ice::Current &=Ice::emptyCurrent) override
PoseBasePtr getGlobalPose(const Ice::Current ¤t=Ice::emptyCurrent) override
std::string getName(const Ice::Current ¤t=Ice::emptyCurrent) override
void setGlobalPose(const PoseBasePtr &pose, const Ice::Current ¤t=Ice::emptyCurrent) override
RobotStateComponentInterfacePrx getRobotStateComponent(const Ice::Current &) const override
SharedRobotNodeInterfacePrx getRobotNode(const std::string &name, const Ice::Current ¤t=Ice::emptyCurrent) override
bool hasRobotNodeSet(const std::string &name, const Ice::Current ¤t=Ice::emptyCurrent) override
std::map< std::string, SharedRobotNodeInterfacePrx > _cachedNodes
NameValueMap getConfig(const Ice::Current ¤t=Ice::emptyCurrent) override
SharedRobotServant(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStateComponent, RobotStateListenerInterfacePrx robotStateListenerPrx)
bool hasRobotNode(const std::string &name, const Ice::Current ¤t=Ice::emptyCurrent) override
NameList getRobotNodeSets(const Ice::Current ¤t=Ice::emptyCurrent) override
NameList getRobotNodes(const Ice::Current ¤t=Ice::emptyCurrent) override
NameValueMap getConfigAndPose(PoseBasePtr &globalPose, const Ice::Current ¤t=Ice::emptyCurrent) override
VirtualRobot::RobotPtr _robot
RobotNodeSetInfoPtr getRobotNodeSet(const std::string &name, const Ice::Current ¤t=Ice::emptyCurrent) override
void setRobotStateComponent(RobotStateComponentInterfacePrx robotStateComponent)
RobotStateListenerInterfacePrx robotStateListenerPrx
void setTimestamp(const IceUtil::Time &updateTime)
~SharedRobotServant() override
VirtualRobot::RobotPtr getRobot() const
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Implements a Variant type for timestamps.
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_FATAL_S
The logging level for unexpected behaviour, that will lead to a seriously malfunctioning program and ...
#define ARMARX_LOG_S
This macro creates a new temporary instance which can then be used to log data using the << operator.
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
std::string const GlobalFrame
Variable of the global coordinate system.
std::shared_ptr< class Robot > RobotPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, SharedRobotNodeInterfacePrx > NodeCache
const LogSender::manipulator flush
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx