3 #include <SimoxUtility/algorithm/get_map_keys_values.h>
10 #include <RobotAPI/libraries/ArmarXObjects/aron/ObjectID.aron.generated.h>
16 #include <RobotAPI/libraries/armem_objects/aron/ObjectClass.aron.generated.h>
17 #include <RobotAPI/libraries/armem_objects/aron/ObjectInstance.aron.generated.h>
19 #include <RobotAPI/libraries/armem_robot_state/aron/Robot.aron.generated.h>
20 #include <RobotAPI/libraries/armem_robot_state/aron/RobotDescription.aron.generated.h>
33 const std::string prefix = propertyPrefix;
35 def->optional(properties.memoryName, prefix +
"MemoryName");
37 def->optional(properties.coreInstanceSegmentName,
38 prefix +
"CoreSegment",
39 "Name of the memory core segment to use for object instances.");
40 def->optional(properties.coreClassSegmentName,
41 prefix +
"CoreSegment",
42 "Name of the memory core segment to use for object classes.");
46 properties.providerName, prefix +
"write.ProviderName",
"Name of this provider");
53 ARMARX_IMPORTANT <<
"Writer: Waiting for memory '" << properties.memoryName <<
"' ...";
56 memoryWriter = memoryNameSystem.
useWriter(properties.memoryName);
57 memoryReader = memoryNameSystem.
useReader(properties.memoryName);
58 ARMARX_IMPORTANT <<
"Writer: Connected to memory '" << properties.memoryName <<
"'";
66 const auto resultCoreClassSegment =
67 memoryWriter.
addSegment(properties.coreClassSegmentName, properties.providerName);
69 const auto resultCoreInstanceSegmentName =
70 memoryWriter.
addSegment(properties.coreInstanceSegmentName, properties.providerName);
74 std::optional<armem::MemoryID>
80 const std::unordered_map<std::string, MemoryID> knownObjects = queryDescriptions(
Time::Now());
81 ARMARX_VERBOSE <<
"Known articulated objects " << simox::alg::get_keys(knownObjects);
86 if (objectId != knownObjects.end())
88 return objectId->second;
93 throw LocalException(
"articulated object class " + obj.
description.
name +
" not found");
96 if (properties.allowClassCreation)
104 std::optional<armem::MemoryID>
107 std::lock_guard g{memoryWriterMutex};
109 ARMARX_DEBUG <<
"Trying to create core segment + provider segment";
113 memoryWriter.
addSegment(properties.coreClassSegmentName, properties.providerName);
115 if (not result.success)
117 ARMARX_ERROR <<
"Creating core segment failed. Reason: " << result.errorMessage;
124 const auto entityID =
125 providerId.withEntityName(obj.
description.
name).withTimestamp(timestamp);
128 update.entityID = entityID;
130 arondto::RobotDescription aronArticulatedObjectDescription;
133 update.instancesData = {aronArticulatedObjectDescription.toAron()};
134 update.referencedTime = timestamp;
141 if (not updateResult.success)
147 return updateResult.snapshotID;
153 return properties.providerName;
159 this->properties.providerName = providerName;
165 std::lock_guard g{memoryWriterMutex};
172 ARMARX_DEBUG <<
"Storing articulated object instance '" << entityName <<
"' (provider '"
173 << properties.providerName <<
"')";
181 update.entityID = providerId.withEntityName(entityName);
187 arondto::ObjectInstance objectInstance;
190 const std::optional<armem::MemoryID> classId = storeOrGetClass(obj);
199 toAron(objectInstance.classID, *classId);
211 <<
"An object instance name must be provided!";
214 cs.className = objectId.className();
215 cs.instanceName = objectId.instanceName();
216 cs.dataset = objectId.dataset();
218 objectInstance.pose.objectID = cs;
219 objectInstance.pose.providerName = properties.providerName;
220 objectInstance.pose.attachmentValid =
false;
222 objectInstance.pose.isStatic = isStatic;
224 update.instancesData = {objectInstance.toAron()};
225 update.referencedTime = timestamp;
232 if (not updateResult.success)
237 return updateResult.success;
243 const std::optional<armem::MemoryID> classId = storeOrGetClass(obj);
248 <<
"Known classes are " << simox::alg::get_keys(queryDescriptions(
Time::Now()));
256 std::optional<robot_state::description::RobotDescription>
261 .getCoreSegment(properties.coreClassSegmentName)
262 .getProviderSegment(properties.providerName);
276 std::unordered_map<std::string, armem::MemoryID>
279 const armem::wm::CoreSegment& coreSegment =
282 std::unordered_map<std::string, armem::MemoryID> descriptions;
283 coreSegment.forEachEntity(
284 [&descriptions](
const wm::Entity& entity)
288 ARMARX_WARNING <<
"No entity found";
295 const armem::MemoryID snapshotID(sn.id());
296 descriptions.insert({robotDescription->name, snapshotID});
304 std::unordered_map<std::string, armem::MemoryID>
305 Writer::queryDescriptions(
const armem::Time& timestamp)
const
308 armem::client::query::Builder qb;
312 .coreSegments().withName(properties.coreClassSegmentName)
313 .providerSegments().all()
315 .snapshots().beforeTime(timestamp);
318 const armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput());
322 if (not qResult.success)
327 return getRobotDescriptions(qResult.memory);