26 #include <Eigen/Geometry>
28 #include <SimoxUtility/algorithm/string/string_tools.h>
29 #include <VirtualRobot/CollisionDetection/CollisionChecker.h>
30 #include <VirtualRobot/Nodes/RobotNode.h>
31 #include <VirtualRobot/Nodes/RobotNodeFixed.h>
32 #include <VirtualRobot/Nodes/RobotNodeFixedFactory.h>
33 #include <VirtualRobot/Nodes/RobotNodePrismatic.h>
34 #include <VirtualRobot/Nodes/RobotNodePrismaticFactory.h>
35 #include <VirtualRobot/Nodes/RobotNodeRevolute.h>
36 #include <VirtualRobot/Nodes/RobotNodeRevoluteFactory.h>
37 #include <VirtualRobot/Robot.h>
38 #include <VirtualRobot/RobotConfig.h>
39 #include <VirtualRobot/RobotFactory.h>
40 #include <VirtualRobot/RobotNodeSet.h>
41 #include <VirtualRobot/VirtualRobot.h>
42 #include <VirtualRobot/XML/RobotIO.h>
49 #include <RobotAPI/interface/core/RobotState.h>
56 using namespace Eigen;
61 std::recursive_mutex RemoteRobot::m;
74 catch (std::exception& e)
100 return _robot->hasRobotNode(robotNodeName);
135 DMES((format(
"Node: %1%") % robotNodeName));
139 DMES(
"No cache hit");
141 _robot->getRobotNode(robotNodeName), shared_from_this());
159 NameList nodes =
_robot->getRobotNodes();
160 for (std::string
const& name : nodes)
169 return _robot->hasRobotNodeSet(name);
175 std::vector<RobotNodePtr> storeNodes;
176 RobotNodeSetInfoPtr info =
_robot->getRobotNodeSet(nodeSetName);
177 return RobotNodeSet::createRobotNodeSet(
178 shared_from_this(), nodeSetName, info->names, info->rootName, info->tcpName);
184 NameList sets =
_robot->getRobotNodeSets();
186 for (std::string
const& name : sets)
202 return _robot->getScaling();
217 VirtualRobot::RobotNodePtr
219 SharedRobotNodeInterfacePrx remoteNode,
220 std::vector<VirtualRobot::RobotNodePtr>& allNodes,
221 std::map<VirtualRobot::RobotNodePtr, std::vector<std::string>>& childrenMap,
224 std::scoped_lock cloneLock(
m);
225 static int nonameCounter = 0;
227 if (!remoteNode || !robo)
230 return VirtualRobot::RobotNodePtr();
233 VirtualRobot::RobotNodeFactoryPtr revoluteNodeFactory =
234 VirtualRobot::RobotNodeFactory::fromName(
235 VirtualRobot::RobotNodeRevoluteFactory::getName(), NULL);
236 VirtualRobot::RobotNodeFactoryPtr fixedNodeFactory =
237 VirtualRobot::RobotNodeFactory::fromName(VirtualRobot::RobotNodeFixedFactory::getName(),
239 VirtualRobot::RobotNodeFactoryPtr prismaticNodeFactory =
240 VirtualRobot::RobotNodeFactory::fromName(
241 VirtualRobot::RobotNodePrismaticFactory::getName(), NULL);
243 Eigen::Vector3f idVec3 = Eigen::Vector3f::Zero();
244 std::string name = remoteNode->getName();
249 std::stringstream ss;
250 ss <<
"robot_node_" << nonameCounter;
255 VirtualRobot::RobotNodePtr result;
256 PosePtr lTbase = PosePtr::dynamicCast(remoteNode->getLocalTransformation());
260 float jvLo = remoteNode->getJointLimitLow();
261 float jvHi = remoteNode->getJointLimitHigh();
262 float jointOffset = 0;
264 JointType jt = remoteNode->getType();
266 SceneObject::Physics physics;
267 physics.localCoM = Vector3Ptr::dynamicCast(remoteNode->getCoM())->toEigen();
268 std::vector<float> inertia = remoteNode->getInertia();
269 for (
int i = 0; i < 3; i++)
270 for (
int j = 0; j < 3; j++)
272 physics.inertiaMatrix(i, j) = inertia.at(i * 3 + j);
274 physics.massKg = remoteNode->getMass();
281 Vector3Ptr::dynamicCast(remoteNode->getJointTranslationDirection());
282 Eigen::Vector3f axis = axisBase->toEigen();
284 Eigen::Vector4f result4f = Eigen::Vector4f::Zero();
285 result4f.segment(0, 3) = axis;
286 PosePtr gp = PosePtr::dynamicCast(remoteNode->getGlobalPose());
287 result4f = gp->toEigen().inverse() * result4f;
288 axis = result4f.block(0, 0, 3, 1);
290 result = prismaticNodeFactory->createRobotNode(robo,
292 VirtualRobot::VisualizationNodePtr(),
293 VirtualRobot::CollisionModelPtr(),
305 result = fixedNodeFactory->createRobotNode(robo,
307 VirtualRobot::VisualizationNodePtr(),
308 VirtualRobot::CollisionModelPtr(),
320 Vector3Ptr axisBase = Vector3Ptr::dynamicCast(remoteNode->getJointRotationAxis());
321 Eigen::Vector3f axis = axisBase->toEigen();
323 Eigen::Vector4f result4f = Eigen::Vector4f::Zero();
324 result4f.segment(0, 3) = axis;
325 PosePtr gp = PosePtr::dynamicCast(remoteNode->getGlobalPose());
326 result4f = gp->toEigen().inverse() * result4f;
327 axis = result4f.block(0, 0, 3, 1);
329 result = revoluteNodeFactory->createRobotNode(robo,
331 VirtualRobot::VisualizationNodePtr(),
332 VirtualRobot::CollisionModelPtr(),
345 return VirtualRobot::RobotNodePtr();
349 robo->registerRobotNode(result);
350 allNodes.push_back(result);
354 std::vector<std::string> childrenBase = remoteNode->getChildren();
355 std::vector<std::string> children;
358 for (
size_t i = 0; i < childrenBase.size(); i++)
360 if (
_robot->hasRobotNode(childrenBase[i]))
362 SharedRobotNodeInterfacePrx rnRemote =
_robot->getRobotNode(childrenBase[i]);
363 VirtualRobot::RobotNodePtr localNode =
372 children.push_back(childrenBase[i]);
376 childrenMap[result] = children;
383 std::scoped_lock cloneLock(
m);
384 std::string robotType =
getName();
385 std::string robotName =
getName();
389 SharedRobotNodeInterfacePrx root =
_robot->getRootNode();
391 std::vector<VirtualRobot::RobotNodePtr> allNodes;
392 std::map<VirtualRobot::RobotNodePtr, std::vector<std::string>> childrenMap;
394 VirtualRobot::RobotNodePtr rootLocal =
createLocalNode(root, allNodes, childrenMap, robo);
397 VirtualRobot::RobotFactory::initializeRobot(robo, allNodes, childrenMap, rootLocal);
406 std::vector<std::string> rns =
_robot->getRobotNodeSets();
408 for (
size_t i = 0; i < rns.size(); i++)
410 RobotNodeSetInfoPtr rnsInfo =
_robot->getRobotNodeSet(rns[i]);
411 RobotNodeSet::createRobotNodeSet(
412 robo, rnsInfo->name, rnsInfo->names, rnsInfo->rootName, rnsInfo->tcpName,
true);
416 auto pose = PosePtr::dynamicCast(
_robot->getGlobalPose());
417 robo->setGlobalPose(pose->toEigen());
424 const Ice::StringSeq packages,
425 VirtualRobot::RobotIO::RobotDescription loadMode)
429 robotStatePrx->getScaling(),
438 const Ice::StringSeq packages,
439 VirtualRobot::RobotIO::RobotDescription loadMode)
443 std::scoped_lock cloneLock(
m);
455 std::shared_ptr<RemoteRobot> rob(
new RemoteRobot(sharedRobotPrx));
456 result = rob->createLocalClone();
466 Ice::StringSeq includePaths;
467 for (
const std::string& projectName : packages)
469 if (projectName.empty())
476 auto pathsString =
project.getDataDir();
477 ARMARX_DEBUG_S <<
"Data paths of ArmarX package " << projectName <<
": "
480 ARMARX_DEBUG_S <<
"Result: Data paths of ArmarX package " << projectName <<
": "
481 << projectIncludePaths;
483 includePaths.end(), projectIncludePaths.begin(), projectIncludePaths.end());
492 result = RobotIO::loadRobot(
filename, loadMode);
501 if (result && scaling != 1.0f)
504 result = result->clone(result->getName(), result->getCollisionChecker(), scaling);
513 RobotIO::RobotDescription loadMode)
516 robotStatePrx->getRobotFilename(),
517 robotStatePrx->getArmarXPackages(),
542 PoseBasePtr globalPose;
543 RobotConfigPtr
c(
new RobotConfig(robot,
"synchronizeLocalClone"));
544 NameValueMap jv = sharedRobotPrx->getConfigAndPose(globalPose);
546 for (NameValueMap::const_iterator it = jv.begin(); it != jv.end(); it++)
549 const std::string& jointName = it->first;
550 float jointAngle = it->second;
552 if (!
c->setConfig(jointName, jointAngle))
555 <<
"Joint not known in local copy:" << jointName <<
". Skipping...";
560 auto pose = PosePtr::dynamicCast(globalPose);
561 robot->setGlobalPose(pose->toEigen());
572 RobotConfigPtr
c(
new RobotConfig(robot,
"synchronizeLocalClone"));
573 RobotStateConfig state = robotStatePrx->getRobotStateAtTimestamp(
timestamp);
583 RobotConfigPtr
c(
new RobotConfig(robot,
"synchronizeLocalClone"));
584 if (state.jointMap.empty())
589 for (NameValueMap::const_iterator it = state.jointMap.begin(); it != state.jointMap.end();
593 const std::string& jointName = it->first;
594 float jointAngle = it->second;
596 if (!
c->setConfig(jointName, jointAngle))
599 <<
"Joint not known in local copy:" << jointName <<
". Skipping...";
604 auto pose = PosePtr::dynamicCast(state.globalPose);
605 robot->setGlobalPose(pose->toEigen());
621 return EndEffectorPtr();
671 return VirtualRobot::CollisionChecker::getGlobalCollisionChecker();