31 #include <VirtualRobot/Grasping/GraspSet.h>
41 usingProxy(
"WorkingMemory");
42 usingProxy(
"PriorKnowledge");
43 usingProxy(
"RobotStateComponent");
45 offeringTopic(
"DebugDrawerUpdates");
50 getProxy(rsc,
"RobotStateComponent");
51 getProxy(wm,
"WorkingMemory");
52 getProxy(prior,
"PriorKnowledge");
53 objectInstances = wm->getObjectInstancesSegment();
54 objectClasses = prior->getObjectClassesSegment();
58 debugDrawerPrx = getTopic<armarx::DebugDrawerInterfacePrx>(
"DebugDrawerUpdates");
71 StringStringDictionary SimpleGraspGenerator::getTcpGcpMapping()
73 StringStringDictionary mapping;
74 auto entries =
Split(getProperty<std::string>(
"TCPtoGCPMapping"),
";",
true,
true);
75 for (
auto& e : entries)
86 GeneratedGraspList result;
89 ObjectInstancePtr instance = ObjectInstancePtr::dynamicCast(objectInstances->getEntityById(objectInstanceEntityId));
92 ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(objectClasses->getEntityByName(instance->getMostProbableClass()));
93 ARMARX_CHECK_EXPRESSION(objectClass) <<
"no object class with name '" << instance->getMostProbableClass() <<
"' found ";
96 VirtualRobot::ManipulationObjectPtr mo = simoxWrapper->getManipulationObject();
100 auto objectFramedPose = instance->getPose();
101 ARMARX_INFO <<
"object Pose: " << objectFramedPose->output();
102 if (instance->hasLocalizationTimestamp())
106 ARMARX_INFO <<
"object has timestamp " << instance->getLocalizationTimestamp().toDateTime() <<
" and frame " << objectFramedPose->frame <<
" with robot at " << robot->getGlobalPose();
107 objectFramedPose->changeToGlobal(robot);
112 objectFramedPose->changeToGlobal(rsc->getSynchronizedRobot());
114 ARMARX_INFO <<
"global object Pose: " << objectFramedPose->output();
118 if (getProperty<bool>(
"EnableVisualization"))
120 debugDrawerPrx->setPoseVisu(
"GeneratedGrasps",
"ObjectPose", objectFramedPose);
129 auto tcpGcpMapping = getTcpGcpMapping();
130 std::string graspNameInfix = getProperty<std::string>(
"GraspNameInfix");
132 auto robotType = getProperty<std::string>(
"RobotType").getValue();
133 for (
const VirtualRobot::GraspSetPtr& gs : mo->getAllGraspSets())
135 if (gs->getRobotType() != robotType)
139 for (
const VirtualRobot::GraspPtr& g : gs->getGrasps())
141 ARMARX_INFO <<
"Found Grasp: " << g->getName() <<
" for eef: " << g->getEefName();
142 if (!
Contains(g->getName(), graspNameInfix,
true))
144 ARMARX_INFO <<
"grasp name does not contain infix " << graspNameInfix <<
" - skipping it";
147 if (!robot->hasEndEffector(g->getEefName()))
149 ARMARX_INFO <<
"Endeffector " << g->getEefName() <<
" does not exist in this robot - skipping grasps";
152 auto globalTcpPose = g->getTcpPoseGlobal(globalObjectPose);
156 auto gcpName = tcpGcpMapping.at(robot->getEndEffector(g->getEefName())->getTcp()->getName());
157 auto gcpNode = robot->getRobotNode(gcpName);
159 Eigen::Vector3f preposeOffsetGCPFrame = Eigen::Vector3f::Zero();
160 preposeOffsetGCPFrame(2) = -getProperty<float>(
"PreposeOffset").getValue();
161 Eigen::Vector3f preposeOffsetTCPFrame = robot->getEndEffector(g->getEefName())->getTcp()->transformTo(gcpNode, preposeOffsetGCPFrame);
163 preposeOffsetGlobal.block<3, 1>(0, 3) += globalTcpPose.block<3, 3>(0, 0) * preposeOffsetTCPFrame;
164 ARMARX_INFO <<
" before up offset: " << preposeOffsetGlobal;
165 preposeOffsetGlobal(2, 3) += getProperty<float>(
"UpwardsOffset").getValue();
169 result.push_back({1.f, g->getEefName(), g->getName(), framedTcpPose, framedTcpPrepose});
177 ARMARX_WARNING <<
"No grasps defined for object class '" << instance->getMostProbableClass() <<
"'";
179 ARMARX_INFO <<
"Found " << result.size() <<
" grasps";
185 memoryx::ObjectInstanceBasePtr objectInstance = wm->getObjectInstancesSegment()->getObjectInstanceByName(objectName);
186 std::string
id = objectInstance->getId();
188 return generateGrasps(
id);