Skip to content
Snippets Groups Projects
Commit 4898f796 authored by Fabian Reister's avatar Fabian Reister
Browse files

simplifying impl and removing memory subscription

parent 500c879f
No related branches found
No related tags found
1 merge request!518Resolve "articulated_object reader: fixing faulty memory subscription"
Pipeline #22427 failed
...@@ -68,46 +68,18 @@ namespace armarx::armem::articulated_object ...@@ -68,46 +68,18 @@ namespace armarx::armem::articulated_object
const auto resultCoreInstanceSegmentName = const auto resultCoreInstanceSegmentName =
memoryWriter.addSegment(properties.coreInstanceSegmentName, properties.providerName); memoryWriter.addSegment(properties.coreInstanceSegmentName, properties.providerName);
armem::MemoryID refId = armem::MemoryID(resultCoreClassSegment.segmentID);
armem::MemoryID id;
id.setCoreSegmentID(refId); // listen to all provider segments!
updateKnownObjects();
memoryNameSystem.subscribe(id, this, &Writer::updateKnownObjects);
}
void
Writer::updateKnownObject(const armem::MemoryID& snapshotId)
{
arondto::RobotDescription aronArticulatedObjectDescription;
// aronArticulatedObjectDescription.fromAron(snapshotId.ent);
// TODO(fabian.reister): implement
} }
void
Writer::updateKnownObjects(const armem::MemoryID& subscriptionID,
const std::vector<armem::MemoryID>& snapshotIDs)
{
ARMARX_INFO << "New objects available!";
updateKnownObjects();
}
void
Writer::updateKnownObjects()
{
knownObjects = queryDescriptions(Time::Now());
ARMARX_INFO << "Known articulated objects " << simox::alg::get_keys(knownObjects);
}
std::optional<armem::MemoryID> std::optional<armem::MemoryID>
Writer::storeOrGetClass(const ArticulatedObject& obj) const Writer::storeOrGetClass(const ArticulatedObject& obj) const
{ {
ARMARX_TRACE; ARMARX_TRACE;
// key: name of object: RobotDescription::name
const std::unordered_map<std::string, MemoryID> knownObjects = queryDescriptions(Time::Now());
ARMARX_VERBOSE << "Known articulated objects " << simox::alg::get_keys(knownObjects);
const auto objectId = knownObjects.find(obj.description.name); const auto objectId = knownObjects.find(obj.description.name);
// check if exists // check if exists
...@@ -172,9 +144,6 @@ namespace armarx::armem::articulated_object ...@@ -172,9 +144,6 @@ namespace armarx::armem::articulated_object
return std::nullopt; return std::nullopt;
} }
// update cache (TODO: likely remove this)
knownObjects[obj.description.name] = updateResult.snapshotID;
return updateResult.snapshotID; return updateResult.snapshotID;
} }
...@@ -276,7 +245,7 @@ namespace armarx::armem::articulated_object ...@@ -276,7 +245,7 @@ namespace armarx::armem::articulated_object
if (not classId) if (not classId)
{ {
ARMARX_WARNING << "Could not get class id for object " << obj.description.name << "! " ARMARX_WARNING << "Could not get class id for object " << obj.description.name << "! "
<< "Known classes are " << simox::alg::get_keys(knownObjects); << "Known classes are " << simox::alg::get_keys(queryDescriptions(Time::Now()));
return false; return false;
} }
...@@ -333,7 +302,7 @@ namespace armarx::armem::articulated_object ...@@ -333,7 +302,7 @@ namespace armarx::armem::articulated_object
} }
std::unordered_map<std::string, armem::MemoryID> std::unordered_map<std::string, armem::MemoryID>
Writer::queryDescriptions(const armem::Time& timestamp) Writer::queryDescriptions(const armem::Time& timestamp) const
{ {
// Query all entities from provider. // Query all entities from provider.
armem::client::query::Builder qb; armem::client::query::Builder qb;
...@@ -343,7 +312,7 @@ namespace armarx::armem::articulated_object ...@@ -343,7 +312,7 @@ namespace armarx::armem::articulated_object
.coreSegments().withName(properties.coreClassSegmentName) .coreSegments().withName(properties.coreClassSegmentName)
.providerSegments().all() .providerSegments().all()
.entities().all() .entities().all()
.snapshots().latest(); // TODO beforeTime(timestamp); .snapshots().beforeTime(timestamp);
// clang-format on // clang-format on
const armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput()); const armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput());
......
...@@ -59,14 +59,9 @@ namespace armarx::armem::articulated_object ...@@ -59,14 +59,9 @@ namespace armarx::armem::articulated_object
private: private:
std::optional<armem::MemoryID> storeOrGetClass(const ArticulatedObject& obj) const; std::optional<armem::MemoryID> storeOrGetClass(const ArticulatedObject& obj) const;
void updateKnownObjects(const armem::MemoryID& subscriptionID,
const std::vector<armem::MemoryID>& snapshotIDs);
void updateKnownObjects();
void updateKnownObject(const armem::MemoryID& snapshotId);
// TODO duplicate // TODO duplicate
std::unordered_map<std::string, armem::MemoryID> std::unordered_map<std::string, armem::MemoryID>
queryDescriptions(const armem::Time& timestamp); queryDescriptions(const armem::Time& timestamp) const;
std::optional<robot_state::description::RobotDescription> std::optional<robot_state::description::RobotDescription>
getRobotDescription(const armarx::armem::wm::Memory& memory) const; getRobotDescription(const armarx::armem::wm::Memory& memory) const;
std::unordered_map<std::string, armem::MemoryID> std::unordered_map<std::string, armem::MemoryID>
...@@ -89,9 +84,6 @@ namespace armarx::armem::articulated_object ...@@ -89,9 +84,6 @@ namespace armarx::armem::articulated_object
armem::client::Reader memoryReader; armem::client::Reader memoryReader;
mutable std::mutex memoryReaderMutex; mutable std::mutex memoryReaderMutex;
// key: name of object: RobotDescription::name
mutable std::unordered_map<std::string, MemoryID> knownObjects;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment