25 #include <VirtualRobot/CollisionDetection/CollisionChecker.h>
26 #include <VirtualRobot/XML/RobotIO.h>
31 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
43 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
50 workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(
51 getProperty<std::string>(
"WorkingMemoryName").getValue());
52 commonStoragePrx = workingMemoryPrx->getCommonStorage();
60 const ::Ice::Current&)
62 clearCollisionObjects();
63 addCollisionObjects(
list);
68 const ::Ice::Current&)
73 std::vector<CollisionObjectData> newObjects;
75 for (
const auto& elem :
list)
80 newObject.
object = elem.objectClassBase;
83 << newObject.
object->getId();
86 memoryx::ObjectClassPtr::dynamicCast(elem.objectClassBase);
91 s <<
"Can't use object class with ice id " << elem.objectClassBase->ice_id();
93 throw armarx::InvalidArgumentException{
s.str()};
100 VirtualRobot::ManipulationObjectPtr orgMo = sw->getManipulationObject();
101 std::string moName = orgMo->getName();
103 VirtualRobot::ManipulationObjectPtr mo = orgMo->clone(moName);
107 const auto objectPose = armarx::PosePtr::dynamicCast(elem.objectPose);
112 s <<
"Can't convert pose of " << objectClass->getName() <<
" to armarx::Pose.";
114 throw armarx::InvalidArgumentException{
s.str()};
117 mo->setGlobalPose(objectPose->toEigen());
120 VirtualRobot::CollisionModelPtr colModel = mo->getCollisionModel();
123 newObjects.push_back(newObject);
124 ARMARX_VERBOSE <<
"Object: " << newObjects.size() - 1 <<
" done.";
128 std::copy(newObjects.begin(), newObjects.end(), std::back_inserter(objects));
131 <<
" collision objects. (Total: " << objects.size() <<
")";
143 const std::string& agentColModelName,
144 const ::Ice::Current&)
146 ARMARX_VERBOSE <<
"Setting agent '" << newAgent->getName() <<
"' with id " << newAgent->getId();
148 std::string agentFilePath = newAgent->getAgentFilePath();
155 <<
" additional paths";
173 s <<
"Can't load agent from: " << agentFilePath;
175 throw armarx::InvalidArgumentException{
s.str()};
179 if (!agent2->hasRobotNode(agentColModelName) ||
180 !agent2->getRobotNode(agentColModelName)->getCollisionModel())
183 s <<
"Agent has no collision model with name " << agentColModelName;
185 throw armarx::InvalidArgumentException{
s.str()};
189 agentCollisionModel = agent->getRobotNode(agentColModelName)->getCollisionModel();
190 agentZCoord = agent->getGlobalPose()(2, 3);
200 s <<
"Invalid margin: " << margin <<
" < 0.0";
202 throw armarx::InvalidArgumentException{
s.str()};
205 safetyMargin = margin;
211 if (!agentCollisionModel)
213 throw std::logic_error{
"no agent collision model"};
223 pose.block<3, 3>(0, 0) =
224 VirtualRobot::MathTools::axisangle2eigen3f(Eigen::Vector3f{0.f, 0.f, 1.f}, position.z);
225 pose(0, 3) = position.x;
226 pose(1, 3) = position.y;
227 pose(3, 3) = agentZCoord;
228 agent->setGlobalPose(pose);
230 if (safetyMargin > 0.01f)
232 for (
const auto&
object : objects)
235 VirtualRobot::CollisionChecker::getGlobalCollisionChecker()->calculateDistance(
236 agentCollisionModel,
object.colModel);
238 if (dist <= safetyMargin)
247 for (
const auto&
object : objects)
249 bool col = VirtualRobot::CollisionChecker::getGlobalCollisionChecker()->checkCollision(
250 agentCollisionModel,
object.colModel);