28 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
34 #include <VirtualRobot/XML/RobotIO.h>
35 #include <VirtualRobot/CollisionDetection/CollisionChecker.h>
45 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
51 workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(getProperty<std::string>(
"WorkingMemoryName").getValue());
52 commonStoragePrx = workingMemoryPrx->getCommonStorage();
60 clearCollisionObjects();
61 addCollisionObjects(
list);
69 std::vector<CollisionObjectData> newObjects;
71 for (
const auto& elem :
list)
76 newObject.
object = elem.objectClassBase;
85 s <<
"Can't use object class with ice id " << elem.objectClassBase->ice_id();
87 throw armarx::InvalidArgumentException {
s.str()};
93 VirtualRobot::ManipulationObjectPtr orgMo = sw->getManipulationObject();
94 std::string moName = orgMo->getName();
96 VirtualRobot::ManipulationObjectPtr mo = orgMo->clone(moName);
100 const auto objectPose = armarx::PosePtr::dynamicCast(elem.objectPose);
105 s <<
"Can't convert pose of " << objectClass->getName() <<
" to armarx::Pose.";
107 throw armarx::InvalidArgumentException {
s.str()};
110 mo->setGlobalPose(objectPose->toEigen());
113 VirtualRobot::CollisionModelPtr colModel = mo->getCollisionModel();
116 newObjects.push_back(newObject);
117 ARMARX_VERBOSE <<
"Object: " << newObjects.size() - 1 <<
" done.";
121 std::copy(newObjects.begin(), newObjects.end(), std::back_inserter(objects));
123 ARMARX_VERBOSE <<
"Added " << newObjects.size() <<
" collision objects. (Total: " << objects.size() <<
")";
134 ARMARX_VERBOSE <<
"Setting agent '" << newAgent->getName() <<
"' with id " << newAgent->getId();
136 std::string agentFilePath = newAgent->getAgentFilePath();
160 s <<
"Can't load agent from: " << agentFilePath;
162 throw armarx::InvalidArgumentException {
s.str()};
166 if (!agent2->hasRobotNode(agentColModelName) || !agent2->getRobotNode(agentColModelName)->getCollisionModel())
169 s <<
"Agent has no collision model with name " << agentColModelName;
171 throw armarx::InvalidArgumentException {
s.str()};
175 agentCollisionModel = agent->getRobotNode(agentColModelName)->getCollisionModel();
176 agentZCoord = agent->getGlobalPose()(2, 3);
185 s <<
"Invalid margin: " << margin <<
" < 0.0";
187 throw armarx::InvalidArgumentException {
s.str()};
190 safetyMargin = margin;
195 if (!agentCollisionModel)
197 throw std::logic_error {
"no agent collision model"};
207 pose.block<3, 3>(0, 0) = VirtualRobot::MathTools::axisangle2eigen3f(Eigen::Vector3f {0.f, 0.f, 1.f}, position.z);
208 pose(0, 3) = position.x;
209 pose(1, 3) = position.y;
210 pose(3, 3) = agentZCoord;
211 agent->setGlobalPose(pose);
213 if (safetyMargin > 0.01f)
215 for (
const auto&
object : objects)
217 float dist = VirtualRobot::CollisionChecker::getGlobalCollisionChecker()->calculateDistance(
221 if (dist <= safetyMargin)
230 for (
const auto&
object : objects)
232 bool col = VirtualRobot::CollisionChecker::getGlobalCollisionChecker()->checkCollision(