2 #include <VirtualRobot/Grasping/GraspSet.h>
3 #include <VirtualRobot/XML/ObjectIO.h>
11 Base(iceMemory, PROVIDER_SEGMENT_NAME, CORE_SEGMENT_NAME)
23 std::optional<arondto::KnownGraspInfo> KnownGraspProviderSegment::knownGraspInfoFromObjectInfo(
const ObjectInfo& info)
25 std::string objectClassName = info.
className();
26 auto fileLocInfo = info.
file(
".xml",
"_Grasps");
27 std::filesystem::path graspFilePath = fileLocInfo.
absolutePath;
29 if (std::filesystem::is_regular_file(graspFilePath))
33 auto manipulationObject = VirtualRobot::ObjectIO::loadManipulationObject(graspFilePath);
35 if(manipulationObject ==
nullptr)
41 arondto::KnownGraspInfo
ret;
42 ret.correspondingObject.memoryName =
"Object";
43 ret.correspondingObject.coreSegmentName =
"Class";
44 ret.correspondingObject.providerSegmentName =
"PriorKnowledgeData";
45 ret.correspondingObject.entityName = info.
idStr();
46 ret.xml.package = fileLocInfo.package;
47 ret.xml.path = fileLocInfo.relativePath;
49 for (
const VirtualRobot::GraspSetPtr& graspSet : manipulationObject->getAllGraspSets())
53 arondto::KnownGraspSet retGraspSet;
55 retGraspSet.name = graspSet->getName();
56 retGraspSet.robot = graspSet->getRobotType();
57 retGraspSet.endeffector = graspSet->getEndEffector();
59 for (
const VirtualRobot::GraspPtr& grasp : graspSet->getGrasps())
63 arondto::KnownGrasp retGrasp;
65 retGrasp.name = grasp->getName();
66 retGrasp.quality = grasp->getQuality();
67 retGrasp.creator = grasp->getCreationMethod();
68 retGrasp.pose = grasp->getTransformation();
70 ARMARX_VERBOSE <<
"Found grasp '" << retGrasp.name <<
"' in set '" << retGraspSet.name <<
"' for obj '" << objectClassName <<
"' with pose \n" << retGrasp.pose;
72 retGraspSet.grasps.push_back(retGrasp);
74 ret.graspSets[retGraspSet.name] = retGraspSet;
79 ARMARX_WARNING << graspFilePath <<
" is not a manipulation object!";
86 void KnownGraspProviderSegment::loadMemory()
89 ObjectFinder objectFinder;
92 const bool checkPaths =
false;
93 std::vector<ObjectInfo> infos = objectFinder.findAllObjects(checkPaths);
96 ARMARX_INFO <<
"Checking up to " << infos.size() <<
" object classes from '" << objectFinder.getPackageName() <<
"' ...";
99 for (ObjectInfo& info : infos)
102 if (
auto knownGraspCandidate = knownGraspInfoFromObjectInfo(info); knownGraspCandidate)
104 EntityUpdate&
update = commit.add();
105 update.entityID = providerID.withEntityName(info.
id().
str());
110 knownGraspCandidate->toAron()
114 ARMARX_INFO <<
"Loaded " << commit.updates.size() <<
" grasp candidates from object classes from '" << objectFinder.getPackageName() <<
"'.";
116 if (!result.allSuccess())
118 ARMARX_WARNING <<
"Got errors for commit: " << result.allErrorMessages();