30 #include <Eigen/Geometry>
32 #include <VirtualRobot/EndEffector/EndEffector.h>
33 #include <VirtualRobot/RobotConfig.h>
37 #include <RobotAPI/interface/objectpose/ObjectPoseStorageInterface.h>
55 simulatorPrxName = getProperty<std::string>(
"SimulatorProxyName").getValue();
64 if (getProperty<bool>(
"UseLegacyWorkingMemory").getValue())
80 getProxy<memoryx::WorkingMemoryInterfacePrx>(
"WorkingMemory",
false,
"",
false);
115 "cmp.ObjectPoseStorageName",
116 "Name of the object pose storage (only used if necessary).");
131 << objectName <<
flush;
171 ARMARX_WARNING <<
"Could not get joint angles fvrom simulator...";
180 std::string myShapeName = shapeName;
190 if (!eef->hasPreshape(myShapeName))
192 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " << eef->getName()
193 <<
". Looking for partial match";
195 bool foundMatch =
false;
197 for (
const std::string& name : eef->getPreshapes())
199 if (name.find(myShapeName) != std::string::npos)
210 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " << eef->getName()
211 <<
" available shapes: " << eef->getPreshapes();
216 VirtualRobot::RobotConfigPtr config = eef->getPreshape(myShapeName);
217 std::map<std::string, float>
jointAngles = config->getRobotNodeJointValueMap();
219 NameControlModeMap controlModes;
221 for (std::pair<std::string, float> pair :
jointAngles)
223 controlModes.insert(std::make_pair(pair.first, ePositionControl));
226 kinematicUnitPrx->switchControlMode(controlModes);
232 const std::string& objectInstanceName,
233 const Ice::Current&
c)
235 std::string myShapeName = shapeName;
236 ARMARX_INFO <<
"Setting shape " << myShapeName <<
" while checking for collision with "
237 << objectInstanceName;
245 if (!eef->hasPreshape(myShapeName))
247 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " << eef->getName()
248 <<
". Looking for partial match";
250 bool foundMatch =
false;
251 for (
const std::string& name : eef->getPreshapes())
253 if (name.find(myShapeName) != std::string::npos)
264 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " << eef->getName()
265 <<
" available shapes: " << eef->getPreshapes();
270 VirtualRobot::EndEffectorPtr endeffector = robot->getEndEffector(eef->getName());
273 auto loadFromObjectPoseStorage = [
this,
274 &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
279 auto fetchObjectPose = [
this, &objectID, &client]() -> std::optional<Eigen::Matrix4f>
285 if (
auto it = objectPoses.find(objectID); it != objectPoses.end())
287 return it->second.objectPoseGlobal;
292 if (
auto objectPose = fetchObjectPose())
294 if (std::optional<armarx::ObjectInfo> info =
297 VirtualRobot::ManipulationObjectPtr
object =
299 object->setGlobalPose(objectPose.value());
306 auto loadFromWorkingMemory = [
this,
307 &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
310 workingMemoryPrx->getObjectInstancesSegment()->getObjectInstanceByName(
311 objectInstanceName));
314 robotStateComponentPrx, VirtualRobot::RobotIO::eCollisionModel);
317 const std::string objectClassName = objInstance->getMostProbableClass();
319 auto classes = workingMemoryPrx->getObjectClassesSegment()->addPriorClassWithSubclasses(
328 memoryx::ObjectClassPtr::dynamicCast(workingMemoryPrx->getObjectClassesSegment()
329 ->getEntityByName(objectClassName)
338 objInstance->setPose(objInstance->getPose()->toGlobal(robot));
339 simoxObject->updateFromEntity(objInstance);
341 return simoxObject->getManipulationObject();
344 VirtualRobot::ManipulationObjectPtr manipulationObject =
nullptr;
345 if (not manipulationObject)
347 manipulationObject = loadFromObjectPoseStorage();
349 if (not manipulationObject and workingMemoryPrx)
351 manipulationObject = loadFromWorkingMemory();
354 if (manipulationObject)
356 endeffector->closeActors(manipulationObject);
359 endeffector->getConfiguration()->getRobotNodeJointValueMap();
361 NameControlModeMap controlModes;
364 controlModes.emplace(name, ePositionControl);
367 kinematicUnitPrx->switchControlMode(controlModes);
372 ARMARX_WARNING <<
"Could not load object '" << objectInstanceName <<
"'. "
373 <<
"Cannot set shape '" << shapeName <<
"' with collision check. "
374 <<
"Setting shape '" << shapeName <<
"' without collision check instead.";
375 setShape(shapeName,
c);
384 NameControlModeMap controlModes;
386 for (std::pair<std::string, float> pair :
jointAngles)
388 controlModes.insert(std::make_pair(pair.first, ePositionControl));
391 kinematicUnitPrx->switchControlMode(controlModes);
393 simulatorPrx->actuateRobotJointsPos(getRobotNameFromHandUnitName(),
403 std::map<std::string, std::vector<std::string>> conversion_dict;
404 conversion_dict[
"Fingers"] = {
"Index",
"Middle",
"Ring",
"Pinky"};
405 conversion_dict[
"Thumb"] = {
"Thumb"};
408 for (
const auto& joint : joints)
410 if (conversion_dict.find(joint.first) != conversion_dict.end())
412 auto correspondences = conversion_dict.at(joint.first);
413 for (
const auto& correspondence : correspondences)
415 for (
int i = 1; i < 4; i++)
417 std::stringstream joint_id;
418 joint_id << correspondence <<
" " << side <<
" " << i <<
" Joint";
419 robot_joints[joint_id.str()] = joint.second * M_PI_2;
425 ARMARX_WARNING <<
"No corresponding finger joint found for " << joint.first;
441 std::stringstream stream;
442 stream << side.front();