27 #include <VirtualRobot/Visualization/VisualizationFactory.h>
28 #include <VirtualRobot/CollisionDetection/CollisionChecker.h>
29 #include <VirtualRobot/Nodes/ForceTorqueSensor.h>
30 #include <VirtualRobot/RobotFactory.h>
31 #include <VirtualRobot/RobotNodeSet.h>
32 #include <VirtualRobot/IK/DifferentialIK.h>
33 #include <VirtualRobot/IK/IKSolver.h>
34 #include <VirtualRobot/Obstacle.h>
88 if (up(1) == 0 && up(2) == 0)
94 else if (up(0) == 0 && up(2) == 0)
101 groundObject = VirtualRobot::Obstacle::createBox(w, h, d, VirtualRobot::VisualizationFactory::Color::Gray());
102 std::string name(
"Floor");
106 gp(2, 3) = -sizeSmall * 0.5f;
110 groundObject->setSimulationType(VirtualRobot::SceneObject::Physics::eStatic);
119 ARMARX_DEBUG_S <<
"actuateRobotJoints: first:" << angles.begin()->first <<
", ang: " << angles.begin()->second <<
", vel:" << velocities.begin()->second;
126 kinRobot->setJointValues(angles);
130 for (
auto& entry : angles)
139 if (angles.size() == 0)
143 ARMARX_DEBUG_S <<
"actuateRobotJointsPos: first:" << angles.begin()->first <<
", ang: " << angles.begin()->second;
151 kinRobot->setJointValues(angles);
155 for (
auto& entry : angles)
164 ARMARX_DEBUG_S <<
"actuateRobotJointsVel: first: vel:" << velocities.begin()->second;
176 std::map<std::string, float> res = velocities;
184 ARMARX_DEBUG_S <<
"actuateRobotJointsTorque: first:" << torques.begin()->first <<
"," << torques.begin()->second;
192 ARMARX_DEBUG <<
"setRobotPose:" << globalPose(0, 3) <<
"," << globalPose(1, 3) <<
", " << globalPose(2, 3);
201 kinRobot->setGlobalPose(globalPose);
245 o->setGlobalPose(globalPose);
260 return kinRobot->getMass();
266 std::map<std::string, float> res;
272 return std::map< std::string, float>();
275 std::vector<RobotNodePtr> rn = kinRob->getRobotNodes();
281 res[i->getName()] = i->getJointValue();
301 if (!kinRob->hasRobotNode(nodeName))
307 float res = kinRob->getRobotNode(nodeName)->getJointValue();
315 std::map< std::string, float> res;
327 ARMARX_DEBUG_S <<
"getRobotJointVelocities:" << res.begin()->second;
342 if (!kinRobot->hasRobotNode(nodeName))
361 return std::map< std::string, float>();
380 if (!kinRobot->hasRobotNode(nodeName))
386 return kinRobot->getRobotNode(nodeName)->getJointLimitLo();
400 if (!kinRobot->hasRobotNode(nodeName))
406 return kinRobot->getRobotNode(nodeName)->getJointLimitHi();
421 return kinRobot->getGlobalPose();
436 if (!kinRobot->hasRobotNode(nodeName))
442 return kinRobot->getRobotNode(nodeName)->getMaxTorque();
457 if (!kinRobot->hasRobotNode(nodeName))
463 kinRobot->getRobotNode(nodeName)->setMaxTorque(maxTorque);
478 if (!kinRobot->hasRobotNode(robotNodeName))
484 return kinRobot->getRobotNode(robotNodeName)->getGlobalPose();
518 RobotNodePtr rn = kinRobot->getRobotNode(nodeName);
526 RobotNodeSetPtr rns = RobotNodeSet::createRobotNodeSet(kinRobot,
"All_Nodes", kinRobot->getRobotNodes());
527 DifferentialIKPtr j(
new DifferentialIK(rns));
531 std::vector<std::string> nodeNames = rns->getNodeNames();
532 Eigen::VectorXf joint_vel(nodeNames.size());
534 for (std::vector<std::string>::iterator it = nodeNames.begin(); it != nodeNames.end(); ++it, ++i)
539 Eigen::Vector3f omega;
540 omega = jac * joint_vel;
595 newPose.setIdentity();
596 newPose.block<3, 1>(0, 3) = vel;
597 auto globalPose = kinRobot->getGlobalPose();
598 globalPose(0, 3) = 0;
599 globalPose(1, 3) = 0;
600 globalPose(2, 3) = 0;
620 newPose.setIdentity();
621 newPose.block<3, 1>(0, 3) = vel;
623 globalPose(0, 3) = 0;
624 globalPose(1, 3) = 0;
625 globalPose(2, 3) = 0;
634 std::map<std::string, KinematicRobotInfo>::iterator it =
kinematicRobots.begin();
637 if (it->first == robotName)
658 return (kinRobot->hasRobotNode(robotNodeName));
677 std::map<std::string, RobotPtr> result;
682 result[elem.first] = (info.
robot);
690 std::vector<VirtualRobot::SceneObjectPtr>::const_iterator it;
694 if ((*it)->getName() == objectName)
716 return o->getGlobalPose();
722 ARMARX_INFO_S <<
"Object released, robot " << robotName <<
", node:" << robotNodeName <<
", object:" << objectName;
730 if (!kinRobot->hasRobotNode(robotNodeName))
743 RobotNodePtr rn = kinRobot->getRobotNode(objectName);
750 bool res = RobotFactory::detach(kinRobot, rn);
757 ARMARX_INFO_S <<
"Object grasped, robot " << robotName <<
", node:" << robotNodeName <<
", object:" << objectName;
762 if (ao.robotName == robotName && ao.robotNodeName == robotNodeName && ao.objectName == objectName)
775 if (!kinRobot->hasRobotNode(robotNodeName))
781 RobotNodePtr rn = kinRobot->getRobotNode(robotNodeName);
791 storeLocalTransform = rn->toLocalCoordinateSystem(o->getGlobalPose());
792 bool res = RobotFactory::attach(kinRobot, o, rn, storeLocalTransform);
836 ARMARX_ERROR_S <<
"More than robot with identical name is currently not supported!";
849 RobotPtr r = robot->clone(robot->getName());
852 r->setThreadsafe(
false);
853 r->setUpdateVisualization(
false);
854 r->setPropagatingJointValuesEnabled(
false);
874 RobotNodePtr rn = kinRobot->getRobotNode(frameName);
918 auto robotName =
data.first;
926 std::vector<RobotNodePtr> rn = kinRobot->getRobotNodes();
934 std::string n = i->getName();
947 jointVelocities[n] = (i->getJointValue() - filterIt->second.second) / (timestamp - filterIt->second.first).toSecondsDouble();
948 filterIt->second.second = i->getJointValue();
949 filterIt->second.first = timestamp;
966 Eigen::Vector3f linearVelocity;
968 Eigen::Vector3f pos = kinRobot->getGlobalPose().block<3, 1>(0, 3);
971 filterIt =
linearVelocityFilters.insert(std::make_pair(kinRobot, std::make_pair(timestamp, pos))).first;
973 linearVelocity = (pos - filterIt->second.second) / (timestamp - filterIt->second.first).toSecondsDouble();
974 filterIt->second.second = pos;
975 filterIt->second.first = timestamp;
982 Eigen::Vector3f angularVelocity;
983 angularVelocity.setZero();
989 filterVelIt =
angularVelocityFilters.insert(std::make_pair(kinRobot, std::make_pair(timestamp, kinRobot->getGlobalPose()))).first;
992 double deltaTimestamp = (timestamp - filterVelIt->second.first).toSecondsDouble();
1007 Rot_prev = filterVelIt->second.second.block(0, 0, 3, 3);
1008 Rot_new = kinRobot->getGlobalPose().block(0, 0, 3, 3);
1009 A = Rot_new * Rot_prev.transpose();
1010 theta = acos((
A.trace() - 1) / 2.);
1018 Omega_mat = theta * (
A -
A.transpose()) / (2 * deltaTimestamp * sin(theta));
1023 if (deltaTimestamp > 0.1)
1042 std::vector<RobotNodePtr> rn = kinRobot->getRobotNodes();
1057 std::string n = i->getName();
1113 bool objectFound =
false;
1117 if (
s.name == oEngine->getName())
1128 ARMARX_WARNING_S <<
"Object with name " << oEngine->getName() <<
" not in synchronized list";
1145 clonedObj->setUpdateVisualization(
false);
1152 std::vector<std::string>
names;
1155 std::map<std::string, KinematicRobotInfo>::iterator it =
kinematicRobots.begin();
1158 names.push_back(it->first);
1186 RobotNodePtr rn = r->getRobotNode(robotNodeName);
1189 ARMARX_WARNING_S <<
"Could not find robot node with name " << robotNodeName;
1197 std::vector<std::string>
names;
1203 names.push_back(o->getName());
1267 auto startTime = IceUtil::Time::now();
1287 auto duration = (IceUtil::Time::now() - startTime).toMilliSecondsDouble();
1289 if (duration < minStepSizeMs)
1291 ARMARX_DEBUG <<
"Sim calculation took " << duration <<
" - Sleeping now for " << (
stepSizeMs - duration);
1292 usleep(1000 * (minStepSizeMs - duration));
1307 std::map<std::string, float> targetPos;
1309 ARMARX_DEBUG <<
"Applying velocities for static robot " << kinRob->getName();
1312 if (!kinRob->hasRobotNode(nv.first))
1317 double change = (nv.second * deltaInSeconds);
1321 double newAngle = kinRob->getRobotNode(nv.first)->getJointValue() + change;
1322 targetPos[nv.first] = (
float)newAngle;
1324 if (targetPos.size() > 0)
1327 kinRob->setJointValues(targetPos);
1334 m3 = Eigen::AngleAxisf(ri.
velRotTarget(0) * deltaInSeconds, Eigen::Vector3f::UnitX())
1335 * Eigen::AngleAxisf(ri.
velRotTarget(1) * deltaInSeconds, Eigen::Vector3f::UnitY())
1336 * Eigen::AngleAxisf(ri.
velRotTarget(2) * deltaInSeconds, Eigen::Vector3f::UnitZ());
1337 gp.block(0, 0, 3, 3) *= m3;
1357 if (!kinRob->hasRobotNode(o.objectName))
1363 Eigen::Matrix4f pose = kinRob->getRobotNode(o.objectName)->getGlobalPose();
1367 if (kino->getName() == o.objectName)
1369 kino->setGlobalPose(pose);
1384 return std::vector<SimDynamics::DynamicsEngine::DynamicsContactInfo>();
1397 std::string textureFile = floorTexture;
1402 Eigen::Vector3f pos;
1404 Eigen::Vector3f up = Eigen::Vector3f::UnitZ();
1419 if (!currentObjEngine)
1424 PosePtr p(
new Pose(currentObjEngine->getGlobalPose()));
1425 objMap[currentObjEngine->getName()] = p;
1426 std::vector<SceneObjectPtr> childrenE = currentObjEngine->getChildren();
1428 for (
const auto& i : childrenE)
1463 auto newEndTime = IceUtil::Time::now();
1464 auto frameTime = newEndTime -
lastTime;
1467 return (
float)(frameTime).toMilliSecondsDouble();;
1484 throw LocalException(
"Wrong robot name. '") << robotName <<
"'";
1487 if (!robot->hasRobotNode(robotNodeName1))
1489 throw LocalException(
"Wrong robot node name. '") << robotNodeName1 <<
"'";
1491 if (!robot->hasRobotNode(robotNodeName2))
1493 throw LocalException(
"Wrong robot node name. '") << robotNodeName2 <<
"'";
1497 Eigen::Vector3f p1, p2;
1498 auto model1 = robot->getRobotNode(robotNodeName1)->getCollisionModel();
1499 auto model2 = robot->getRobotNode(robotNodeName2)->getCollisionModel();
1500 float d = robot->getCollisionChecker()->calculateDistance(model1, model2, p1, p2);
1516 throw LocalException(
"Wrong robot name. '") << robotName <<
"'";
1519 if (!robot->hasRobotNode(robotNodeName))
1521 throw LocalException(
"Wrong robot node name. '") << robotNodeName <<
"'";
1526 throw LocalException(
"No object with name '") << worldObjectName <<
"'";
1528 Eigen::Vector3f p1, p2;
1530 float d = robot->getCollisionChecker()->calculateDistance(robot->getRobotNode(robotNodeName)->getCollisionModel(),
so->getCollisionModel(), p1, p2);