27 #include <SimDynamics/DynamicsEngine/BulletEngine/BulletRobot.h>
28 #include <VirtualRobot/Robot.h>
29 #include <VirtualRobot/Nodes/ForceTorqueSensor.h>
30 #include <VirtualRobot/CollisionDetection/CollisionChecker.h>
31 #include <VirtualRobot/RobotFactory.h>
41 using namespace SimDynamics;
58 void BulletPhysicsWorld::initialize(
int stepSizeMS,
int bulletFixedTimeStepMS,
int bulletFixedTimeStepMaxNrLoops,
float maxRealTimeSimSpeed,
bool floorPlane, std::string floorTexture)
60 ARMARX_INFO_S <<
"Init BulletPhysicsWorld. Creating bullet engine...";
81 ARMARX_ERROR_S <<
"Could not cast engine to BULLET engine, non-bullet engines not yet supported!";
82 throw UserException(
"Bullet engine missing");
97 ARMARX_DEBUG_S <<
"actuateRobotJoints: first:" << angles.begin()->first <<
", ang: " << angles.begin()->second <<
", vel:" << velocities.begin()->second;
98 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
105 RobotPtr kinRob = dynamicsRobot->getRobot();
107 if (!kinRob || kinRob->getName() != robotName)
121 for (
const auto&
angle : angles)
124 std::string targetJointName =
angle.first;
125 float targetJointPos =
angle.second;
126 auto velIt = velocities.find(
angle.first);
130 RobotNodePtr rn = kinRob->getRobotNode(targetJointName);
131 BulletRobot* br =
dynamic_cast<BulletRobot*
>(dynamicsRobot.get());
132 if (br && br->hasLink(rn))
134 kinRob->setJointValue(rn, targetJointPos);
135 BulletRobot::LinkInfo link = br->getLink(rn);
136 RobotNodePtr nodeCloneA;
137 RobotNodePtr nodeCloneB;
139 if (link.nodeA && link.dynNode1)
141 nodeCloneA = kinRob->getRobotNode(link.nodeA->getName());
142 link.dynNode1->setPose(nodeCloneA->getGlobalPose());
144 if (link.nodeB && link.dynNode2)
146 nodeCloneB = kinRob->getRobotNode(link.nodeB->getName());
147 link.dynNode1->setPose(nodeCloneB->getGlobalPose());
153 if (kinRob->hasRobotNode(targetJointName) && dynamicsRobot->getDynamicsRobotNode(targetJointName) && velIt != velocities.end())
155 VR_ASSERT(not kinRob->isPassive());
156 dynamicsRobot->actuateNode(dynamicsRobot->getRobot()->getRobotNode(targetJointName),
157 static_cast<double>(targetJointPos),
158 static_cast<double>(velIt->second));
171 if (angles.size() == 0)
175 ARMARX_DEBUG_S <<
"actuateRobotJointsPos: first:" << angles.begin()->first <<
", ang: " << angles.begin()->second;
179 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
187 RobotPtr kinRob = dynamicsRobot->getRobot();
189 if (!kinRob || kinRob->getName() != robotName)
195 for (
const auto&
angle : angles)
198 std::string targetJointName =
angle.first;
199 float targetJoint =
angle.second;
201 if (kinRob->hasRobotNode(targetJointName) )
203 if (isStatic or kinRob->isPassive())
205 RobotNodePtr rn = kinRob->getRobotNode(targetJointName);
206 BulletRobot* br =
dynamic_cast<BulletRobot*
>(dynamicsRobot.get());
207 if (br && br->hasLink(rn))
209 kinRob->setJointValue(rn, targetJoint);
210 BulletRobot::LinkInfo link = br->getLink(rn);
211 RobotNodePtr nodeCloneA;
212 RobotNodePtr nodeCloneB;
214 if (link.nodeA && link.dynNode1)
216 nodeCloneA = kinRob->getRobotNode(link.nodeA->getName());
217 link.dynNode1->setPose(nodeCloneA->getGlobalPose());
219 if (link.nodeB && link.dynNode2)
221 nodeCloneB = kinRob->getRobotNode(link.nodeB->getName());
222 link.dynNode1->setPose(nodeCloneB->getGlobalPose());
228 VR_ASSERT(not kinRob->isPassive());
229 dynamicsRobot->actuateNode(targetJointName,
230 static_cast<double>(targetJoint));
243 ARMARX_DEBUG_S <<
"actuateRobotJointsVel: first: vel:" << velocities.begin()->second;
245 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
252 RobotPtr kinRob = dynamicsRobot->getRobot();
254 if (!kinRob || kinRob->getName() != robotName)
265 std::map<std::string, float> res = velocities;
272 for (
const auto& velocitie : velocities)
275 std::string targetJointName = velocitie.first;
276 float targetJointVel = velocitie.second;
278 if (kinRob->hasRobotNode(targetJointName))
280 VR_ASSERT(not kinRob->isPassive());
282 dynamicsRobot->actuateNodeVel(targetJointName,
static_cast<double>(targetJointVel));
295 ARMARX_DEBUG_S <<
"actuateRobotJointsTorque: first:" << torques.begin()->first <<
"," << torques.begin()->second;
297 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
304 RobotPtr kinRob = dynamicsRobot->getRobot();
306 if (!kinRob || kinRob->getName() != robotName)
312 for (
const auto& torque : torques)
315 std::string targetJointName = torque.first;
316 float targetJointTorque = torque.second;
318 if (kinRob->hasRobotNode(targetJointName))
320 VR_ASSERT(not kinRob->isPassive());
322 dynamicsRobot->actuateNodeTorque(targetJointName,
static_cast<double>(targetJointTorque));
334 ARMARX_DEBUG_S <<
"setRobotPose:" << globalPose(0, 3) <<
"," << globalPose(1, 3) <<
", " << globalPose(2, 3);
336 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
343 RobotPtr kinRob = dynamicsRobot->getRobot();
345 if (!kinRob || kinRob->getName() != robotName)
352 dynamicsRobot->setGlobalPose(gp);
360 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
367 RobotPtr kinRob = dynamicsRobot->getRobot();
369 if (!kinRob || kinRob->getName() != robotName)
375 RobotNodePtr rn = kinRob->getRobotNode(robotNodeName);
383 dynamicsRobot->getDynamicsRobotNode(rn)->applyForce(force);
391 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
399 RobotPtr kinRob = dynamicsRobot->getRobot();
401 if (!kinRob || kinRob->getName() != robotName)
407 RobotNodePtr rn = kinRob->getRobotNode(robotNodeName);
415 dynamicsRobot->getDynamicsRobotNode(rn)->applyTorque(torque);
421 SimDynamics::DynamicsObjectPtr o =
getObject(objectName);
429 o->applyForce(force);
435 SimDynamics::DynamicsObjectPtr o =
getObject(objectName);
443 o->applyTorque(torque);
450 SimDynamics::DynamicsObjectPtr o;
451 std::vector<SimDynamics::DynamicsObjectPtr>::const_iterator it;
455 if ((*it)->getName() == objectName)
473 SimDynamics::DynamicsObjectPtr o =
getObject(objectName);
481 o->setPose(globalPose);
487 SimDynamics::DynamicsObjectPtr o =
getObject(objectName);
507 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
514 RobotPtr kinRob = dynamicsRobot->getRobot();
516 if (!kinRob || kinRob->getName() != robotName)
522 return kinRob->getMass();
528 std::map< std::string, float> res;
530 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
537 RobotPtr kinRob = dynamicsRobot->getRobot();
539 if (!kinRob || kinRob->getName() != robotName)
545 std::vector<RobotNodePtr> rn = kinRob->getRobotNodes();
551 res[i->getName()] = i->getJointValue();
564 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
571 RobotPtr kinRob = dynamicsRobot->getRobot();
573 if (!kinRob || kinRob->getName() != robotName)
579 if (!kinRob->hasRobotNode(nodeName))
585 float res = kinRob->getRobotNode(nodeName)->getJointValue();
593 std::map< std::string, float> res;
595 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
602 RobotPtr kinRob = dynamicsRobot->getRobot();
604 if (!kinRob || kinRob->getName() != robotName)
610 std::vector<RobotNodePtr> rn = kinRob->getRobotNodes();
616 float vel = dynamicsRobot->getJointSpeed(i);
617 res[i->getName()] = vel;
621 ARMARX_DEBUG_S <<
"getRobotJointVelocities:" << res.begin()->second;
629 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
636 RobotPtr kinRob = dynamicsRobot->getRobot();
638 if (!kinRob || kinRob->getName() != robotName)
644 if (!kinRob->hasRobotNode(nodeName))
650 double res = dynamicsRobot->getJointSpeed(kinRob->getRobotNode(nodeName));
652 return static_cast<float>(res);
658 std::map< std::string, float> res;
660 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
669 if (!kinRob || kinRob->getName() != robotName)
675 SimDynamics::BulletRobot* br =
dynamic_cast<BulletRobot*
>(dynamicsRobot.get());
681 std::vector<RobotNodePtr> rn = kinRob->getRobotNodes();
685 if (i->isJoint() && br)
687 if (dynamicsRobot->isNodeActuated(i))
689 res[i->getName()] = br->getJointTorque(i);
701 if (!dynamicsRobot || !virtualRobot)
703 static bool printed =
false;
710 const auto ftsensors = virtualRobot->getSensors<ForceTorqueSensor>();
711 ForceTorqueDataSeq result;
712 result.reserve(ftsensors.size());
713 for (
const VirtualRobot::ForceTorqueSensorPtr& sensor : ftsensors)
715 ForceTorqueData
data;
716 Eigen::Vector3f force = sensor->getForce();
717 Eigen::Vector3f torque = sensor->getTorque();
718 data.nodeName = sensor->getRobotNode()->getName();
719 data.sensorName = sensor->getName();
721 if (!robotName.empty() && !
data.nodeName.empty())
723 RobotNodePtr rn = dynamicsRobot->getRobot()->getRobotNode(
data.nodeName);
724 Eigen::Vector3f forceGlobal = force;
725 Eigen::Vector3f torqueGlobal = torque;
729 force = rotMat.inverse() * forceGlobal;
730 torque = rotMat.inverse() * torqueGlobal;
736 result.emplace_back(std::move(
data));
745 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
752 RobotPtr kinRob = dynamicsRobot->getRobot();
754 if (!kinRob || kinRob->getName() != robotName)
760 if (!kinRob->hasRobotNode(nodeName))
766 return kinRob->getRobotNode(nodeName)->getJointLimitLo();
773 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
780 RobotPtr kinRob = dynamicsRobot->getRobot();
782 if (!kinRob || kinRob->getName() != robotName)
788 if (!kinRob->hasRobotNode(nodeName))
794 return kinRob->getRobotNode(nodeName)->getJointLimitHi();
802 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
809 RobotPtr kinRob = dynamicsRobot->getRobot();
811 if (!kinRob || kinRob->getName() != robotName)
823 return kinRob->getGlobalPose();
831 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
838 RobotPtr kinRob = dynamicsRobot->getRobot();
840 if (!kinRob || kinRob->getName() != robotName)
852 if (!kinRob->hasRobotNode(nodeName))
858 return kinRob->getRobotNode(nodeName)->getMaxTorque();
866 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
873 RobotPtr kinRob = dynamicsRobot->getRobot();
875 if (!kinRob || kinRob->getName() != robotName)
887 if (!kinRob->hasRobotNode(nodeName))
893 kinRob->getRobotNode(nodeName)->setMaxTorque(maxTorque);
901 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
908 RobotPtr kinRob = dynamicsRobot->getRobot();
910 if (!kinRob || kinRob->getName() != robotName)
916 if (!kinRob->hasRobotNode(robotNodeName))
922 return kinRob->getRobotNode(robotNodeName)->getGlobalPose();
933 if (!dynamicsRobotNode)
937 return dynamicsRobotNode->getLinearVelocity();
943 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
949 robots.push_back(elem.first);
958 RobotPtr kinRob = dynamicsRobot->getRobot();
960 if (!kinRob || kinRob->getName() != robotName)
966 if (!kinRob->hasRobotNode(nodeName))
973 RobotNodePtr robotNode = kinRob->getRobotNode(nodeName);
974 DynamicsObjectPtr dynamicsRobotNode = dynamicsRobot->getDynamicsRobotNode(robotNode);
977 while (!dynamicsRobotNode)
979 robotNode = std::dynamic_pointer_cast<RobotNode>(robotNode->getParent());
986 dynamicsRobotNode = dynamicsRobot->getDynamicsRobotNode(robotNode);
989 return dynamicsRobotNode;
1000 if (!dynamicsRobotNode)
1005 return dynamicsRobotNode->getAngularVelocity();
1013 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1020 RobotPtr kinRob = dynamicsRobot->getRobot();
1022 if (!kinRob || kinRob->getName() != robotName)
1028 if (!kinRob->hasRobotNode(robotNodeName))
1034 dynamicsRobot->getDynamicsRobotNode(kinRob->getRobotNode(robotNodeName))->setLinearVelocity(vel);
1043 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1050 RobotPtr kinRob = dynamicsRobot->getRobot();
1052 if (!kinRob || kinRob->getName() != robotName)
1058 if (!kinRob->hasRobotNode(robotNodeName))
1064 dynamicsRobot->getDynamicsRobotNode(kinRob->getRobotNode(robotNodeName))->setAngularVelocity(vel);
1073 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1080 RobotPtr kinRob = dynamicsRobot->getRobot();
1082 if (!kinRob || kinRob->getName() != robotName)
1088 if (!kinRob->hasRobotNode(robotNodeName))
1090 ARMARX_WARNING_S <<
"No robotNode available with name '" << robotNodeName <<
"'";
1094 if (!dynamicsRobot->hasDynamicsRobotNode(kinRob->getRobotNode(robotNodeName)))
1096 ARMARX_WARNING_S <<
"No dynamic robotNode available with name '" << robotNodeName <<
"'";
1101 newPose.setIdentity();
1102 newPose.block<3, 1>(0, 3) = vel;
1103 auto globalPose = dynamicsRobot->getRobot()->getGlobalPose();
1104 globalPose(0, 3) = 0;
1105 globalPose(1, 3) = 0;
1106 globalPose(2, 3) = 0;
1107 auto globalNewPose = globalPose * newPose;
1108 dynamicsRobot->getDynamicsRobotNode(kinRob->getRobotNode(robotNodeName))->setLinearVelocity(globalNewPose.block<3, 1>(0, 3));
1117 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1124 RobotPtr kinRob = dynamicsRobot->getRobot();
1126 if (!kinRob || kinRob->getName() != robotName)
1132 if (!kinRob->hasRobotNode(robotNodeName))
1134 ARMARX_WARNING_S <<
"No robotNode available with name '" << robotNodeName <<
"'";
1138 if (!dynamicsRobot->hasDynamicsRobotNode(kinRob->getRobotNode(robotNodeName)))
1140 ARMARX_WARNING_S <<
"No dynamic robotNode available with name '" << robotNodeName <<
"'";
1145 newPose.setIdentity();
1146 newPose.block<3, 1>(0, 3) = vel;
1147 auto globalPose = dynamicsRobot->getRobot()->getGlobalPose();
1148 globalPose(0, 3) = 0;
1149 globalPose(1, 3) = 0;
1150 globalPose(2, 3) = 0;
1151 auto globalNewPose = globalPose * newPose;
1153 RobotNodePtr robotNode = kinRob->getRobotNode(robotNodeName);
1154 DynamicsObjectPtr dynamicsRobotNode = dynamicsRobot->getDynamicsRobotNode(robotNode);
1155 dynamicsRobotNode->setAngularVelocity(globalNewPose.block<3, 1>(0, 3));
1162 std::map<std::string, DynamicsRobotInfo>::iterator it =
dynamicRobots.begin();
1165 if (it->first == robotName)
1186 return (dynRob->getRobot()->hasRobotNode(robotNodeName));
1199 return r->getRobot();
1204 std::map<std::string, RobotPtr> result;
1209 result[elem.first] = (info.
robot);
1220 return SimDynamics::DynamicsRobotPtr();
1228 SimDynamics::DynamicsObjectPtr o;
1229 std::vector<SimDynamics::DynamicsObjectPtr>::const_iterator it;
1233 if ((*it)->getName() == objectName)
1255 return o->getSceneObject()->getGlobalPose();
1261 ARMARX_INFO_S <<
"Object released, robot " << robotName <<
", node:" << robotNodeName <<
", object:" << objectName;
1262 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1268 RobotPtr kinRob = dynamicsRobot->getRobot();
1270 if (!kinRob || kinRob->getName() != robotName)
1276 if (!kinRob->hasRobotNode(robotNodeName))
1282 SimDynamics::DynamicsObjectPtr o =
getObject(objectName);
1290 bool res =
dynamicsWorld->getEngine()->detachObjectFromRobot(robotName, o);
1298 ARMARX_INFO_S <<
"Object grasped, robot " << robotName <<
", node:" << robotNodeName <<
", object:" << objectName;
1303 if (ao.robotName == robotName && ao.robotNodeName == robotNodeName && ao.objectName == objectName)
1309 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1310 RobotPtr kinRob = dynamicsRobot->getRobot();
1312 if (!kinRob || kinRob->getName() != robotName)
1318 if (!kinRob->hasRobotNode(robotNodeName))
1324 RobotNodePtr rn = kinRob->getRobotNode(robotNodeName);
1327 SimDynamics::DynamicsObjectPtr o =
getObject(objectName);
1335 bool res =
dynamicsWorld->getEngine()->attachObjectToRobot(robotName, robotNodeName, o);
1336 storeLocalTransform = rn->toLocalCoordinateSystem(o->getSceneObject()->getGlobalPose());
1347 return dynamicsWorld->getEngine()->getFloor()->getSceneObject();
1357 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1368 if (robotName != dynamicsRobot->getRobot()->getName())
1399 ARMARX_ERROR_S <<
"More than one robot with identical name is currently not supported!";
1407 std::vector< RobotNodePtr > nodes = robot->getRobotNodes();
1408 for (
auto n : nodes)
1410 n->setSimulationType(SceneObject::Physics::eKinematic);
1414 SimDynamics::DynamicsRobotPtr dynamicsRobot;
1418 ARMARX_DEBUG_S <<
"add dynamicsRobot" << dynamicsRobot->getName();
1420 auto& controllers = dynamicsRobot->getControllers();
1421 std::vector<RobotNodePtr> nodes = robot->getRobotNodes();
1423 if (not robot->isPassive())
1425 ARMARX_INFO_S <<
"Configuring controllers for robot " << dynamicsRobot->getName();
1427 for (
auto node : nodes)
1429 if (node->isRotationalJoint())
1431 if (controllers.find(node) == controllers.end())
1433 controllers[node] = VelocityMotorController(
1434 static_cast<double>(node->getMaxVelocity()),
1435 static_cast<double>(node->getMaxAcceleration()));
1437 controllers[node].reset(pid_p, pid_i, pid_d);
1442 ARMARX_INFO_S <<
"The robot " << dynamicsRobot->getName() <<
" has " << controllers.size() <<
" controllers";
1444 if (not selfCollisions)
1446 dynamicsRobot->enableSelfCollisions(
false);
1450 ARMARX_DEBUG_S <<
"add dynamicsRobot2 " << dynamicsRobot->getName();
1452 catch (VirtualRobotException& e)
1462 dynamicsRobot->getRobot()->setThreadsafe(
false);
1463 dynamicsRobot->getRobot()->setUpdateVisualization(
false);
1467 robInfo.
robot = robot;
1479 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1481 if (!dynamicsRobot || dynamicsRobot->getRobot()->getName() != robotName)
1487 RobotNodePtr rn = dynamicsRobot->getRobot()->getRobotNode(frameName);
1507 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1509 if (!dynamicsRobot || robotName != dynamicsRobot->getName())
1529 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1531 if (!dynamicsRobot || robotName != dynamicsRobot->getName())
1536 double simTimeFactor = 1.0;
1544 SimDynamics::BulletRobotPtr br = std::dynamic_pointer_cast<BulletRobot>(dynamicsRobot);
1545 std::vector<RobotNodePtr> rn = kinRob->getRobotNodes();
1555 if (dynamicsRobot->isNodeActuated(i))
1557 jointVelocities[i->getName()] = dynamicsRobot->getJointSpeed(i) * simTimeFactor;
1572 DynamicsObjectPtr rootDyn = dynamicsRobot->getDynamicsRobotNode(kinRob->getRootNode());
1576 linearVelocity = rootDyn->getLinearVelocity();
1577 angularVelocity = rootDyn->getAngularVelocity();
1581 linearVelocity.setZero();
1582 angularVelocity.setZero();
1594 static bool printed =
false;
1614 std::string robotName = ftInfo.
robotName;
1616 if (!robotName.empty() && !nodeName.empty() && dynamicsRobot)
1618 RobotNodePtr rn = dynamicsRobot->getRobot()->getRobotNode(nodeName);
1619 Eigen::Vector3f forceLocal;
1621 Eigen::Vector3f torqueLocal;
1627 forceLocal = rotMat.inverse() * forceGlobal;
1628 torqueLocal = rotMat.inverse() * torqueGlobal;
1649 bool objectFound =
false;
1653 if (
s.name == oEngine->getName())
1664 ARMARX_WARNING_S <<
"Object with name " << oEngine->getName() <<
" not in synchronized list";
1680 VirtualRobot::SceneObject::Physics::SimulationType simType)
1687 DynamicsObjectPtr dynamicsObject;
1691 if (simType != VirtualRobot::SceneObject::Physics::eUnknown)
1693 o->setSimulationType(simType);
1700 catch (VirtualRobotException& e)
1702 cout <<
" ERROR while building dynamic object";
1710 dynamicsObject->getSceneObject()->setUpdateVisualization(
false);
1717 std::vector<std::string>
names;
1720 std::map<std::string, DynamicsRobotInfo>::iterator it =
dynamicRobots.begin();
1723 names.push_back(it->first);
1733 SimDynamics::DynamicsObjectPtr o =
getObject(objectName);
1739 o->setSimType(simType);
1751 DynamicsObjectPtr rn = r->getDynamicsRobotNode(robotNodeName);
1754 ARMARX_WARNING_S <<
"Could not find robot node with name " << robotNodeName;
1757 rn->setSimType(simType);
1762 std::vector<std::string>
names;
1768 names.push_back(o->getName());
1780 SimDynamics::DynamicsObjectPtr o =
getObject(name);
1837 auto startTime = IceUtil::Time::now();
1842 float stepSize =
static_cast<float>(
stepSizeMs / 1000.0);
1849 bulletEngine->stepSimulation(
static_cast<double>(stepSize),
1863 auto duration = (IceUtil::Time::now() - startTime).toMilliSecondsDouble();
1865 if (duration < minStepSizeMs)
1867 ARMARX_DEBUG <<
"Sim calculation took " << duration <<
" - Sleeping now for " << (
stepSizeMs - duration);
1868 usleep(
static_cast<unsigned int>(1000 * (minStepSizeMs - duration)));
1885 std::map<std::string, float> targetPos;
1887 ARMARX_DEBUG <<
"Applying velocities for static robot " << kinRob->getName();
1890 if (!kinRob->hasRobotNode(nv.first))
1892 ARMARX_ERROR <<
"No rn with name " << kinRob->hasRobotNode(nv.first);
1895 double change =
static_cast<double>(nv.second) * deltaInSeconds;
1899 double newAngle =
static_cast<double>(kinRob->getRobotNode(nv.first)->getJointValue()) + change;
1900 targetPos[nv.first] =
static_cast<float>(newAngle);
1903 if (not targetPos.empty())
1926 std::vector<VirtualRobot::SceneObjectPtr> res;
1929 res.push_back(o->getSceneObject());
1949 std::string textureFile = floorTexture;
1961 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
1962 BulletRobotPtr br = std::dynamic_pointer_cast<BulletRobot>(dynamicsRobot);
1971 std::vector<RobotNodePtr> rnsBodies;
1972 std::vector<RobotNodePtr> rnsJoints;
1973 std::vector<RobotNodePtr> rnAll = br->getRobot()->getRobotNodes();
1974 std::string nameJoints =
"RNS_Joints_All_logging";
1975 std::string nameBodies =
"RNS_Bodies_All_logging";
1977 for (
auto r : rnAll)
1981 rnsJoints.push_back(r);
1984 if (r->getMass() > 0)
1986 rnsBodies.push_back(r);
1990 RobotNodeSetPtr rnsJ = RobotNodeSet::createRobotNodeSet(br->getRobot(), nameJoints, rnsJoints);
1991 RobotNodeSetPtr rnsB = RobotNodeSet::createRobotNodeSet(br->getRobot(), nameBodies, rnsBodies);
2002 if (!currentObjEngine)
2007 PosePtr p(
new Pose(currentObjEngine->getGlobalPose()));
2008 objMap[currentObjEngine->getName()] = p;
2009 std::vector<SceneObjectPtr> childrenE = currentObjEngine->getChildren();
2011 for (
const auto& i : childrenE)
2032 std::stringstream ss;
2035 ss <<
c.objectAName <<
" < - > " <<
c.objectBName;
2045 btScalar
dt =
static_cast<btScalar
>(
m_clock.getTimeMicroseconds());
2054 return static_cast<int>(
contacts.size());
2061 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
2064 throw LocalException(
"No robot");
2066 if (dynamicsRobot->getName() != robotName)
2068 throw LocalException(
"Wrong robot name. '") << robotName <<
"' != '" << dynamicsRobot->getName() <<
"'";
2071 if (!robot->hasRobotNode(robotNodeName1))
2073 throw LocalException(
"Wrong robot node name. '") << robotNodeName1 <<
"'";
2075 if (!robot->hasRobotNode(robotNodeName2))
2077 throw LocalException(
"Wrong robot node name. '") << robotNodeName2 <<
"'";
2081 Eigen::Vector3f p1, p2;
2082 auto model1 = robot->getRobotNode(robotNodeName1)->getCollisionModel();
2083 auto model2 = robot->getRobotNode(robotNodeName2)->getCollisionModel();
2084 float d = robot->getCollisionChecker()->calculateDistance(model1, model2, p1, p2);
2097 SimDynamics::DynamicsRobotPtr dynamicsRobot =
getDynamicRobot(robotName);
2100 throw LocalException(
"No robot");
2102 if (dynamicsRobot->getName() != robotName)
2104 throw LocalException(
"Wrong robot name. '") << robotName <<
"' != '" << dynamicsRobot->getName() <<
"'";
2107 if (!robot->hasRobotNode(robotNodeName))
2109 throw LocalException(
"Wrong robot node name. '") << robotNodeName <<
"'";
2111 SimDynamics::DynamicsObjectPtr
object =
getObject(worldObjectName);
2114 throw LocalException(
"No object with name '") << worldObjectName <<
"'";
2117 Eigen::Vector3f p1, p2;
2119 float d = robot->getCollisionChecker()->calculateDistance(robot->getRobotNode(robotNodeName)->getCollisionModel(),
so->getCollisionModel(), p1, p2);
2130 return RobotFactory::createFlattenedModel(*robot);