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>
18 #include <RobotAPI/libraries/armem_robot_state/aron/Robot.aron.generated.h>
19 #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);
78 memoryNameSystem.
subscribe(
id,
this, &Writer::updateKnownObjects);
84 arondto::RobotDescription aronArticulatedObjectDescription;
92 const std::vector<armem::MemoryID>& snapshotIDs)
99 Writer::updateKnownObjects()
101 knownObjects = queryDescriptions(
Time::Now());
103 ARMARX_INFO <<
"Known articulated objects " << simox::alg::get_keys(knownObjects);
106 std::optional<armem::MemoryID>
111 const auto objectId = knownObjects.find(obj.description.name);
114 if (objectId != knownObjects.end())
116 return objectId->second;
121 throw LocalException(
"articulated object class " + obj.description.name +
" not found");
124 if (properties.allowClassCreation)
132 std::optional<armem::MemoryID>
135 std::lock_guard g{memoryWriterMutex};
137 ARMARX_DEBUG <<
"Trying to create core segment + provider segment";
141 memoryWriter.
addSegment(properties.coreClassSegmentName, properties.providerName);
143 if (not result.success)
145 ARMARX_ERROR <<
"Creating core segment failed. Reason: " << result.errorMessage;
152 const auto entityID =
153 providerId.withEntityName(obj.
description.
name).withTimestamp(timestamp);
156 update.entityID = entityID;
158 arondto::RobotDescription aronArticulatedObjectDescription;
161 update.instancesData = {aronArticulatedObjectDescription.toAron()};
162 update.referencedTime = timestamp;
169 if (not updateResult.success)
178 return updateResult.snapshotID;
184 return properties.providerName;
190 this->properties.providerName = providerName;
196 std::lock_guard g{memoryWriterMutex};
203 ARMARX_DEBUG <<
"Storing articulated object instance '" << entityName <<
"' (provider '"
204 << properties.providerName <<
"')";
212 update.entityID = providerId.withEntityName(entityName);
218 arondto::ObjectInstance objectInstance;
221 const auto classId = storeOrGetClass(obj);
230 toAron(objectInstance.classID, *classId);
240 cs.dataset = objectId.
dataset();
242 objectInstance.pose.objectID = cs;
243 objectInstance.pose.providerName = properties.providerName;
244 objectInstance.pose.attachmentValid =
false;
246 update.instancesData = {objectInstance.toAron()};
247 update.referencedTime = timestamp;
254 if (not updateResult.success)
259 return updateResult.success;
265 const std::optional<armem::MemoryID> classId = storeOrGetClass(obj);
270 <<
"Known classes are " << simox::alg::get_keys(knownObjects);
278 std::optional<robot_state::description::RobotDescription>
283 .getCoreSegment(properties.coreClassSegmentName)
284 .getProviderSegment(properties.providerName);
298 std::unordered_map<std::string, armem::MemoryID>
301 const armem::wm::CoreSegment& coreSegment =
304 std::unordered_map<std::string, armem::MemoryID> descriptions;
305 coreSegment.forEachEntity(
306 [&descriptions](
const wm::Entity& entity)
310 ARMARX_WARNING <<
"No entity found";
317 const armem::MemoryID snapshotID(sn.id());
318 descriptions.insert({robotDescription->name, snapshotID});
326 std::unordered_map<std::string, armem::MemoryID>
327 Writer::queryDescriptions(
const armem::Time& timestamp)
330 armem::client::query::Builder qb;
334 .coreSegments().withName(properties.coreClassSegmentName)
335 .providerSegments().all()
337 .snapshots().latest();
340 const armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput());
344 if (not qResult.success)
349 return getRobotDescriptions(qResult.memory);