27#include <VirtualRobot/MathTools.h>
28#include <VirtualRobot/XML/BaseIO.h>
29#include <VirtualRobot/Obstacle.h>
30#include <VirtualRobot/ManipulationObject.h>
31#include <VirtualRobot/XML/RobotIO.h>
36#define MAX_SIM_TIME_WARNING 25
42#ifdef MUJOCO_PHYSICS_WORLD
46#include <SimoxUtility/algorithm/string/string_tools.h>
47#include <SimoxUtility/json.h>
48#include <VirtualRobot/Scene.h>
49#include <VirtualRobot/SceneObject.h>
50#include <VirtualRobot/XML/ObjectIO.h>
51#include <VirtualRobot/math/Helpers.h>
57#include <RobotAPI/interface/core/GeometryBase.h>
69#include <SimDynamics/DynamicsEngine/DynamicsObject.h>
70#include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
72#ifdef ENABLE_SDF_FORMAT
83 "SimoxSceneFileName",
"",
"Simox/VirtualRobot scene file name, e.g. myScene.xml");
87 "LongtermMemory.SnapshotName",
"",
"Name of snapshot to load the scene")
88 .setCaseInsensitive(
true);
90 "LoadSnapshotToWorkingMemory",
true,
"Load the snapshot also into the WorkingMemory");
93 "Also load the agents from the snapshot into the WorkingMemory");
96 "WorkingMemoryName",
"WorkingMemory",
"Name of WorkingMemory")
97 .setCaseInsensitive(
true);
99 "CommonStorageName",
"CommonStorage",
"Name of CommonStorage")
100 .setCaseInsensitive(
true);
102 "PriorKnowledgeName",
"PriorKnowledge",
"Name of PriorKnowledge")
103 .setCaseInsensitive(
true);
105 "LongtermMemoryName",
"LongtermMemory",
"Name of LongtermMemory")
106 .setCaseInsensitive(
true);
109 "PriorKnowledgeData",
110 "Package to search for object models."
111 "Used when loading scenes from JSON files.");
114 "Path to one or multiple JSON scene file(s) to load.\n"
115 "Example: 'PriorKnowledgeData/scenes/MyScene.json'.\n"
116 "Multiple paths are separated by semicolons (';').\n"
117 "The package to load a scene from is automatically"
118 "extracted from its first path segment.");
122 "Simulation type (Supported: Bullet, Kinematics, Mujoco)")
126 .setCaseInsensitive(
true);
137 "RobotFileName" + postfix,
139 "Simox/VirtualRobot robot file name, e.g. robot_model.xml");
141 "RobotInstanceName" + postfix,
"",
"Name of this robot instance");
143 "RobotIsStatic" + postfix,
145 "A static robot does not move due to the physical environment (i.e. no gravity). \n"
146 "It is a static (but kinematic) object in the world.");
149 "RobotCollisionModel" + postfix,
false,
"Show the collision model of the robot.");
151 "InitialRobotPose.x" + postfix, 0.f,
"x component of initial robot position (mm)");
153 "InitialRobotPose.y" + postfix, 0.f,
"y component of initial robot position (mm)");
155 "InitialRobotPose.z" + postfix, 0.f,
"z component of initial robot position (mm)");
158 "Initial robot pose: roll component of RPY angles (radian)");
161 "Initial robot pose: pitch component of RPY angles (radian)");
164 "Initial robot pose: yaw component of RPY angles (radian)");
166 "InitialRobotConfig" + postfix,
168 "Initial robot config as comma separated list (RobotNodeName:value)");
171 "InitialNamedRobotConfig" + postfix,
173 "Initial named robot config, e.g., `Home`.");
176 "RobotScaling" + postfix, 1.0f,
"Scaling of the robot (1 = no scaling).");
178 "RobotControllerPID.p" + postfix, 10.0,
"Setup robot controllers: PID paramter p.");
180 "RobotControllerPID.i" + postfix, 0.0,
"Setup robot controllers: PID paramter i.");
182 "RobotControllerPID.d" + postfix, 0.0,
"Setup robot controllers: PID paramter d.");
184 "RobotSelfCollisions" + postfix,
186 "If false, the robot bodies will not collide with other bodies of this \n"
187 "robot but with all other bodies in the world. \n"
188 "If true, the robot bodies will collide with all other bodies \n"
189 "(This needs an accurately modelled robot model without self collisions \n"
190 "if the robot does not move.)");
193 "FixedTimeStepLoopNrSteps",
195 "The maximum number of internal simulation loops (fixed time step mode).\n"
196 "After max number of time steps, the remaining time is interpolated.");
198 "FixedTimeStepStepTimeMS",
200 "The simulation's internal timestep (fixed time step mode). \n"
201 "This property determines the precision of the simulation. \n"
202 "Needs to be set to bigger values for slow PCs, but the simulation results might be bad. "
203 "Smaller value for higher precision, but slower calculation.");
208 "If true the timestep is adjusted to the computing power of the host and \n"
209 "the time progress in real time. Can result in bad results on slow PCs. \n"
210 "The property StepTimeMS has then no effect. FixedTimeStepStepTimeMS needs \n"
211 "to be adjusted if real time cannot be achieved on slower PCs.");
215 "If not zero and the real time mode is off, the simulator will not run \n"
216 "\tfaster than real-time * MaxRealTime even if the machine is fast enough \n"
217 "\t(a sleep is inserted to slow down the simulator - the precision remains unchanged).\n"
218 "\tIf set to 2, the simulator will not run faster than double speed. \n"
219 "\tIf set to 0.5, the simulator will not run faster than half speed. \n"
220 "\tIf set to 0, the simulator will run as fast as possible.\n");
225 "Enable robot logging. If true, the complete robot state is logged to a file each step.");
229 "How often should the visualization data be published. Value is "
230 "given in Hz. (0 to disable)");
232 "ReportVisuTopicName",
233 "SimulatorVisuUpdates",
234 "The topic on which the visualization updates are published.");
236 "ReportDataFrequency",
238 "How often should the robot data be published. Value is given in Hz. (0 to disable)");
242 "Fixate objects or parts of a robot in the world. Comma separated list. \n"
243 "Define objects by their name, robots can be defined with robotName:RobotNodeName");
246 "If true the CoM of each robot is drawn as a circle on the ground "
247 "after each simulation cycle.");
297 if (!snapshotName.empty())
299 ARMARX_LOG <<
"UsingProxy LongtermMemory for snapshot " << snapshotName;
307 ARMARX_LOG <<
"Not using LongtermMemoryProxy";
331 switch (simulatorType)
336 kw->initialize(stepTimeMs, maxRealTime, floorPlane, floorTexture);
342 int bulletFixedTimeStepMS =
getProperty<int>(
"FixedTimeStepStepTimeMS").getValue();
343 int bulletFixedTimeStepMaxNrLoops =
346 bw->initialize(stepTimeMs,
347 bulletFixedTimeStepMS,
348 bulletFixedTimeStepMaxNrLoops,
357#ifdef MUJOCO_PHYSICS_WORLD
361 mw->initialize(stepTimeMs, floorPlane, floorTexture);
365 ARMARX_ERROR <<
"Simulator type 'mujoco' is not supported, since simulator was built "
367 <<
"\nGet the package MujocoX from: https://gitlab.com/h2t/mujoco .";
380Simulator::addRobotsFromProperties()
396 Eigen::Matrix4f gp = Eigen::Matrix4f::Identity();
398 VirtualRobot::MathTools::rpy2eigen4f(
404 math::Helpers::Position(gp) =
410 std::map<std::string, float> initConfig;
414 std::string confStr =
420 std::string robFileGlobal = robotFile;
424 ARMARX_ERROR <<
"Could not find robot file " << robotFile;
427 const auto robot = VirtualRobot::RobotIO::loadRobot(robFileGlobal, VirtualRobot::BaseIO::eStructure);
430 const std::optional<std::map<std::string, float>> namedConfig =
431 robot->getConfiguration(confStr);
434 <<
"Could not find named robot config " <<
QUOTED(confStr) <<
" in robot file "
437 initConfig = namedConfig.value();
443 <<
" because InitialNamedRobotConfig is set.";
450 std::string confStr =
452 std::vector<std::string> confList =
Split(confStr,
",",
true,
true);
453 for (
auto& pos : confList)
456 std::vector<std::string> d =
Split(pos,
":",
true,
true);
462 std::string name = d.at(0);
464 initConfig[name] =
static_cast<float>(atof(d.at(1).c_str()));
465 ARMARX_INFO <<
"1:'" << name <<
"', 2:" << initConfig[name];
474 std::string robotInstanceName =
478 bool colModelRobot =
getProperty<bool>(
"RobotCollisionModel" + postfix).getValue();
481 if (!robotFile.empty())
483 std::string robFileGlobal = robotFile;
487 ARMARX_ERROR <<
"Could not find robot file " << robotFile;
491 ARMARX_INFO <<
"Adding robot with name '" << robotInstanceName <<
"' from file "
511Simulator::addSceneFromFile(
const std::string& sceneFile)
516 ARMARX_ERROR <<
"Could not find scene file " << sceneFile;
528Simulator::addSceneFromMemorySnapshot(
const std::string& snapshotName)
533 ARMARX_ERROR <<
"No connection to memory - cannot add snapshot!";
543 WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx;
547 ARMARX_LOG <<
"Loading snapshot " << snapshotName;
551 snapshotInterfacePrx =
556 if (snapshotInterfacePrx)
562 ARMARX_ERROR <<
"Could not get snapshot segment from longterm memory...";
566 catch (memoryx::SnapshotNotFoundException&)
568 ARMARX_ERROR <<
"Could not find snapshot: " << snapshotName;
572 ARMARX_ERROR <<
"Failed to load snapshot with name:" << snapshotName;
577 ARMARX_ERROR <<
"Could not get PriorKnowledge/LongtermMemory/WorkingMemory Proxy";
582 ARMARX_LOG <<
"Found and opened snapshot " << snapshotName;
587 ARMARX_ERROR <<
"Failed to open snapshot " << snapshotName;
592Simulator::addSceneFromSdfFile(
const std::string& scenePath)
594#ifdef ENABLE_SDF_FORMAT
595 std::string scenePackage = simox::alg::split(scenePath,
"/").at(0);
596 CMakePackageFinder cmakeFinder(scenePackage);
597 if (!cmakeFinder.packageFound())
599 ARMARX_WARNING <<
"Could not find CMake package " << scenePackage <<
".";
603 std::filesystem::path dataDir = cmakeFinder.getDataDir();
604 std::filesystem::path path = dataDir / scenePath;
607 sdf::SDFPtr sdfFile(
new sdf::SDF());
610 std::filesystem::path modelDirectory = path.parent_path();
612 const std::string modelURI =
"model://";
614 auto findFileCallback = [
this, &modelURI](
const std::string& uri) -> std::string
616 std::stringstream ss;
617 ss <<
"Find '" << uri <<
"' ... -> ";
619 const std::string classIDStr = simox::alg::remove_prefix(uri, modelURI);
622 if (std::optional<ObjectInfo> info =
objectFinder.findObject(classID))
624 if (std::optional<PackageFileLocation> modelPath = info->getModel())
626 std::filesystem::path result = modelPath->absolutePath.parent_path();
640 parser.AddURIPath(modelURI, modelDirectory.string());
641 parser.SetFindCallback(findFileCallback);
644 sdf::Errors errors = root.Load(path.string(), parser);
646 for (
auto const& error : errors)
657 if (root.WorldCount() == 0)
663 if (root.WorldCount() > 1)
669 sdf::World* world = root.WorldByIndex(0);
670 auto addSceneObject = [&](sdf::Model* model)
672 const std::string name = model->Name();
675 ARMARX_WARNING <<
"Object with name \"" << name <<
"\" already exists.";
679 const std::string uri = model->Uri();
682 ARMARX_WARNING <<
"No URI set for object \"" << name <<
"\" in SDF.";
688 const std::filesystem::path modelPath = findFileCallback(uri);
690 gz::math::Pose3d pose = model->RawPose();
692 const float meterToMillimeter = 1000.0F;
694 Eigen::Vector3f position;
695 position.x() =
static_cast<float>(pose.Pos().X() * meterToMillimeter);
696 position.y() =
static_cast<float>(pose.Pos().Y() * meterToMillimeter);
697 position.z() =
static_cast<float>(pose.Pos().Z() * meterToMillimeter);
700 orientation.x() =
static_cast<float>(pose.Rot().X());
701 orientation.y() =
static_cast<float>(pose.Rot().Y());
702 orientation.z() =
static_cast<float>(pose.Rot().Z());
703 orientation.w() =
static_cast<float>(pose.Rot().W());
705 auto isStatic = model->Static();
707 std::string robotFilename = modelPath.filename().generic_string() +
".urdf";
708 std::filesystem::path robotPath = modelPath / robotFilename;
710 std::string xmlFilename = modelPath.filename().generic_string() +
".xml";
711 std::filesystem::path xmlPath = modelPath / xmlFilename;
713 if (std::filesystem::exists(xmlPath))
715 ARMARX_INFO <<
"Loading object '" << name <<
"' from object XML file " << xmlPath;
716 VirtualRobot::ManipulationObjectPtr simoxObject =
717 VirtualRobot::ObjectIO::loadManipulationObject(xmlPath.string());
719 simoxObject->setGlobalPose(simox::math::pose(position, orientation));
721 VirtualRobot::SceneObject::Physics::SimulationType simType =
722 isStatic ? VirtualRobot::SceneObject::Physics::eKinematic
723 : VirtualRobot::SceneObject::Physics::eDynamic;
725 simoxObject->setSimulationType(simType);
726 simoxObject->setFilename(xmlPath.string());
727 simoxObject->setName(name);
730 simoxObject, simType, xmlPath.string(), name, {}, scenePackage);
732 else if (std::filesystem::exists(robotPath))
734 ARMARX_INFO <<
"Loading object '" << name <<
"' from robot URDF file " << xmlPath;
737 robot->setGlobalPose(simox::math::pose(position, orientation));
739 VirtualRobot::SceneObject::Physics::SimulationType simType =
740 isStatic ? VirtualRobot::SceneObject::Physics::eKinematic
741 : VirtualRobot::SceneObject::Physics::eDynamic;
743 robot->setSimulationType(simType);
744 robot->setFilename(robotPath.string());
745 robot->setName(name);
747 physicsWorld->addRobot(robot, 10.0, 0.0, 0.0, robotPath.string(), isStatic);
752 <<
"Not adding object '" << name
753 <<
"' because neither object XML nor robot URDF file exist. (Tried object XML = "
754 << xmlPath <<
" and robot URDF = " << robotPath <<
")";
760 addSceneObject(world->ModelByIndex(
index));
763 ARMARX_ERROR <<
"Loading from SDF file was not compiled";
768Simulator::addSceneFromJsonFile(
const std::string& scenePath)
770 std::string mutScenePath = scenePath;
771 if (!simox::alg::ends_with(mutScenePath,
".json"))
773 mutScenePath +=
".json";
776 std::string scenePackage = simox::alg::split(scenePath,
"/").at(0);
777 CMakePackageFinder cmakeFinder(scenePackage);
778 if (!cmakeFinder.packageFound())
780 ARMARX_WARNING <<
"Could not find CMake package " << scenePackage <<
".";
784 std::filesystem::path dataDir = cmakeFinder.getDataDir();
785 std::filesystem::path path = dataDir / scenePath;
787 armarx::objects::Scene scene;
790 scene = simox::json::read<armarx::objects::Scene>(path);
792 catch (
const simox::json::error::JsonError& e)
794 ARMARX_WARNING <<
"Loading scene snapshot failed: \n" << e.what();
798 std::map<ObjectID, int> idCounters;
799 for (
const auto&
object : scene.
objects)
801 if (simox::alg::starts_with(
object.className,
"#"))
807 addJsonSceneObject(
object, idCounters);
812Simulator::addJsonSceneObject(
const armarx::objects::SceneObject
object,
813 std::map<ObjectID, int>& idCounters)
816 const std::string name =
818 .
withInstanceName(
object.instanceName.empty() ? std::to_string(idCounters[classID]++)
819 :
object.instanceName)
824 ARMARX_INFO <<
"Object with name \"" << name <<
"\" already exists.";
828 ARMARX_INFO <<
"Adding object with name \"" << name <<
"\" to scene.";
830 std::optional<ObjectInfo> objectInfo =
objectFinder.findObject(classID);
831 VirtualRobot::ManipulationObjectPtr simoxObject =
832 VirtualRobot::ObjectIO::loadManipulationObject(objectInfo->simoxXML().absolutePath);
833 simoxObject->setGlobalPose(simox::math::pose(
object.position,
object.orientation));
835 VirtualRobot::SceneObject::Physics::SimulationType simType;
836 if (
object.isStatic.has_value())
838 simType = *
object.isStatic ? VirtualRobot::SceneObject::Physics::eKinematic
839 : VirtualRobot::SceneObject::Physics::eDynamic;
843 simType = VirtualRobot::SceneObject::Physics::eKinematic;
846 PackageFileLocation simoxXml = objectInfo->simoxXML();
847 simoxObject->setSimulationType(simType);
849 simoxObject->setName(name);
856Simulator::fixateRobotNode(
const std::string& robotName,
const std::string& robotNodeName)
858 ARMARX_VERBOSE <<
"Fixing robot node" << robotName <<
"." << robotNodeName;
860 robotName, robotNodeName, VirtualRobot::SceneObject::Physics::eStatic);
864Simulator::fixateObject(
const std::string& objectName)
867 physicsWorld->setObjectSimType(objectName, VirtualRobot::SceneObject::Physics::eStatic);
875 addRobotsFromProperties();
878 if (!sceneFile.empty())
880 addSceneFromFile(sceneFile);
884 if (!snapshotName.empty())
886 addSceneFromMemorySnapshot(snapshotName);
893 if (!scenePaths.empty())
896 for (
const std::string& scenePath : simox::alg::split(scenePaths,
";", trim))
898 std::filesystem::path path = scenePath;
899 std::string sdfExtension =
".sdf";
901 if (path.has_extension() && path.extension().string() == sdfExtension)
903 ARMARX_INFO <<
"Loading scene from SDF file '" << scenePath <<
"' ...";
904 addSceneFromSdfFile(scenePath);
908 ARMARX_INFO <<
"Loading scene from JSON file '" << scenePath <<
"' ...";
909 addSceneFromJsonFile(scenePath);
916 if (!fixedObjects.empty())
918 std::vector<std::string>
objects =
Split(fixedObjects,
",;");
921 std::vector<std::string> rob =
Split(o,
":");
925 fixateRobotNode(rob.at(0), rob.at(1));
941 SimulatedRobotState state;
943 state.hasRobot =
true;
944 state.timestampInMicroSeconds =
timestamp.toMicroSeconds();
956 if (forceTorqueSensor.enable)
958 ForceTorqueData& ftData = state.forceTorqueValues.emplace_back();
959 ftData.force =
new Vector3(forceTorqueSensor.currentForce);
960 ftData.torque =
new Vector3(forceTorqueSensor.currentTorque);
961 ftData.sensorName = forceTorqueSensor.sensorName;
962 ftData.nodeName = forceTorqueSensor.robotNodeName;
975 <<
"Was able to find a reference to the CommonStorage. Continue with existing "
976 "connection to memory.";
979 CommonStorageInterfacePrx commonStoragePrx =
982 if (commonStoragePrx)
985 <<
"Was able to find a reference to the CommonStorage. Reset GridFSManager and "
986 "continue with memory.";
992 <<
"Could not get CommonStorage Proxy - continuing without memory";
1013 ARMARX_DEBUG <<
"Starting periodic simulation task in ArmarX Simulator";
1018 ARMARX_DEBUG <<
"Starting periodic visualization report task in ArmarX Simulator";
1032 int cycleTime = 1000 / hzVisu;
1039 ARMARX_DEBUG <<
"Starting periodic data report task in ArmarX Simulator";
1048 int cycleTime = 1000 / hzData;
1111 IceUtil::ThreadControl threadControl = getThreadControl();
1116 threadControl.join();
1127 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1128 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1164 const std::string segmentName =
"objectInstances";
1168 PersistentEntitySegmentBasePrx segInstances = snapshotInterfacePrx->getSegment(segmentName);
1172 ARMARX_ERROR <<
"Segment not found in snapshot: " << segmentName;
1177 PersistentObjectClassSegmentBasePrx classesSegmentPrx =
1180 if (!classesSegmentPrx)
1182 ARMARX_ERROR <<
"Classes Segment not found in PriorKnowledge";
1187 EntityIdList ids = segInstances->getAllEntityIds();
1191 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
1193 EntityBasePtr snapEntity = segInstances->getEntityById(*it);
1195 std::string
id = snapInstance->getId();
1196 bool ok = snapInstance->hasAttribute(
"classes");
1201 <<
" has no classes attribute, could not load iv files, skipping";
1205 std::string classesName = snapInstance->getAttributeValue(
"classes")->getString();
1207 EntityBasePtr classesEntity = classesSegmentPrx->getEntityByName(classesName);
1211 ARMARX_ERROR <<
"Classes Segment does not know class with name : " << classesName;
1215 ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(classesEntity);
1219 ARMARX_ERROR <<
"Could not cast class entity : " << classesName;
1224 Eigen::Matrix4f m = Eigen::Matrix4f::Identity();
1231 m.block<3,1>(0, 3) = objPos->toEigen();
1239 m.block<3,3>(0, 0) = objOrient->toEigen();
1245 VirtualRobot::ManipulationObjectPtr mo = sw->getManipulationObject()->clone(
1246 sw->getManipulationObject()
1251 std::string instanceName = snapInstance->getName();
1255 instanceName = snapInstance->getName() +
"_" +
to_string(i);
1258 if (instanceName != snapInstance->getName())
1260 ARMARX_INFO <<
"Object instance with name '" << snapInstance->getName()
1261 <<
"'' already exists - using '" << instanceName <<
"'";
1264 mo->getSimulationType() == VirtualRobot::SceneObject::Physics::eStatic;
1265 addObject(objectClass, instanceName, poseGlobal, isStatic);
1289 const std::string segmentName =
"agentInstances";
1293 PersistentEntitySegmentBasePrx segInstances = snapshotInterfacePrx->getSegment(segmentName);
1297 ARMARX_ERROR <<
"Segment not found in snapshot: " << segmentName;
1301 EntityIdList ids = segInstances->getAllEntityIds();
1304 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
1306 EntityBasePtr snapEntity = segInstances->getEntityById(*it);
1309 auto agentName = snapAgent->getName();
1310 std::string agentModelFile = snapAgent->getAgentFilePath();
1311 std::string absModelFile;
1314 ARMARX_INFO <<
"Robot with name '" << agentName <<
"' already exists.";
1320 <<
"'- file not found: " << agentModelFile;
1326 if (
addRobot(agentName, absModelFile, snapAgent->getPose()->toEigen(), agentModelFile)
1343 const NameValueMap& angles,
1344 const NameValueMap& velocities,
1345 const Ice::Current&)
1347 physicsWorld->actuateRobotJoints(robotName, angles, velocities);
1352 const NameValueMap& angles,
1353 const Ice::Current&)
1355 physicsWorld->actuateRobotJointsPos(robotName, angles);
1360 const NameValueMap& velocities,
1361 const Ice::Current&)
1363 physicsWorld->actuateRobotJointsVel(robotName, velocities);
1368 const NameValueMap& torques,
1369 const Ice::Current&)
1371 physicsWorld->actuateRobotJointsTorque(robotName, torques);
1376 const PoseBasePtr& globalPose,
1377 const Ice::Current&)
1379 VirtualRobot::MathTools::Quaternion qa;
1380 qa.x = globalPose->orientation->qx;
1381 qa.y = globalPose->orientation->qy;
1382 qa.z = globalPose->orientation->qz;
1383 qa.w = globalPose->orientation->qw;
1384 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1385 gp(0, 3) = globalPose->position->x;
1386 gp(1, 3) = globalPose->position->y;
1387 gp(2, 3) = globalPose->position->z;
1393 const std::string& robotNodeName,
1394 const Vector3BasePtr& force,
1395 const Ice::Current&)
1397 Vector3Ptr v3p = Vector3Ptr::dynamicCast(force);
1398 physicsWorld->applyForceRobotNode(robotName, robotNodeName, v3p->toEigen());
1403 const std::string& robotNodeName,
1404 const Vector3BasePtr& torque,
1405 const Ice::Current&)
1407 Vector3Ptr v3p = Vector3Ptr::dynamicCast(torque);
1408 physicsWorld->applyTorqueRobotNode(robotName, robotNodeName, v3p->toEigen());
1413 const Vector3BasePtr& force,
1414 const Ice::Current&)
1416 Vector3Ptr v3p = Vector3Ptr::dynamicCast(force);
1417 physicsWorld->applyForceObject(objectName, v3p->toEigen());
1422 const Vector3BasePtr& torque,
1423 const Ice::Current&)
1425 Vector3Ptr v3p = Vector3Ptr::dynamicCast(torque);
1426 physicsWorld->applyTorqueObject(objectName, v3p->toEigen());
1431 const std::string& instanceName,
1432 const PoseBasePtr& globalPose,
1434 const Ice::Current&)
1439 ARMARX_WARNING <<
"Cannot add object - no connection to common storage";
1442 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1443 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1448 ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(objectClassBase);
1452 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" already exists";
1458 ARMARX_ERROR <<
"Invalid object class; could not create object with instance name "
1466 VirtualRobot::ManipulationObjectPtr mo =
1467 sw->getManipulationObject();
1471 ARMARX_ERROR <<
"Could not retrieve manipulation object of object class "
1472 << objectClass->getName();
1479 mo->setName(instanceName);
1481 ARMARX_LOG <<
"Adding manipulation object " << mo->getName() <<
" of class "
1482 << objectClass->getName();
1485 VirtualRobot::MathTools::Quaternion qa;
1486 qa.x = globalPose->orientation->qx;
1487 qa.y = globalPose->orientation->qy;
1488 qa.z = globalPose->orientation->qz;
1489 qa.w = globalPose->orientation->qw;
1490 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1491 gp(0, 3) = globalPose->position->x;
1492 gp(1, 3) = globalPose->position->y;
1493 gp(2, 3) = globalPose->position->z;
1494 mo->setGlobalPose(gp);
1495 VirtualRobot::SceneObject::Physics::SimulationType simType =
1496 (isStatic) ? VirtualRobot::SceneObject::Physics::eKinematic
1497 : VirtualRobot::SceneObject::Physics::eDynamic;
1498 physicsWorld->addObstacle(mo, simType, std::string(), objectClassBase->getName());
1508 const std::string& instanceName,
1509 const PoseBasePtr& globalPose,
1511 const Ice::Current&)
1513 ARMARX_INFO <<
"Add object from packagePath " << packagePath <<
": " << instanceName;
1519 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1520 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1523 std::string filename;
1526 ARMARX_ERROR <<
"Could not find file: \"" << packagePath.path <<
"\".";
1536 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" already exists";
1541 VirtualRobot::ManipulationObjectPtr mo =
1542 VirtualRobot::ObjectIO::loadManipulationObject(filename);
1546 ARMARX_ERROR <<
"Could not retrieve manipulation object from file " << filename;
1553 mo->setName(instanceName);
1558 VirtualRobot::MathTools::Quaternion qa;
1559 qa.x = globalPose->orientation->qx;
1560 qa.y = globalPose->orientation->qy;
1561 qa.z = globalPose->orientation->qz;
1562 qa.w = globalPose->orientation->qw;
1563 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1564 gp(0, 3) = globalPose->position->x;
1565 gp(1, 3) = globalPose->position->y;
1566 gp(2, 3) = globalPose->position->z;
1567 mo->setGlobalPose(gp);
1568 VirtualRobot::SceneObject::Physics::SimulationType simType =
1569 (isStatic) ? VirtualRobot::SceneObject::Physics::eKinematic
1570 : VirtualRobot::SceneObject::Physics::eDynamic;
1571 physicsWorld->addObstacle(mo, simType, filename, instanceName, {}, packagePath.package);
1584 const DrawColor& color,
1585 const std::string& instanceName,
1586 const PoseBasePtr& globalPose,
1588 const Ice::Current&)
1592 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1593 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1600 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" already exists";
1604 if (depth <= 0 || width <= 0 || height <= 0)
1606 ARMARX_ERROR <<
"Invalid properties; could not create object with instance name "
1611 VirtualRobot::VisualizationFactory::Color
c;
1615 c.transparency = color.a;
1616 VirtualRobot::ObstaclePtr o = VirtualRobot::Obstacle::createBox(width, height, depth,
c);
1626 o->setName(instanceName);
1628 ARMARX_LOG <<
"Adding box object " << o->getName();
1633 VirtualRobot::MathTools::Quaternion qa;
1634 qa.x = globalPose->orientation->qx;
1635 qa.y = globalPose->orientation->qy;
1636 qa.z = globalPose->orientation->qz;
1637 qa.w = globalPose->orientation->qw;
1638 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1639 gp(0, 3) = globalPose->position->x;
1640 gp(1, 3) = globalPose->position->y;
1641 gp(2, 3) = globalPose->position->z;
1642 o->setGlobalPose(gp);
1643 VirtualRobot::SceneObject::Physics::SimulationType simType =
1644 (isStatic) ? VirtualRobot::SceneObject::Physics::eStatic
1645 : VirtualRobot::SceneObject::Physics::eDynamic;
1647 BoxVisuPrimitivePtr bp(
new BoxVisuPrimitive());
1650 bp->height = height;
1652 bp->massKG = massKG;
1655 physicsWorld->addObstacle(o, simType, std::string(), std::string(), bp);
1668 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1677 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1678 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1684 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" does not exist";
1688 ARMARX_LOG <<
"Removing object " << instanceName;
1692 ARMARX_ERROR <<
"Could not remove object with instance name \"" << instanceName <<
"\"";
1704 const PoseBasePtr& globalPose,
1705 const Ice::Current&)
1707 VirtualRobot::MathTools::Quaternion
q;
1708 q.x = globalPose->orientation->qx;
1709 q.y = globalPose->orientation->qy;
1710 q.z = globalPose->orientation->qz;
1711 q.w = globalPose->orientation->qw;
1712 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(
q);
1713 gp(0, 3) = globalPose->position->x;
1714 gp(1, 3) = globalPose->position->y;
1715 gp(2, 3) = globalPose->position->z;
1722 SimulationType type,
1723 const Ice::Current&)
1725 VirtualRobot::SceneObject::Physics::SimulationType st =
1726 VirtualRobot::SceneObject::Physics::eDynamic;
1727 if (type == armarx::Kinematic)
1729 st = VirtualRobot::SceneObject::Physics::eKinematic;
1731 ARMARX_DEBUG <<
"setting simulation type of " << objectName <<
" to " << st;
1761 const std::string& nodeName,
1762 const Ice::Current&)
1764 return physicsWorld->getRobotJointAngle(robotName, nodeName);
1770 return physicsWorld->getRobotJointVelocities(robotName);
1775 const std::string& nodeName,
1776 const Ice::Current&)
1778 return physicsWorld->getRobotJointVelocity(robotName, nodeName);
1790 return physicsWorld->getRobotForceTorqueSensors(robotName);
1795 const std::string& nodeName,
1796 const Ice::Current&)
1798 return physicsWorld->getRobotJointLimitLo(robotName, nodeName);
1803 const std::string& nodeName,
1804 const Ice::Current&)
1806 return physicsWorld->getRobotJointLimitHi(robotName, nodeName);
1818 const std::string& nodeName,
1819 const Ice::Current&)
1821 return physicsWorld->getRobotMaxTorque(robotName, nodeName);
1826 const std::string& nodeName,
1828 const Ice::Current&)
1830 physicsWorld->setRobotMaxTorque(robotName, nodeName, maxTorque);
1835 const std::string& robotNodeName,
1836 const Ice::Current&)
1844 const std::string& nodeName,
1845 const Ice::Current&)
1853 const std::string& nodeName,
1854 const Ice::Current&)
1862 const std::string& robotNodeName,
1863 const Vector3BasePtr& vel,
1864 const Ice::Current&)
1866 Eigen::Vector3f newVel = Vector3Ptr::dynamicCast(vel)->toEigen();
1867 physicsWorld->setRobotLinearVelocity(robotName, robotNodeName, newVel);
1872 const std::string& robotNodeName,
1873 const Vector3BasePtr& vel,
1874 const Ice::Current&)
1876 Vector3Ptr newVel = Vector3Ptr::dynamicCast(vel);
1877 physicsWorld->setRobotAngularVelocity(robotName, robotNodeName, newVel->toEigen());
1882 const std::string& robotNodeName,
1883 const Vector3BasePtr& vel,
1884 const Ice::Current&)
1886 Eigen::Vector3f newVel = Vector3Ptr::dynamicCast(vel)->toEigen();
1887 physicsWorld->setRobotLinearVelocityRobotRootFrame(robotName, robotNodeName, newVel);
1892 const std::string& robotNodeName,
1893 const Vector3BasePtr& vel,
1894 const Ice::Current&)
1896 Eigen::Vector3f newVel = Vector3Ptr::dynamicCast(vel)->toEigen();
1897 physicsWorld->setRobotAngularVelocityRobotRootFrame(robotName, robotNodeName, newVel);
1908 const std::string& robotNodeName,
1909 const Ice::Current&)
1912 return physicsWorld->hasRobotNode(robotName, robotNodeName);
1924 const std::string& robotNodeName,
1925 const std::string& objectName,
1926 const Ice::Current&)
1928 ARMARX_VERBOSE <<
"Object released " << robotName <<
"," << objectName;
1929 physicsWorld->objectReleased(robotName, robotNodeName, objectName);
1934 const std::string& robotNodeName,
1935 const std::string& objectName,
1936 const Ice::Current&)
1938 ARMARX_VERBOSE <<
"Object grasped" << robotName <<
"," << objectName;
1939 physicsWorld->objectGrasped(robotName, robotNodeName, objectName);
1945 return static_cast<float>(
physicsWorld->getCurrentSimTime());
1962 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1963 SimulatorInformation res;
1968 std::vector<std::string> robNames =
physicsWorld->getRobotNames();
1969 res.nrRobots =
static_cast<int>(robNames.size());
1971 res.nrActuatedJoints =
physicsWorld->getRobotJointAngleCount();
1975 res.simTimeStepMeasuredMS =
physicsWorld->getSimulationStepTimeMeasured();
1976 res.simTimeStepDurationMS =
physicsWorld->getSimulationStepDuration();
1978 res.simTimeFactor = 0;
1979 if (res.simTimeStepMeasuredMS > 0)
1981 res.simTimeFactor = res.simTimeStepDurationMS / res.simTimeStepMeasuredMS;
1986 for (VirtualRobot::SceneObjectPtr& o :
objects)
1990 ovd.name = o->getName();
1992 ovd.objectPoses[ovd.name] = p;
1993 VirtualRobot::Obstacle* ob =
dynamic_cast<VirtualRobot::Obstacle*
>(o.get());
1997 ovd.filename = ob->getFilename();
2000 if (o->getSimulationType() == VirtualRobot::SceneObject::Physics::eStatic)
2002 ovd.staticObject =
true;
2006 ovd.staticObject =
false;
2009 res.objects.push_back(ovd);
2012 for (
auto& r : robNames)
2021 ovd.robotFile = rob->getFilename();
2024 res.robots.push_back(ovd);
2037 std::string filename;
2050 ARMARX_ERROR <<
"Could not find file: \"" << packagePath.path <<
"\".";
2056 const std::string& robFileGlobal,
2058 const std::string& robFile,
2065 std::map<std::string, float> initConfig,
2066 bool selfCollisions)
2068 ARMARX_DEBUG <<
"Add robot from file " << robFileGlobal;
2069 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
2070 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2097 return robotInstanceName;
2107 for (
auto& rob : syncData.
robots)
2110 std::string top = rob.robotTopicName;
2119 for (
auto& fti : rob.forceTorqueSensors)
2121 ARMARX_INFO <<
"Offering topic " << fti.topicName;
2126 ARMARX_INFO <<
"Connecting to topic " << fti.topicName;
2147ObjectClassInformationSequence
2149 const std::string& frameName,
2150 const std::string& className,
2151 const Ice::Current&)
2153 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
2154 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2158 ObjectClassInformationSequence result;
2161 for (
const auto&
object :
objects)
2163 ObjectClassInformation inf;
2165 inf.timestampMicroSeconds =
2166 static_cast<Ice::Long
>(
physicsWorld->getCurrentSimTime() * 1.0e6);
2167 inf.className = className;
2168 inf.manipulationObjectName = object;
2169 Eigen::Matrix4f worldPose =
physicsWorld->getObjectPose(
object);
2177 inf.pose =
physicsWorld->toFramedPose(worldPose, robotName, frameName);
2180 result.push_back(inf);
2188 const std::string& robotNodeName,
2189 const std::string& worldObjectName,
2190 const Ice::Current&)
2192 return physicsWorld->getDistance(robotName, robotNodeName, worldObjectName);
2197 const std::string& robotNodeName1,
2198 const std::string& robotNodeName2,
2199 const Ice::Current&)
2201 return physicsWorld->getRobotNodeDistance(robotName, robotNodeName1, robotNodeName2);
2207 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2267 IceUtil::Time startTime;
2282 startTime = IceUtil::Time::now();
2284 sleepTimeMS =
static_cast<int>(
2286 static_cast<float>((IceUtil::Time::now() - startTime).toMilliSeconds()));
2288 if (sleepTimeMS < 0)
2291 <<
" milliseconds too long!";
2295 usleep(
static_cast<unsigned int>(sleepTimeMS * 1000));
2335 return static_cast<long>(
physicsWorld->getCurrentSimTime() * 1000);
2341 IceUtil::Time startTime = IceUtil::Time::now();
2352 IceUtil::Time durationSim = IceUtil::Time::now() - startTime;
2357 << durationSim.toMilliSecondsDouble();
2360 ARMARX_DEBUG <<
"*** Step Physics, MS:" << durationSim.toMilliSecondsDouble();
2362 startTime = IceUtil::Time::now();
2365 IceUtil::Time durationSync = IceUtil::Time::now() - startTime;
2368 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2388 IceUtil::Time startTime = IceUtil::Time::now();
2390 SceneVisuData reportData =
physicsWorld->copySceneVisuData();
2406 const auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
2407 const auto lockSync =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2412 std::vector<SimDynamics::DynamicsEngine::DynamicsContactInfo> contacts =
2414 VirtualRobot::ColorMap cm(VirtualRobot::ColorMap::eHot);
2415 float maxImpulse = 2.0f;
2416 float arrowLength = 50.0f;
2420 for (
auto&
c : contacts)
2422 std::stringstream ss;
2423 ss <<
"Contact_" << i;
2428 std::string name = ss.str();
2429 std::string name2 = name +
"_2";
2432 if (!
c.objectAName.empty())
2434 objA =
c.objectAName;
2443 if (!
c.objectBName.empty())
2445 objB =
c.objectBName;
2452 ARMARX_DEBUG <<
"CONTACT " << name <<
", objects: " << objA <<
"-" << objB
2453 <<
", impulse:" <<
c.appliedImpulse;
2454 float intensity =
static_cast<float>(
c.appliedImpulse);
2456 if (intensity > maxImpulse)
2458 intensity = maxImpulse;
2461 intensity /= maxImpulse;
2462 VirtualRobot::VisualizationFactory::Color colSimox = cm.getColor(intensity);
2469 Eigen::Vector3f dir2 = -(
c.normalGlobalB);
2484 std::stringstream ss;
2485 ss <<
"Contact_" << j;
2486 std::string name = ss.str();
2487 std::string name2 = name +
"_2";
2502 "CoM",
"GlobalCoM_" + name, pos, DrawColor{0.f, 0.f, 1.f, 0.5f}, 20);
2506 IceUtil::Time duration = IceUtil::Time::now() - startTime;
2531 IceUtil::Time startTime = IceUtil::Time::now();
2542 ctx[
"origin"] =
"simulation";
2548 header.timestampInMicroSeconds = reportData.
timestamp.toMicroSeconds();
2550 TransformStamped globalRobotPose;
2551 globalRobotPose.header = header;
2552 globalRobotPose.transform = r.
pose;
2569 IceUtil::Time duration = IceUtil::Time::now() - startTime;
2585 ContactInfoSequence result;
2587 for (
auto& contact : contacts)
2589 ContactInformation contactInfo;
2590 contactInfo.objectNameA = contact.objectAName;
2591 contactInfo.objectNameB = contact.objectBName;
2592 contactInfo.posGlobalA =
new Vector3(contact.posGlobalA);
2593 contactInfo.posGlobalB =
new Vector3(contact.posGlobalB);
2594 result.push_back(contactInfo);
2609 std::string instanceName;
2611 instanceName, filename, Eigen::Matrix4f::Identity(),
"", 10.0, 0, 0,
false, scaling);
2612 return instanceName;
2617 const std::string& filename,
2619 const Ice::Current&)
2622 std::string name = instanceName;
2624 name, filename, Eigen::Matrix4f::Identity(),
"", 10.0, 0, 0,
false, scaling);
2638 std::string instanceName;
2640 instanceName, filename, Eigen::Matrix4f::Identity(),
"", 10.0, 0, 0,
false, 1.0f);
2641 return instanceName;
2648 for (
auto& robot : report.
robots)
2650 if (robot.robotName == robotName)
2656 return SimulatedRobotState();
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
#define ARMARX_CHECK_NOT_EMPTY(c)
#define MAX_SIM_TIME_WARNING
#define MAX_INITIAL_ROBOT_COUNT
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
static bool SearchReadableFile(const std::string &querryFileName, std::string &resultFileName, bool verbose=true)
static bool FindPackageAndAddDataPath(const std::string &packageName)
Search for the package and add its data path if it was found.
The BulletPhysicsWorld class encapsulates the whole physics simulation and the corresponding data.
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Property< PropertyType > getProperty(const std::string &name)
The KinematicsWorld class encapsulates the kinemtics simulation and the corresponding data....
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
The MujocoPhysicsWorld class encapsulates the whole physics simulation and the corresponding data.
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
static ObjectID FromString(const std::string &idString)
Construct from a string produced by str(), e.g. ("mydataset/myobject", "mydataset/myclass/myinstance"...
ObjectID withInstanceName(const std::string &instanceName) const
ObjectID getClassID() const
Return just the class ID without an intance name.
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
The SimulatedWorldData class This data is queried by the simulated in order to offer it via topics.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::vector< RobotInfo > robots
SimulatorPropertyDefinitions(std::string prefix)
~SimulatorPropertyDefinitions() override
The SimulatorTimeServerProxy class forwards TimeserverInterface calls to the simulator This is a hack...
The Simulator class holds an instance of the AmrarXPhysicsWorld and communicates to ArmarX.
std::mutex simulatorRunningMutex
memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx
void applyForceObject(const std::string &objectName, const Vector3BasePtr &force, const Ice::Current &c=Ice::emptyCurrent) override
void setRobotLinearVelocity(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
std::string addScaledRobot(const std::string &filename, float scale, const Ice::Current &c=Ice::emptyCurrent) override
void onInitComponent() override
Pure virtual hook for the subclass.
memoryx::WorkingMemoryInterfacePrx memoryPrx
void setObjectSimulationType(const std::string &objectName, armarx::SimulationType type, const Ice::Current &c=Ice::emptyCurrent) override
SimulatorTimeServerProxyPtr timeserverProxy
Proxy object to offer the Timeserver proxy.
Ice::Long getTime(const Ice::Current &c=Ice::emptyCurrent) override
void showContacts(bool enable, const std::string &layerName, const Ice::Current &c=Ice::emptyCurrent) override
Vector3BasePtr getRobotAngularVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void start(const Ice::Current &c=Ice::emptyCurrent) override
void addBox(float width, float height, float depth, float massKG, const DrawColor &color, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
float getRobotJointAngle(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsTorque(const std::string &robotName, const NameValueMap &torques, const Ice::Current &c=Ice::emptyCurrent) override
SimulatorInformation getSimulatorInformation(const ::Ice::Current &=Ice::emptyCurrent) override
void resetData(bool clearWorkingMemory=false)
resetData Clears all data
bool hasRobotNode(const std::string &robotName, const std::string &robotNodeName, const Ice::Current &c=Ice::emptyCurrent) override
PoseBasePtr getRobotPose(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
ContactInfoSequence getContacts(const Ice::Current &c=Ice::emptyCurrent) override
Returns a list of all contacts. Note that you must call updateContacts() first to enable contacts han...
Ice::Int getStepTimeMS(const ::Ice::Current &=Ice::emptyCurrent) override
void shutdownSimulationLoop()
stop the simulation and join the simulation thread
GlobalRobotPoseLocalizationListenerPrx globalRobotLocalization
void onDisconnectComponent() override
Hook for subclass.
SimulatorResetEventPrx simulatorResetEventTopic
void applyTorqueRobotNode(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &torque, const Ice::Current &c=Ice::emptyCurrent) override
float timeServerSpeed
Scaling factor for the passing of time.
PoseBasePtr getObjectPose(const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
void reInitialize(const Ice::Current &c=Ice::emptyCurrent) override
reInitialize Re-initializes the scene. Removes all robots and objects (and, in case the scene was loa...
float currentComTimeMS
Stores the time that was needed for communictaion.
void applyForceRobotNode(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &force, const Ice::Current &c=Ice::emptyCurrent) override
float getRobotJointVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void addObjectFromFile(const armarx::data::PackagePath &packagePath, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getRobotJointAngles(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
void step(const Ice::Current &c=Ice::emptyCurrent) override
void setRobotAngularVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
std::string addRobotFromFile(const armarx::data::PackagePath &packagePath, const Ice::Current &c=Ice::emptyCurrent) override
memoryx::GridFileManagerPtr fileManager
memoryx::PriorKnowledgeInterfacePrx priorKnowledgePrx
SimulatorListenerInterfacePrx simulatorVisuUpdateListenerPrx
std::condition_variable condSimulatorThreadRunning
bool hasObject(const std::string &instanceName, const Ice::Current &c=Ice::emptyCurrent) override
Ice::Float getSpeed(const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getRobotJointTorques(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
bool loadAgentsFromSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx)
void removeObject(const std::string &instanceName, const Ice::Current &) override
DistanceInfo getDistance(const std::string &robotName, const std::string &robotNodeName, const std::string &worldObjectName, const Ice::Current &c=Ice::emptyCurrent) override
float getSimTime(const Ice::Current &c=Ice::emptyCurrent) override
void stop(const Ice::Current &c=Ice::emptyCurrent) override
NameValueMap getRobotJointVelocities(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< Simulator >::pointer_type reportVisuTask
The report visu task.
bool addSnapshot(memoryx::WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx)
float getRobotJointLimitHi(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
bool hasRobot(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
std::string contactLayerName
void pause(const Ice::Current &c=Ice::emptyCurrent) override
void setRobotAngularVelocity(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< Simulator >::pointer_type reportDataTask
The report data task.
void setRobotLinearVelocityRobotRootFrame(const std::string &robotName, const std::string &robotNodeName, const Vector3BasePtr &vel, const Ice::Current &c=Ice::emptyCurrent) override
float currentSimTimeMS
Stores the time that was needed to perform the last simulation loop.
Vector3BasePtr getRobotLinearVelocity(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
SimulatedWorldPtr physicsWorld
void setSpeed(Ice::Float newSpeed, const Ice::Current &c=Ice::emptyCurrent) override
setSpeed sets the scaling factor for the speed of passing of time e.g.
std::string addScaledRobotName(const std::string &instanceName, const std::string &filename, float scale, const Ice::Current &c=Ice::emptyCurrent) override
ObjectFinder objectFinder
Constructed once based on the ObjectPackage property.
void onConnectComponent() override
Pure virtual hook for the subclass.
void objectReleased(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
remove a joint
bool isRunning(const Ice::Current &c=Ice::emptyCurrent) override
int lastPublishedContacts
std::atomic< float > reportVisuTimeMS
float getRobotMaxTorque(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void updateContacts(bool enable, const Ice::Current &c=Ice::emptyCurrent) override
Enables the handling of contacts. If you intend to use getContacts(), call this method with enabled =...
memoryx::GridFileManagerPtr requestFileManager()
float currentSyncTimeMS
stores the time that was needed to sync the data
static std::string GetDefaultName()
SimulatedRobotState getRobotState(const std::string &robotName, const Ice::Current &) override
bool removeRobot(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent)
float getRobotMass(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
bool simulatorThreadShutdown
SceneVisuData getScene(const Ice::Current &c=Ice::emptyCurrent) override
float getRobotJointLimitLo(const std::string &robotName, const std::string &nodeName, const Ice::Current &c=Ice::emptyCurrent) override
void setObjectPose(const std::string &objectName, const PoseBasePtr &globalPose, const Ice::Current &c=Ice::emptyCurrent) override
DistanceInfo getRobotNodeDistance(const std::string &robotName, const std::string &robotNodeName1, const std::string &robotNodeName2, const Ice::Current &c=Ice::emptyCurrent) override
void objectGrasped(const std::string &robotName, const std::string &robotNodeName, const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
create a joint
TimeServerListenerPrx timeTopicPrx
void setRobotPose(const std::string &robotName, const PoseBasePtr &globalPose, const Ice::Current &c=Ice::emptyCurrent) override
std::string addRobot(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
Hook for subclass.
void addObject(const memoryx::ObjectClassBasePtr &objectClassBase, const std::string &instanceName, const PoseBasePtr &globalPose, bool isStatic=false, const Ice::Current &c=Ice::emptyCurrent) override
SimulatedRobotState stateFromRobotInfo(RobotInfo const &robot, IceUtil::Time timestamp)
void actuateRobotJoints(const std::string &robotName, const NameValueMap &angles, const NameValueMap &velocities, const Ice::Current &c=Ice::emptyCurrent) override
ForceTorqueDataSeq getRobotForceTorqueSensors(const std::string &robotName, const Ice::Current &c=Ice::emptyCurrent) override
void setRobotMaxTorque(const std::string &robotName, const std::string &nodeName, float maxTorque, const Ice::Current &c=Ice::emptyCurrent) override
ObjectClassInformationSequence getObjectClassPoses(const std::string &robotName, const std::string &frameName, const std::string &className, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsPos(const std::string &robotName, const NameValueMap &angles, const Ice::Current &c=Ice::emptyCurrent) override
PoseBasePtr getRobotNodePose(const std::string &robotName, const std::string &robotNodeName, const Ice::Current &c=Ice::emptyCurrent) override
void actuateRobotJointsVel(const std::string &robotName, const NameValueMap &velocities, const Ice::Current &c=Ice::emptyCurrent) override
std::string commonStorageName
void activateObject(const std::string &objectName, const Ice::Current &c=Ice::emptyCurrent) override
bool simulatorThreadRunning
std::string priorKnowledgeName
Ice::StringSeq getRobotNames(const Ice::Current &) override
memoryx::EntityDrawerInterfacePrx entityDrawerPrx
Drawing contacts.
std::map< std::string, std::vector< std::string > > classInstanceMap
Stores all instances that belong to a class.
std::string getDefaultName() const override
Retrieve default name of component.
int getFixedTimeStepMS(const Ice::Current &c=Ice::emptyCurrent) override
void applyTorqueObject(const std::string &objectName, const Vector3BasePtr &torque, const Ice::Current &c=Ice::emptyCurrent) override
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_NONNEGATIVE(number)
Check whether number is nonnegative (>= 0).
#define ARMARX_DEBUG_S
The logging level for output that is only interesting while debugging.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
#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.
Quaternion< float, 0 > Quaternionf
std::shared_ptr< class Robot > RobotPtr
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
std::string GetHandledExceptionString()
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceInternal::Handle< Pose > PosePtr
std::shared_ptr< KinematicsWorld > KinematicsWorldPtr
IceInternal::Handle< FramedPosition > FramedPositionPtr
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
std::shared_ptr< MujocoPhysicsWorld > MujocoPhysicsWorldPtr
const std::string & to_string(const std::string &s)
std::string ValueToString(const T &value)
std::shared_ptr< BulletPhysicsWorld > BulletPhysicsWorldPtr
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
IceInternal::Handle< AgentInstance > AgentInstancePtr
Typedef of AgentEntityPtr as IceInternal::Handle<AgentEntity> for convenience.
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
std::filesystem::path absolutePath
The absolute path (in the host's file system).
std::string package
Name of the ArmarX package.
std::string relativePath
Relative to the package's data directory.
NameValueMap jointVelocities
std::vector< ForceTorqueInfo > forceTorqueSensors
SimulatorRobotListenerInterfacePrx simulatorRobotListenerPrx
Eigen::Vector3f angularVelocity
Eigen::Vector3f linearVelocity
NameValueMap jointTorques
std::vector< SceneObject > objects