27#include <VirtualRobot/MathTools.h>
28#include <VirtualRobot/XML/BaseIO.h>
29#include <VirtualRobot/XML/RobotIO.h>
34#define MAX_SIM_TIME_WARNING 25
38#ifdef MUJOCO_PHYSICS_WORLD
42#include <SimoxUtility/algorithm/string/string_tools.h>
43#include <SimoxUtility/json.h>
44#include <VirtualRobot/Scene.h>
45#include <VirtualRobot/SceneObject.h>
46#include <VirtualRobot/XML/ObjectIO.h>
47#include <VirtualRobot/math/Helpers.h>
53#include <RobotAPI/interface/core/GeometryBase.h>
65#include <SimDynamics/DynamicsEngine/DynamicsObject.h>
66#include <SimDynamics/DynamicsEngine/DynamicsRobot.h>
68#ifdef ENABLE_SDF_FORMAT
79 "SimoxSceneFileName",
"",
"Simox/VirtualRobot scene file name, e.g. myScene.xml");
83 "LongtermMemory.SnapshotName",
"",
"Name of snapshot to load the scene")
84 .setCaseInsensitive(
true);
86 "LoadSnapshotToWorkingMemory",
true,
"Load the snapshot also into the WorkingMemory");
89 "Also load the agents from the snapshot into the WorkingMemory");
92 "WorkingMemoryName",
"WorkingMemory",
"Name of WorkingMemory")
93 .setCaseInsensitive(
true);
95 "CommonStorageName",
"CommonStorage",
"Name of CommonStorage")
96 .setCaseInsensitive(
true);
98 "PriorKnowledgeName",
"PriorKnowledge",
"Name of PriorKnowledge")
99 .setCaseInsensitive(
true);
101 "LongtermMemoryName",
"LongtermMemory",
"Name of LongtermMemory")
102 .setCaseInsensitive(
true);
105 "PriorKnowledgeData",
106 "Package to search for object models."
107 "Used when loading scenes from JSON files.");
110 "Path to one or multiple JSON scene file(s) to load.\n"
111 "Example: 'PriorKnowledgeData/scenes/MyScene.json'.\n"
112 "Multiple paths are separated by semicolons (';').\n"
113 "The package to load a scene from is automatically"
114 "extracted from its first path segment.");
118 "Simulation type (Supported: Bullet, Kinematics, Mujoco)")
122 .setCaseInsensitive(
true);
133 "RobotFileName" + postfix,
135 "Simox/VirtualRobot robot file name, e.g. robot_model.xml");
137 "RobotInstanceName" + postfix,
"",
"Name of this robot instance");
139 "RobotIsStatic" + postfix,
141 "A static robot does not move due to the physical environment (i.e. no gravity). \n"
142 "It is a static (but kinematic) object in the world.");
145 "RobotCollisionModel" + postfix,
false,
"Show the collision model of the robot.");
147 "InitialRobotPose.x" + postfix, 0.f,
"x component of initial robot position (mm)");
149 "InitialRobotPose.y" + postfix, 0.f,
"y component of initial robot position (mm)");
151 "InitialRobotPose.z" + postfix, 0.f,
"z component of initial robot position (mm)");
154 "Initial robot pose: roll component of RPY angles (radian)");
157 "Initial robot pose: pitch component of RPY angles (radian)");
160 "Initial robot pose: yaw component of RPY angles (radian)");
162 "InitialRobotConfig" + postfix,
164 "Initial robot config as comma separated list (RobotNodeName:value)");
167 "InitialNamedRobotConfig" + postfix,
169 "Initial named robot config, e.g., `Home`.");
172 "RobotScaling" + postfix, 1.0f,
"Scaling of the robot (1 = no scaling).");
174 "RobotControllerPID.p" + postfix, 10.0,
"Setup robot controllers: PID paramter p.");
176 "RobotControllerPID.i" + postfix, 0.0,
"Setup robot controllers: PID paramter i.");
178 "RobotControllerPID.d" + postfix, 0.0,
"Setup robot controllers: PID paramter d.");
180 "RobotSelfCollisions" + postfix,
182 "If false, the robot bodies will not collide with other bodies of this \n"
183 "robot but with all other bodies in the world. \n"
184 "If true, the robot bodies will collide with all other bodies \n"
185 "(This needs an accurately modelled robot model without self collisions \n"
186 "if the robot does not move.)");
189 "FixedTimeStepLoopNrSteps",
191 "The maximum number of internal simulation loops (fixed time step mode).\n"
192 "After max number of time steps, the remaining time is interpolated.");
194 "FixedTimeStepStepTimeMS",
196 "The simulation's internal timestep (fixed time step mode). \n"
197 "This property determines the precision of the simulation. \n"
198 "Needs to be set to bigger values for slow PCs, but the simulation results might be bad. "
199 "Smaller value for higher precision, but slower calculation.");
204 "If true the timestep is adjusted to the computing power of the host and \n"
205 "the time progress in real time. Can result in bad results on slow PCs. \n"
206 "The property StepTimeMS has then no effect. FixedTimeStepStepTimeMS needs \n"
207 "to be adjusted if real time cannot be achieved on slower PCs.");
211 "If not zero and the real time mode is off, the simulator will not run \n"
212 "\tfaster than real-time * MaxRealTime even if the machine is fast enough \n"
213 "\t(a sleep is inserted to slow down the simulator - the precision remains unchanged).\n"
214 "\tIf set to 2, the simulator will not run faster than double speed. \n"
215 "\tIf set to 0.5, the simulator will not run faster than half speed. \n"
216 "\tIf set to 0, the simulator will run as fast as possible.\n");
221 "Enable robot logging. If true, the complete robot state is logged to a file each step.");
225 "How often should the visualization data be published. Value is "
226 "given in Hz. (0 to disable)");
228 "ReportVisuTopicName",
229 "SimulatorVisuUpdates",
230 "The topic on which the visualization updates are published.");
232 "ReportDataFrequency",
234 "How often should the robot data be published. Value is given in Hz. (0 to disable)");
238 "Fixate objects or parts of a robot in the world. Comma separated list. \n"
239 "Define objects by their name, robots can be defined with robotName:RobotNodeName");
242 "If true the CoM of each robot is drawn as a circle on the ground "
243 "after each simulation cycle.");
287 if (!snapshotName.empty())
289 ARMARX_LOG <<
"UsingProxy LongtermMemory for snapshot " << snapshotName;
297 ARMARX_LOG <<
"Not using LongtermMemoryProxy";
321 switch (simulatorType)
326 kw->initialize(stepTimeMs, maxRealTime, floorPlane, floorTexture);
332 int bulletFixedTimeStepMS =
getProperty<int>(
"FixedTimeStepStepTimeMS").getValue();
333 int bulletFixedTimeStepMaxNrLoops =
336 bw->initialize(stepTimeMs,
337 bulletFixedTimeStepMS,
338 bulletFixedTimeStepMaxNrLoops,
347#ifdef MUJOCO_PHYSICS_WORLD
351 mw->initialize(stepTimeMs, floorPlane, floorTexture);
355 ARMARX_ERROR <<
"Simulator type 'mujoco' is not supported, since simulator was built "
357 <<
"\nGet the package MujocoX from: https://gitlab.com/h2t/mujoco .";
370Simulator::addRobotsFromProperties()
386 Eigen::Matrix4f gp = Eigen::Matrix4f::Identity();
388 VirtualRobot::MathTools::rpy2eigen4f(
394 math::Helpers::Position(gp) =
400 std::map<std::string, float> initConfig;
404 std::string confStr =
410 std::string robFileGlobal = robotFile;
414 ARMARX_ERROR <<
"Could not find robot file " << robotFile;
417 const auto robot = VirtualRobot::RobotIO::loadRobot(robFileGlobal, VirtualRobot::BaseIO::eStructure);
420 const std::optional<std::map<std::string, float>> namedConfig =
421 robot->getConfiguration(confStr);
424 <<
"Could not find named robot config " <<
QUOTED(confStr) <<
" in robot file "
427 initConfig = namedConfig.value();
433 <<
" because InitialNamedRobotConfig is set.";
440 std::string confStr =
442 std::vector<std::string> confList =
Split(confStr,
",",
true,
true);
443 for (
auto& pos : confList)
446 std::vector<std::string> d =
Split(pos,
":",
true,
true);
452 std::string name = d.at(0);
454 initConfig[name] =
static_cast<float>(atof(d.at(1).c_str()));
455 ARMARX_INFO <<
"1:'" << name <<
"', 2:" << initConfig[name];
464 std::string robotInstanceName =
468 bool colModelRobot =
getProperty<bool>(
"RobotCollisionModel" + postfix).getValue();
471 if (!robotFile.empty())
473 std::string robFileGlobal = robotFile;
477 ARMARX_ERROR <<
"Could not find robot file " << robotFile;
481 ARMARX_INFO <<
"Adding robot with name '" << robotInstanceName <<
"' from file "
501Simulator::addSceneFromFile(
const std::string& sceneFile)
506 ARMARX_ERROR <<
"Could not find scene file " << sceneFile;
518Simulator::addSceneFromMemorySnapshot(
const std::string& snapshotName)
523 ARMARX_ERROR <<
"No connection to memory - cannot add snapshot!";
533 WorkingMemorySnapshotInterfacePrx snapshotInterfacePrx;
537 ARMARX_LOG <<
"Loading snapshot " << snapshotName;
541 snapshotInterfacePrx =
546 if (snapshotInterfacePrx)
552 ARMARX_ERROR <<
"Could not get snapshot segment from longterm memory...";
556 catch (memoryx::SnapshotNotFoundException&)
558 ARMARX_ERROR <<
"Could not find snapshot: " << snapshotName;
562 ARMARX_ERROR <<
"Failed to load snapshot with name:" << snapshotName;
567 ARMARX_ERROR <<
"Could not get PriorKnowledge/LongtermMemory/WorkingMemory Proxy";
572 ARMARX_LOG <<
"Found and opened snapshot " << snapshotName;
577 ARMARX_ERROR <<
"Failed to open snapshot " << snapshotName;
582Simulator::addSceneFromSdfFile(
const std::string& scenePath)
584#ifdef ENABLE_SDF_FORMAT
585 std::string scenePackage = simox::alg::split(scenePath,
"/").at(0);
586 CMakePackageFinder cmakeFinder(scenePackage);
587 if (!cmakeFinder.packageFound())
589 ARMARX_WARNING <<
"Could not find CMake package " << scenePackage <<
".";
593 std::filesystem::path dataDir = cmakeFinder.getDataDir();
594 std::filesystem::path path = dataDir / scenePath;
597 sdf::SDFPtr sdfFile(
new sdf::SDF());
600 std::filesystem::path modelDirectory = path.parent_path();
602 const std::string modelURI =
"model://";
604 auto findFileCallback = [
this, &modelURI](
const std::string& uri) -> std::string
606 std::stringstream ss;
607 ss <<
"Find '" << uri <<
"' ... -> ";
609 const std::string classIDStr = simox::alg::remove_prefix(uri, modelURI);
612 if (std::optional<ObjectInfo> info =
objectFinder.findObject(classID))
614 if (std::optional<PackageFileLocation> modelPath = info->getModel())
616 std::filesystem::path result = modelPath->absolutePath.parent_path();
630 parser.AddURIPath(modelURI, modelDirectory.string());
631 parser.SetFindCallback(findFileCallback);
634 sdf::Errors errors = root.Load(path.string(), parser);
636 for (
auto const& error : errors)
647 if (root.WorldCount() == 0)
653 if (root.WorldCount() > 1)
659 sdf::World* world = root.WorldByIndex(0);
660 auto addSceneObject = [&](sdf::Model* model)
662 const std::string name = model->Name();
665 ARMARX_WARNING <<
"Object with name \"" << name <<
"\" already exists.";
669 const std::string uri = model->Uri();
672 ARMARX_WARNING <<
"No URI set for object \"" << name <<
"\" in SDF.";
678 const std::filesystem::path modelPath = findFileCallback(uri);
680 gz::math::Pose3d pose = model->RawPose();
682 const float meterToMillimeter = 1000.0F;
684 Eigen::Vector3f position;
685 position.x() =
static_cast<float>(pose.Pos().X() * meterToMillimeter);
686 position.y() =
static_cast<float>(pose.Pos().Y() * meterToMillimeter);
687 position.z() =
static_cast<float>(pose.Pos().Z() * meterToMillimeter);
690 orientation.x() =
static_cast<float>(pose.Rot().X());
691 orientation.y() =
static_cast<float>(pose.Rot().Y());
692 orientation.z() =
static_cast<float>(pose.Rot().Z());
693 orientation.w() =
static_cast<float>(pose.Rot().W());
695 auto isStatic = model->Static();
697 std::string robotFilename = modelPath.filename().generic_string() +
".urdf";
698 std::filesystem::path robotPath = modelPath / robotFilename;
700 std::string xmlFilename = modelPath.filename().generic_string() +
".xml";
701 std::filesystem::path xmlPath = modelPath / xmlFilename;
703 if (std::filesystem::exists(xmlPath))
705 ARMARX_INFO <<
"Loading object '" << name <<
"' from object XML file " << xmlPath;
706 VirtualRobot::ManipulationObjectPtr simoxObject =
707 VirtualRobot::ObjectIO::loadManipulationObject(xmlPath.string());
709 simoxObject->setGlobalPose(simox::math::pose(position, orientation));
711 VirtualRobot::SceneObject::Physics::SimulationType simType =
712 isStatic ? VirtualRobot::SceneObject::Physics::eKinematic
713 : VirtualRobot::SceneObject::Physics::eDynamic;
715 simoxObject->setSimulationType(simType);
716 simoxObject->setFilename(xmlPath.string());
717 simoxObject->setName(name);
720 simoxObject, simType, xmlPath.string(), name, {}, scenePackage);
722 else if (std::filesystem::exists(robotPath))
724 ARMARX_INFO <<
"Loading object '" << name <<
"' from robot URDF file " << xmlPath;
727 robot->setGlobalPose(simox::math::pose(position, orientation));
729 VirtualRobot::SceneObject::Physics::SimulationType simType =
730 isStatic ? VirtualRobot::SceneObject::Physics::eKinematic
731 : VirtualRobot::SceneObject::Physics::eDynamic;
733 robot->setSimulationType(simType);
734 robot->setFilename(robotPath.string());
735 robot->setName(name);
737 physicsWorld->addRobot(robot, 10.0, 0.0, 0.0, robotPath.string(), isStatic);
742 <<
"Not adding object '" << name
743 <<
"' because neither object XML nor robot URDF file exist. (Tried object XML = "
744 << xmlPath <<
" and robot URDF = " << robotPath <<
")";
750 addSceneObject(world->ModelByIndex(
index));
753 ARMARX_ERROR <<
"Loading from SDF file was not compiled";
758Simulator::addSceneFromJsonFile(
const std::string& scenePath)
760 std::string mutScenePath = scenePath;
761 if (!simox::alg::ends_with(mutScenePath,
".json"))
763 mutScenePath +=
".json";
766 std::string scenePackage = simox::alg::split(scenePath,
"/").at(0);
767 CMakePackageFinder cmakeFinder(scenePackage);
768 if (!cmakeFinder.packageFound())
770 ARMARX_WARNING <<
"Could not find CMake package " << scenePackage <<
".";
774 std::filesystem::path dataDir = cmakeFinder.getDataDir();
775 std::filesystem::path path = dataDir / scenePath;
777 armarx::objects::Scene scene;
780 scene = simox::json::read<armarx::objects::Scene>(path);
782 catch (
const simox::json::error::JsonError& e)
784 ARMARX_WARNING <<
"Loading scene snapshot failed: \n" << e.what();
788 std::map<ObjectID, int> idCounters;
789 for (
const auto&
object : scene.
objects)
791 if (simox::alg::starts_with(
object.className,
"#"))
797 addJsonSceneObject(
object, idCounters);
802Simulator::addJsonSceneObject(
const armarx::objects::SceneObject
object,
803 std::map<ObjectID, int>& idCounters)
806 const std::string name =
808 .
withInstanceName(
object.instanceName.empty() ? std::to_string(idCounters[classID]++)
809 :
object.instanceName)
814 ARMARX_INFO <<
"Object with name \"" << name <<
"\" already exists.";
818 ARMARX_INFO <<
"Adding object with name \"" << name <<
"\" to scene.";
820 std::optional<ObjectInfo> objectInfo =
objectFinder.findObject(classID);
821 VirtualRobot::ManipulationObjectPtr simoxObject =
822 VirtualRobot::ObjectIO::loadManipulationObject(objectInfo->simoxXML().absolutePath);
823 simoxObject->setGlobalPose(simox::math::pose(
object.position,
object.orientation));
825 VirtualRobot::SceneObject::Physics::SimulationType simType;
826 if (
object.isStatic.has_value())
828 simType = *
object.isStatic ? VirtualRobot::SceneObject::Physics::eKinematic
829 : VirtualRobot::SceneObject::Physics::eDynamic;
833 simType = VirtualRobot::SceneObject::Physics::eKinematic;
836 PackageFileLocation simoxXml = objectInfo->simoxXML();
837 simoxObject->setSimulationType(simType);
839 simoxObject->setName(name);
846Simulator::fixateRobotNode(
const std::string& robotName,
const std::string& robotNodeName)
848 ARMARX_VERBOSE <<
"Fixing robot node" << robotName <<
"." << robotNodeName;
850 robotName, robotNodeName, VirtualRobot::SceneObject::Physics::eStatic);
854Simulator::fixateObject(
const std::string& objectName)
857 physicsWorld->setObjectSimType(objectName, VirtualRobot::SceneObject::Physics::eStatic);
865 addRobotsFromProperties();
868 if (!sceneFile.empty())
870 addSceneFromFile(sceneFile);
874 if (!snapshotName.empty())
876 addSceneFromMemorySnapshot(snapshotName);
883 if (!scenePaths.empty())
886 for (
const std::string& scenePath : simox::alg::split(scenePaths,
";", trim))
888 std::filesystem::path path = scenePath;
889 std::string sdfExtension =
".sdf";
891 if (path.has_extension() && path.extension().string() == sdfExtension)
893 ARMARX_INFO <<
"Loading scene from SDF file '" << scenePath <<
"' ...";
894 addSceneFromSdfFile(scenePath);
898 ARMARX_INFO <<
"Loading scene from JSON file '" << scenePath <<
"' ...";
899 addSceneFromJsonFile(scenePath);
906 if (!fixedObjects.empty())
908 std::vector<std::string>
objects =
Split(fixedObjects,
",;");
911 std::vector<std::string> rob =
Split(o,
":");
915 fixateRobotNode(rob.at(0), rob.at(1));
931 SimulatedRobotState state;
933 state.hasRobot =
true;
934 state.timestampInMicroSeconds =
timestamp.toMicroSeconds();
946 if (forceTorqueSensor.enable)
948 ForceTorqueData& ftData = state.forceTorqueValues.emplace_back();
949 ftData.force =
new Vector3(forceTorqueSensor.currentForce);
950 ftData.torque =
new Vector3(forceTorqueSensor.currentTorque);
951 ftData.sensorName = forceTorqueSensor.sensorName;
952 ftData.nodeName = forceTorqueSensor.robotNodeName;
965 <<
"Was able to find a reference to the CommonStorage. Continue with existing "
966 "connection to memory.";
969 CommonStorageInterfacePrx commonStoragePrx =
972 if (commonStoragePrx)
975 <<
"Was able to find a reference to the CommonStorage. Reset GridFSManager and "
976 "continue with memory.";
982 <<
"Could not get CommonStorage Proxy - continuing without memory";
1003 ARMARX_DEBUG <<
"Starting periodic simulation task in ArmarX Simulator";
1008 ARMARX_DEBUG <<
"Starting periodic visualization report task in ArmarX Simulator";
1022 int cycleTime = 1000 / hzVisu;
1029 ARMARX_DEBUG <<
"Starting periodic data report task in ArmarX Simulator";
1038 int cycleTime = 1000 / hzData;
1101 IceUtil::ThreadControl threadControl = getThreadControl();
1106 threadControl.join();
1117 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1118 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1154 const std::string segmentName =
"objectInstances";
1158 PersistentEntitySegmentBasePrx segInstances = snapshotInterfacePrx->getSegment(segmentName);
1162 ARMARX_ERROR <<
"Segment not found in snapshot: " << segmentName;
1167 PersistentObjectClassSegmentBasePrx classesSegmentPrx =
1170 if (!classesSegmentPrx)
1172 ARMARX_ERROR <<
"Classes Segment not found in PriorKnowledge";
1177 EntityIdList ids = segInstances->getAllEntityIds();
1181 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
1183 EntityBasePtr snapEntity = segInstances->getEntityById(*it);
1185 std::string
id = snapInstance->getId();
1186 bool ok = snapInstance->hasAttribute(
"classes");
1191 <<
" has no classes attribute, could not load iv files, skipping";
1195 std::string classesName = snapInstance->getAttributeValue(
"classes")->getString();
1197 EntityBasePtr classesEntity = classesSegmentPrx->getEntityByName(classesName);
1201 ARMARX_ERROR <<
"Classes Segment does not know class with name : " << classesName;
1205 ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(classesEntity);
1209 ARMARX_ERROR <<
"Could not cast class entity : " << classesName;
1214 Eigen::Matrix4f m = Eigen::Matrix4f::Identity();
1221 m.block<3,1>(0, 3) = objPos->toEigen();
1229 m.block<3,3>(0, 0) = objOrient->toEigen();
1235 VirtualRobot::ManipulationObjectPtr mo = sw->getManipulationObject()->clone(
1236 sw->getManipulationObject()
1241 std::string instanceName = snapInstance->getName();
1245 instanceName = snapInstance->getName() +
"_" +
to_string(i);
1248 if (instanceName != snapInstance->getName())
1250 ARMARX_INFO <<
"Object instance with name '" << snapInstance->getName()
1251 <<
"'' already exists - using '" << instanceName <<
"'";
1254 mo->getSimulationType() == VirtualRobot::SceneObject::Physics::eStatic;
1255 addObject(objectClass, instanceName, poseGlobal, isStatic);
1279 const std::string segmentName =
"agentInstances";
1283 PersistentEntitySegmentBasePrx segInstances = snapshotInterfacePrx->getSegment(segmentName);
1287 ARMARX_ERROR <<
"Segment not found in snapshot: " << segmentName;
1291 EntityIdList ids = segInstances->getAllEntityIds();
1294 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
1296 EntityBasePtr snapEntity = segInstances->getEntityById(*it);
1299 auto agentName = snapAgent->getName();
1300 std::string agentModelFile = snapAgent->getAgentFilePath();
1301 std::string absModelFile;
1304 ARMARX_INFO <<
"Robot with name '" << agentName <<
"' already exists.";
1310 <<
"'- file not found: " << agentModelFile;
1316 if (
addRobot(agentName, absModelFile, snapAgent->getPose()->toEigen(), agentModelFile)
1333 const NameValueMap& angles,
1334 const NameValueMap& velocities,
1335 const Ice::Current&)
1337 physicsWorld->actuateRobotJoints(robotName, angles, velocities);
1342 const NameValueMap& angles,
1343 const Ice::Current&)
1345 physicsWorld->actuateRobotJointsPos(robotName, angles);
1350 const NameValueMap& velocities,
1351 const Ice::Current&)
1353 physicsWorld->actuateRobotJointsVel(robotName, velocities);
1358 const NameValueMap& torques,
1359 const Ice::Current&)
1361 physicsWorld->actuateRobotJointsTorque(robotName, torques);
1366 const PoseBasePtr& globalPose,
1367 const Ice::Current&)
1369 VirtualRobot::MathTools::Quaternion qa;
1370 qa.x = globalPose->orientation->qx;
1371 qa.y = globalPose->orientation->qy;
1372 qa.z = globalPose->orientation->qz;
1373 qa.w = globalPose->orientation->qw;
1374 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1375 gp(0, 3) = globalPose->position->x;
1376 gp(1, 3) = globalPose->position->y;
1377 gp(2, 3) = globalPose->position->z;
1383 const std::string& robotNodeName,
1384 const Vector3BasePtr& force,
1385 const Ice::Current&)
1387 Vector3Ptr v3p = Vector3Ptr::dynamicCast(force);
1388 physicsWorld->applyForceRobotNode(robotName, robotNodeName, v3p->toEigen());
1393 const std::string& robotNodeName,
1394 const Vector3BasePtr& torque,
1395 const Ice::Current&)
1397 Vector3Ptr v3p = Vector3Ptr::dynamicCast(torque);
1398 physicsWorld->applyTorqueRobotNode(robotName, robotNodeName, v3p->toEigen());
1403 const Vector3BasePtr& force,
1404 const Ice::Current&)
1406 Vector3Ptr v3p = Vector3Ptr::dynamicCast(force);
1407 physicsWorld->applyForceObject(objectName, v3p->toEigen());
1412 const Vector3BasePtr& torque,
1413 const Ice::Current&)
1415 Vector3Ptr v3p = Vector3Ptr::dynamicCast(torque);
1416 physicsWorld->applyTorqueObject(objectName, v3p->toEigen());
1421 const std::string& instanceName,
1422 const PoseBasePtr& globalPose,
1424 const Ice::Current&)
1429 ARMARX_WARNING <<
"Cannot add object - no connection to common storage";
1432 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1433 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1438 ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(objectClassBase);
1442 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" already exists";
1448 ARMARX_ERROR <<
"Invalid object class; could not create object with instance name "
1456 VirtualRobot::ManipulationObjectPtr mo =
1457 sw->getManipulationObject();
1461 ARMARX_ERROR <<
"Could not retrieve manipulation object of object class "
1462 << objectClass->getName();
1469 mo->setName(instanceName);
1471 ARMARX_LOG <<
"Adding manipulation object " << mo->getName() <<
" of class "
1472 << objectClass->getName();
1475 VirtualRobot::MathTools::Quaternion qa;
1476 qa.x = globalPose->orientation->qx;
1477 qa.y = globalPose->orientation->qy;
1478 qa.z = globalPose->orientation->qz;
1479 qa.w = globalPose->orientation->qw;
1480 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1481 gp(0, 3) = globalPose->position->x;
1482 gp(1, 3) = globalPose->position->y;
1483 gp(2, 3) = globalPose->position->z;
1484 mo->setGlobalPose(gp);
1485 VirtualRobot::SceneObject::Physics::SimulationType simType =
1486 (isStatic) ? VirtualRobot::SceneObject::Physics::eKinematic
1487 : VirtualRobot::SceneObject::Physics::eDynamic;
1488 physicsWorld->addObstacle(mo, simType, std::string(), objectClassBase->getName());
1498 const std::string& instanceName,
1499 const PoseBasePtr& globalPose,
1501 const Ice::Current&)
1503 ARMARX_INFO <<
"Add object from packagePath " << packagePath <<
": " << instanceName;
1509 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1510 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1513 std::string filename;
1516 ARMARX_ERROR <<
"Could not find file: \"" << packagePath.path <<
"\".";
1526 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" already exists";
1531 VirtualRobot::ManipulationObjectPtr mo =
1532 VirtualRobot::ObjectIO::loadManipulationObject(filename);
1536 ARMARX_ERROR <<
"Could not retrieve manipulation object from file " << filename;
1543 mo->setName(instanceName);
1548 VirtualRobot::MathTools::Quaternion qa;
1549 qa.x = globalPose->orientation->qx;
1550 qa.y = globalPose->orientation->qy;
1551 qa.z = globalPose->orientation->qz;
1552 qa.w = globalPose->orientation->qw;
1553 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1554 gp(0, 3) = globalPose->position->x;
1555 gp(1, 3) = globalPose->position->y;
1556 gp(2, 3) = globalPose->position->z;
1557 mo->setGlobalPose(gp);
1558 VirtualRobot::SceneObject::Physics::SimulationType simType =
1559 (isStatic) ? VirtualRobot::SceneObject::Physics::eKinematic
1560 : VirtualRobot::SceneObject::Physics::eDynamic;
1561 physicsWorld->addObstacle(mo, simType, filename, instanceName, {}, packagePath.package);
1574 const DrawColor& color,
1575 const std::string& instanceName,
1576 const PoseBasePtr& globalPose,
1578 const Ice::Current&)
1582 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1583 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1590 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" already exists";
1594 if (depth <= 0 || width <= 0 || height <= 0)
1596 ARMARX_ERROR <<
"Invalid properties; could not create object with instance name "
1601 VirtualRobot::VisualizationFactory::Color
c;
1605 c.transparency = color.a;
1606 VirtualRobot::ObstaclePtr o = VirtualRobot::Obstacle::createBox(width, height, depth,
c);
1616 o->setName(instanceName);
1618 ARMARX_LOG <<
"Adding box object " << o->getName();
1623 VirtualRobot::MathTools::Quaternion qa;
1624 qa.x = globalPose->orientation->qx;
1625 qa.y = globalPose->orientation->qy;
1626 qa.z = globalPose->orientation->qz;
1627 qa.w = globalPose->orientation->qw;
1628 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(qa);
1629 gp(0, 3) = globalPose->position->x;
1630 gp(1, 3) = globalPose->position->y;
1631 gp(2, 3) = globalPose->position->z;
1632 o->setGlobalPose(gp);
1633 VirtualRobot::SceneObject::Physics::SimulationType simType =
1634 (isStatic) ? VirtualRobot::SceneObject::Physics::eStatic
1635 : VirtualRobot::SceneObject::Physics::eDynamic;
1637 BoxVisuPrimitivePtr bp(
new BoxVisuPrimitive());
1640 bp->height = height;
1642 bp->massKG = massKG;
1645 physicsWorld->addObstacle(o, simType, std::string(), std::string(), bp);
1658 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1667 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
1668 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1674 ARMARX_ERROR <<
"Object with instance name \"" << instanceName <<
"\" does not exist";
1678 ARMARX_LOG <<
"Removing object " << instanceName;
1682 ARMARX_ERROR <<
"Could not remove object with instance name \"" << instanceName <<
"\"";
1694 const PoseBasePtr& globalPose,
1695 const Ice::Current&)
1697 VirtualRobot::MathTools::Quaternion
q;
1698 q.x = globalPose->orientation->qx;
1699 q.y = globalPose->orientation->qy;
1700 q.z = globalPose->orientation->qz;
1701 q.w = globalPose->orientation->qw;
1702 Eigen::Matrix4f gp = VirtualRobot::MathTools::quat2eigen4f(
q);
1703 gp(0, 3) = globalPose->position->x;
1704 gp(1, 3) = globalPose->position->y;
1705 gp(2, 3) = globalPose->position->z;
1712 SimulationType type,
1713 const Ice::Current&)
1715 VirtualRobot::SceneObject::Physics::SimulationType st =
1716 VirtualRobot::SceneObject::Physics::eDynamic;
1717 if (type == armarx::Kinematic)
1719 st = VirtualRobot::SceneObject::Physics::eKinematic;
1721 ARMARX_DEBUG <<
"setting simulation type of " << objectName <<
" to " << st;
1751 const std::string& nodeName,
1752 const Ice::Current&)
1754 return physicsWorld->getRobotJointAngle(robotName, nodeName);
1760 return physicsWorld->getRobotJointVelocities(robotName);
1765 const std::string& nodeName,
1766 const Ice::Current&)
1768 return physicsWorld->getRobotJointVelocity(robotName, nodeName);
1780 return physicsWorld->getRobotForceTorqueSensors(robotName);
1785 const std::string& nodeName,
1786 const Ice::Current&)
1788 return physicsWorld->getRobotJointLimitLo(robotName, nodeName);
1793 const std::string& nodeName,
1794 const Ice::Current&)
1796 return physicsWorld->getRobotJointLimitHi(robotName, nodeName);
1808 const std::string& nodeName,
1809 const Ice::Current&)
1811 return physicsWorld->getRobotMaxTorque(robotName, nodeName);
1816 const std::string& nodeName,
1818 const Ice::Current&)
1820 physicsWorld->setRobotMaxTorque(robotName, nodeName, maxTorque);
1825 const std::string& robotNodeName,
1826 const Ice::Current&)
1834 const std::string& nodeName,
1835 const Ice::Current&)
1843 const std::string& nodeName,
1844 const Ice::Current&)
1852 const std::string& robotNodeName,
1853 const Vector3BasePtr& vel,
1854 const Ice::Current&)
1856 Eigen::Vector3f newVel = Vector3Ptr::dynamicCast(vel)->toEigen();
1857 physicsWorld->setRobotLinearVelocity(robotName, robotNodeName, newVel);
1862 const std::string& robotNodeName,
1863 const Vector3BasePtr& vel,
1864 const Ice::Current&)
1866 Vector3Ptr newVel = Vector3Ptr::dynamicCast(vel);
1867 physicsWorld->setRobotAngularVelocity(robotName, robotNodeName, newVel->toEigen());
1872 const std::string& robotNodeName,
1873 const Vector3BasePtr& vel,
1874 const Ice::Current&)
1876 Eigen::Vector3f newVel = Vector3Ptr::dynamicCast(vel)->toEigen();
1877 physicsWorld->setRobotLinearVelocityRobotRootFrame(robotName, robotNodeName, newVel);
1882 const std::string& robotNodeName,
1883 const Vector3BasePtr& vel,
1884 const Ice::Current&)
1886 Eigen::Vector3f newVel = Vector3Ptr::dynamicCast(vel)->toEigen();
1887 physicsWorld->setRobotAngularVelocityRobotRootFrame(robotName, robotNodeName, newVel);
1898 const std::string& robotNodeName,
1899 const Ice::Current&)
1902 return physicsWorld->hasRobotNode(robotName, robotNodeName);
1914 const std::string& robotNodeName,
1915 const std::string& objectName,
1916 const Ice::Current&)
1918 ARMARX_VERBOSE <<
"Object released " << robotName <<
"," << objectName;
1919 physicsWorld->objectReleased(robotName, robotNodeName, objectName);
1924 const std::string& robotNodeName,
1925 const std::string& objectName,
1926 const Ice::Current&)
1928 ARMARX_VERBOSE <<
"Object grasped" << robotName <<
"," << objectName;
1929 physicsWorld->objectGrasped(robotName, robotNodeName, objectName);
1935 return static_cast<float>(
physicsWorld->getCurrentSimTime());
1952 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
1953 SimulatorInformation res;
1958 std::vector<std::string> robNames =
physicsWorld->getRobotNames();
1959 res.nrRobots =
static_cast<int>(robNames.size());
1961 res.nrActuatedJoints =
physicsWorld->getRobotJointAngleCount();
1965 res.simTimeStepMeasuredMS =
physicsWorld->getSimulationStepTimeMeasured();
1966 res.simTimeStepDurationMS =
physicsWorld->getSimulationStepDuration();
1968 res.simTimeFactor = 0;
1969 if (res.simTimeStepMeasuredMS > 0)
1971 res.simTimeFactor = res.simTimeStepDurationMS / res.simTimeStepMeasuredMS;
1976 for (VirtualRobot::SceneObjectPtr& o :
objects)
1980 ovd.name = o->getName();
1982 ovd.objectPoses[ovd.name] = p;
1983 VirtualRobot::Obstacle* ob =
dynamic_cast<VirtualRobot::Obstacle*
>(o.get());
1987 ovd.filename = ob->getFilename();
1990 if (o->getSimulationType() == VirtualRobot::SceneObject::Physics::eStatic)
1992 ovd.staticObject =
true;
1996 ovd.staticObject =
false;
1999 res.objects.push_back(ovd);
2002 for (
auto& r : robNames)
2011 ovd.robotFile = rob->getFilename();
2014 res.robots.push_back(ovd);
2027 std::string filename;
2040 ARMARX_ERROR <<
"Could not find file: \"" << packagePath.path <<
"\".";
2046 const std::string& robFileGlobal,
2048 const std::string& robFile,
2055 std::map<std::string, float> initConfig,
2056 bool selfCollisions)
2058 ARMARX_DEBUG <<
"Add robot from file " << robFileGlobal;
2059 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
2060 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2087 return robotInstanceName;
2097 for (
auto& rob : syncData.
robots)
2100 std::string top = rob.robotTopicName;
2109 for (
auto& fti : rob.forceTorqueSensors)
2111 ARMARX_INFO <<
"Offering topic " << fti.topicName;
2116 ARMARX_INFO <<
"Connecting to topic " << fti.topicName;
2137ObjectClassInformationSequence
2139 const std::string& frameName,
2140 const std::string& className,
2141 const Ice::Current&)
2143 auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
2144 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2148 ObjectClassInformationSequence result;
2151 for (
const auto&
object :
objects)
2153 ObjectClassInformation inf;
2155 inf.timestampMicroSeconds =
2156 static_cast<Ice::Long
>(
physicsWorld->getCurrentSimTime() * 1.0e6);
2157 inf.className = className;
2158 inf.manipulationObjectName = object;
2159 Eigen::Matrix4f worldPose =
physicsWorld->getObjectPose(
object);
2167 inf.pose =
physicsWorld->toFramedPose(worldPose, robotName, frameName);
2170 result.push_back(inf);
2178 const std::string& robotNodeName,
2179 const std::string& worldObjectName,
2180 const Ice::Current&)
2182 return physicsWorld->getDistance(robotName, robotNodeName, worldObjectName);
2187 const std::string& robotNodeName1,
2188 const std::string& robotNodeName2,
2189 const Ice::Current&)
2191 return physicsWorld->getRobotNodeDistance(robotName, robotNodeName1, robotNodeName2);
2197 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2257 IceUtil::Time startTime;
2272 startTime = IceUtil::Time::now();
2274 sleepTimeMS =
static_cast<int>(
2276 static_cast<float>((IceUtil::Time::now() - startTime).toMilliSeconds()));
2278 if (sleepTimeMS < 0)
2281 <<
" milliseconds too long!";
2285 usleep(
static_cast<unsigned int>(sleepTimeMS * 1000));
2325 return static_cast<long>(
physicsWorld->getCurrentSimTime() * 1000);
2331 IceUtil::Time startTime = IceUtil::Time::now();
2342 IceUtil::Time durationSim = IceUtil::Time::now() - startTime;
2347 << durationSim.toMilliSecondsDouble();
2350 ARMARX_DEBUG <<
"*** Step Physics, MS:" << durationSim.toMilliSecondsDouble();
2352 startTime = IceUtil::Time::now();
2355 IceUtil::Time durationSync = IceUtil::Time::now() - startTime;
2358 auto lockData =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2378 IceUtil::Time startTime = IceUtil::Time::now();
2380 SceneVisuData reportData =
physicsWorld->copySceneVisuData();
2396 const auto lockEngine =
physicsWorld->getScopedEngineLock(__FUNCTION__);
2397 const auto lockSync =
physicsWorld->getScopedSyncLock(__FUNCTION__);
2402 std::vector<SimDynamics::DynamicsEngine::DynamicsContactInfo> contacts =
2404 VirtualRobot::ColorMap cm(VirtualRobot::ColorMap::eHot);
2405 float maxImpulse = 2.0f;
2406 float arrowLength = 50.0f;
2410 for (
auto&
c : contacts)
2412 std::stringstream ss;
2413 ss <<
"Contact_" << i;
2418 std::string name = ss.str();
2419 std::string name2 = name +
"_2";
2422 if (!
c.objectAName.empty())
2424 objA =
c.objectAName;
2433 if (!
c.objectBName.empty())
2435 objB =
c.objectBName;
2442 ARMARX_DEBUG <<
"CONTACT " << name <<
", objects: " << objA <<
"-" << objB
2443 <<
", impulse:" <<
c.appliedImpulse;
2444 float intensity =
static_cast<float>(
c.appliedImpulse);
2446 if (intensity > maxImpulse)
2448 intensity = maxImpulse;
2451 intensity /= maxImpulse;
2452 VirtualRobot::VisualizationFactory::Color colSimox = cm.getColor(intensity);
2459 Eigen::Vector3f dir2 = -(
c.normalGlobalB);
2474 std::stringstream ss;
2475 ss <<
"Contact_" << j;
2476 std::string name = ss.str();
2477 std::string name2 = name +
"_2";
2492 "CoM",
"GlobalCoM_" + name, pos, DrawColor{0.f, 0.f, 1.f, 0.5f}, 20);
2496 IceUtil::Time duration = IceUtil::Time::now() - startTime;
2521 IceUtil::Time startTime = IceUtil::Time::now();
2532 ctx[
"origin"] =
"simulation";
2538 header.timestampInMicroSeconds = reportData.
timestamp.toMicroSeconds();
2540 TransformStamped globalRobotPose;
2541 globalRobotPose.header = header;
2542 globalRobotPose.transform = r.
pose;
2559 IceUtil::Time duration = IceUtil::Time::now() - startTime;
2575 ContactInfoSequence result;
2577 for (
auto& contact : contacts)
2579 ContactInformation contactInfo;
2580 contactInfo.objectNameA = contact.objectAName;
2581 contactInfo.objectNameB = contact.objectBName;
2582 contactInfo.posGlobalA =
new Vector3(contact.posGlobalA);
2583 contactInfo.posGlobalB =
new Vector3(contact.posGlobalB);
2584 result.push_back(contactInfo);
2599 std::string instanceName;
2601 instanceName, filename, Eigen::Matrix4f::Identity(),
"", 10.0, 0, 0,
false, scaling);
2602 return instanceName;
2607 const std::string& filename,
2609 const Ice::Current&)
2612 std::string name = instanceName;
2614 name, filename, Eigen::Matrix4f::Identity(),
"", 10.0, 0, 0,
false, scaling);
2628 std::string instanceName;
2630 instanceName, filename, Eigen::Matrix4f::Identity(),
"", 10.0, 0, 0,
false, 1.0f);
2631 return instanceName;
2638 for (
auto& robot : report.
robots)
2640 if (robot.robotName == robotName)
2646 return SimulatedRobotState();
#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...
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
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