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());
257 Eigen::Matrix4f localTransform = lTbase->toEigen();
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());
436 std::string filename,
438 const Ice::StringSeq packages,
439 VirtualRobot::RobotIO::RobotDescription loadMode)
443 std::scoped_lock cloneLock(
m);
444 ARMARX_VERBOSE_S <<
"Creating local clone of remote robot (filename:" << filename <<
")";
453 if (filename.empty())
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 <<
": "
479 Ice::StringSeq projectIncludePaths = simox::alg::split(pathsString,
";,");
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);
496 ARMARX_ERROR_S <<
"Could not load robot file " << filename <<
". Aborting...";
501 if (result && scaling != 1.0f)
504 result = result->clone(result->getName(), result->getCollisionChecker(), scaling);