KnownGraspCandidateReader.cpp
Go to the documentation of this file.
2
3#include <optional>
4
5#include <SimoxUtility/algorithm/string/string_tools.h>
6
9
15#include <RobotAPI/libraries/armem_objects/aron/Attachment.aron.generated.h>
18
20{
21 void
23 {
24 ARMARX_DEBUG << "Reader: registerPropertyDefinitions";
25
26 const std::string prefix = propertyPrefix;
27
28 def->optional(properties.memoryName, prefix + "MemoryName");
29
30 def->optional(properties.coreSegmentName,
31 prefix + "CoreSegment",
32 "Name of the memory core segment to use for object instances.");
33 }
34
35 void
37 {
38 // Wait for the memory to become available and add it as dependency.
39 ARMARX_IMPORTANT << "Reader: Waiting for memory '" << properties.memoryName << "' ...";
40 try
41 {
42 memoryReader = memoryNameSystem.useReader(properties.memoryName);
43 ARMARX_IMPORTANT << "Reader: Connected to memory '" << properties.memoryName << "'";
44 }
46 {
47 ARMARX_ERROR << e.what();
48 return;
49 }
50 }
51
52 std::optional<armem::grasping::arondto::KnownGraspInfo>
54 {
55 // clang-format off
57 .getCoreSegment(properties.coreSegmentName);
58 // clang-format on
59
60 const armem::wm::EntityInstance* instance = nullptr;
61 s.forEachInstance([&instance](const wm::EntityInstance& i) { instance = &i; });
62 if (instance == nullptr)
63 {
64 ARMARX_VERBOSE << "No entity snapshots found";
65 return std::nullopt;
66 }
67 return armem::grasping::arondto::KnownGraspInfo::FromAron(instance->data());
68 }
69
70 std::optional<armarx::armem::grasping::arondto::KnownGraspInfo>
71 Reader::queryKnownGraspInfoByEntityName(const std::string& entityName,
73 {
74 // Query all entities from all provider.
76
77 // clang-format off
78 qb
79 .coreSegments().withName(properties.coreSegmentName)
81 .entities().withName(entityName) // first, we search for the input entity, which may be dataset/class/index
83 // clang-format on
84
85 const armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput());
86
87 ARMARX_VERBOSE << "Lookup result in reader: " << qResult;
88
89 if (not qResult.success) /* c++20 [[unlikely]] */
90 {
91 return std::nullopt;
92 }
93
94 auto ret = queryKnownGraspInfo(qResult.memory, timestamp);
95
96 if (not ret)
97 {
98 // No grasp info was found. Try if we find a grasp without the object entity index
99 auto split = simox::alg::split(entityName, "/");
100 if (split.size() > 2) // there is more than just dataset/class
101 {
102 ARMARX_INFO << "No grasp found for object entity " << entityName
103 << ". Search for grasp without the index";
105 }
106 }
107
108 return ret;
109 }
110
111} // namespace armarx::armem::grasping::known_grasps
std::string timestamp()
The memory name system (MNS) client.
Reader useReader(const MemoryID &memoryID)
Use a memory server and get a reader for it.
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition Builder.h:22
CoreSegmentSelector & coreSegments()
Start specifying core segments.
Definition Builder.cpp:42
CoreSegmentSelector & withName(const std::string &name) override
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
EntitySelector & withName(const std::string &name) override
SnapshotSelector & snapshots()
Start specifying entity snapshots.
Definition selectors.cpp:92
EntitySelector & entities()
Start specifying entities.
ProviderSegmentSelector & all() override
SnapshotSelector & beforeOrAtTime(Time timestamp)
Definition selectors.cpp:73
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
std::optional< armem::grasping::arondto::KnownGraspInfo > queryKnownGraspInfoByEntityName(const std::string &, const armem::Time &)
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
std::optional< armem::grasping::arondto::KnownGraspInfo > queryKnownGraspInfo(const armem::wm::Memory &memory, const armem::Time &)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
Client-side working memory core segment.
Client-side working entity instance.
Client-side working memory.
Brief description of class memory.
Definition memory.h:39
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
armem::wm::EntityInstance EntityInstance
armarx::core::time::DateTime Time
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Result of a QueryInput.
Definition Query.h:51
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58