diff --git a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp index 680f19388b0e4846903396ff9e37ea43bbb322e5..deded9bcbcfee433d99146452f9a9425ec7a3797 100644 --- a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp +++ b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp @@ -20,11 +20,12 @@ namespace armarx::armem::server::grasp { armarx::PropertyDefinitionsPtr GraspMemory::createPropertyDefinitions() { + setMemoryName("Grasp"); + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); defs->topic(debugObserver); - defs->optional(memoryName, "memory.Name", "Name of this memory server."); defs->optional(enableRemoteGui, "remoteGui.enable", "Enable/Disable Remote GUI"); defs->optional(gui.trackNewEntities, "EnableTrackingOfNewEntities", "Enable/Disable the automatic visual tracking of newly commited Entities"); return defs; @@ -43,8 +44,6 @@ namespace armarx::armem::server::grasp void GraspMemory::onInitComponent() { - workingMemory().name() = memoryName; - workingMemory().addCoreSegment("GraspCandidate", armarx::grasping::arondto::GraspCandidate::ToAronType()); workingMemory().addCoreSegment("BimanualGraspCandidate", @@ -464,7 +463,7 @@ namespace armarx::armem::server::grasp } else { - providers.push_back(MemoryID(memoryName, gui.coreSegment, gui.provider)); + providers.push_back(MemoryID(workingMemory().name(), gui.coreSegment, gui.provider)); } for (MemoryID & provider : providers) @@ -514,7 +513,7 @@ namespace armarx::armem::server::grasp { if (workingMemory().getProviderSegment(provider).hasEntity(gui.entity)) { - entities.push_back(MemoryID(memoryName, gui.coreSegment, provider.providerSegmentName, gui.entity)); + entities.push_back(MemoryID(workingMemory().name(), gui.coreSegment, provider.providerSegmentName, gui.entity)); } } } diff --git a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h index 00dcaa1f4335a84c1cb8ad97170c334e7d7838be..20e0055141b0d679455c77b290b661da68fdf227 100644 --- a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h +++ b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h @@ -64,8 +64,6 @@ namespace armarx::armem::server::grasp DebugObserverInterfacePrx debugObserver; - std::string memoryName = "Grasp"; - // segments armem::grasping::segment::KnownGraspProviderSegment knownGraspProviderSegment; diff --git a/source/RobotAPI/libraries/armem/server/ltm/base/detail/BufferedMemoryBase.h b/source/RobotAPI/libraries/armem/server/ltm/base/detail/BufferedMemoryBase.h index f61b4451d54b34b3aa0ddc330462a5ca884577f1..1104da67e9c19488daa3cc4d508a4355095d1704 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/base/detail/BufferedMemoryBase.h +++ b/source/RobotAPI/libraries/armem/server/ltm/base/detail/BufferedMemoryBase.h @@ -12,23 +12,18 @@ namespace armarx::armem::server::ltm using Base = MemoryBase<_CoreSegmentT>; public: - BufferedMemoryBase() : - BufferedMemoryBase({}) - { - } - BufferedMemoryBase(const MemoryID& id) : - Base(id) + Base(id), + buffer(std::make_shared<armem::wm::Memory>(id)), + to_store(std::make_shared<armem::wm::Memory>(id)) { - buffer = std::make_shared<armem::wm::Memory>(id); - to_store = std::make_shared<armem::wm::Memory>(id); } virtual ~BufferedMemoryBase() = default; void setMemoryID(const MemoryID& id) override { - ARMARX_CHECK_NOT_EMPTY(id.memoryName); + ARMARX_CHECK_NOT_EMPTY(id.memoryName) << " The full id was: " << id.str(); Base::setMemoryID(id.getMemoryID()); @@ -76,8 +71,13 @@ namespace armarx::armem::server::ltm } /// configuration - virtual void configure() + void configure(const nlohmann::json& json) override { + Base::configure(json); + if (json.find("BufferedMemoryBase.storeFrequency") != json.end()) + { + storeFrequency = json.at("BufferedMemoryBase.storeFrequency"); + } } protected: diff --git a/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h b/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h index 97049d88999a24f7ad10c9e41f58792f7e462181..bec7576234c8f6bbc9064745f2d0cdc0f8ef333b 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h +++ b/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h @@ -35,26 +35,14 @@ namespace armarx::armem::server::ltm public: using CoreSegmentT = _CoreSegmentT; - MemoryBase() : - MemoryBase({}) - { - } - MemoryBase(const MemoryID& id) : MemoryItem(id) { } /// initialize config - void init() + virtual void init() { - // init without changing the memory id - init(this->id()); - } - void init(const armem::MemoryID& wmMemoryId) - { - setMemoryID(wmMemoryId); - enabled = enabled_on_startup; ARMARX_INFO << VAROUT(configuration_on_startup); @@ -62,7 +50,8 @@ namespace armarx::armem::server::ltm { const auto j = nlohmann::json::parse(configuration_on_startup); this->configure(j); - }catch(...) + } + catch(...) { ARMARX_WARNING << "Failed to parse `" << configuration_on_startup << "`"; enabled = false; @@ -139,7 +128,7 @@ namespace armarx::armem::server::ltm /// find core segment virtual std::shared_ptr<CoreSegmentT> findCoreSegment(const std::string&) const = 0; - /// parameters + /// default parameters. Implementation should use the configuration to configure virtual void createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix) { defs->optional(enabled_on_startup, prefix + "enabled"); @@ -195,7 +184,7 @@ namespace armarx::armem::server::ltm public: // stuff for scenario parameters bool enabled_on_startup = false; - std::string configuration_on_startup = ""; + std::string configuration_on_startup = "{}"; protected: mutable std::recursive_mutex ltm_mutex; diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.cpp b/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.cpp index 0a85e4ac5c0b019d201fe9c633476f7c45cd81cd..bc71c50fc07094c3b27a914c8d0af55c0d135810 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.cpp @@ -7,11 +7,17 @@ namespace armarx::armem::server::ltm::disk { - void Memory::createPropertyDefinitions(PropertyDefinitionsPtr& properties, const std::string& prefix) + void Memory::configure(const nlohmann::json& json) { - Base::createPropertyDefinitions(properties, prefix); - properties->optional(memoryParentPath, prefix + "storagepath", "The path to the memory storage (the memory will be stored in a seperate subfolder)."); - properties->optional(sizeToCompressDataInMegaBytes, prefix + "sizeToCompressDataInMegaBytes", "The size in MB to compress away the current export. Exports are numbered (lower number means newer)."); + Base::configure(json); + if (json.find("Memory.memoryParentPath") != json.end()) + { + memoryParentPath = std::filesystem::path(json.at("Memory.memoryParentPath")); + } + if (json.find("Memory.sizeToCompressDataInMegaBytes") != json.end()) + { + sizeToCompressDataInMegaBytes = json.at("Memory.sizeToCompressDataInMegaBytes"); + } } Memory::Memory() : @@ -22,21 +28,18 @@ namespace armarx::armem::server::ltm::disk Memory::Memory(const std::filesystem::path& p, const std::string& memoryName /* UNESCAPED */, const MemoryEncodingMode defaultEncodingMode) : Base(MemoryID(memoryName, "")), DiskMemoryItem(p, EscapeSegmentName(memoryName), ""), - exportEncodingMode(defaultEncodingMode) + defaultExportEncodingMode(defaultEncodingMode) { - setMemoryID(MemoryID(memoryName, "")); // set Memory id and search for old exports } - void Memory::setMemoryID(const MemoryID& id) + void Memory::init() { - ARMARX_CHECK_NOT_EMPTY(id.memoryName); - Base::setMemoryID(id.getMemoryID()); - escapedMemoryName = EscapeSegmentName(id.memoryName); + Base::init(); // Discover how many exports already exists for (unsigned long i = 1; i < 10000; ++i) { - std::filesystem::path exportPath = getMemoryBasePathForMode(exportEncodingMode, i); + std::filesystem::path exportPath = getMemoryBasePathForMode(defaultExportEncodingMode, i); if (!std::filesystem::exists(exportPath)) { break; @@ -44,12 +47,18 @@ namespace armarx::armem::server::ltm::disk maxExportIndex = i; } } + void Memory::setMemoryID(const MemoryID& id) + { + Base::setMemoryID(id); + + escapedMemoryName = EscapeSegmentName(id.memoryName); + } bool Memory::forEachCoreSegment(std::function<void(CoreSegment&)>&& func) const { for (unsigned long i = 0; i <= maxExportIndex; ++i) { - MemoryEncodingMode mode = i == 0 ? MemoryEncodingMode::FILESYSTEM : exportEncodingMode; + MemoryEncodingMode mode = i == 0 ? MemoryEncodingMode::FILESYSTEM : defaultExportEncodingMode; auto mPath = getMemoryBasePathForMode(mode, i); if (util::checkIfBasePathExists(mPath)) { @@ -69,7 +78,7 @@ namespace armarx::armem::server::ltm::disk { for (unsigned long i = 0; i <= maxExportIndex; ++i) { - MemoryEncodingMode mode = i == 0 ? MemoryEncodingMode::FILESYSTEM : exportEncodingMode; + MemoryEncodingMode mode = i == 0 ? MemoryEncodingMode::FILESYSTEM : defaultExportEncodingMode; auto mPath = getMemoryBasePathForMode(mode, i); if (!util::checkIfBasePathExists(mPath)) @@ -105,7 +114,7 @@ namespace armarx::armem::server::ltm::disk for (unsigned long i = 0; i <= maxExportIndex; ++i) { - MemoryEncodingMode mode = i == 0 ? MemoryEncodingMode::FILESYSTEM : exportEncodingMode; + MemoryEncodingMode mode = i == 0 ? MemoryEncodingMode::FILESYSTEM : defaultExportEncodingMode; auto mPath = getMemoryBasePathForMode(mode, i); if (!util::checkIfBasePathExists(mPath)) @@ -129,7 +138,7 @@ namespace armarx::armem::server::ltm::disk std::lock_guard l(ltm_mutex); // we cannot store a memory multiple times simultaneously MemoryEncodingMode defaultMode = MemoryEncodingMode::FILESYSTEM; - MemoryEncodingMode encodeModeOfPast = exportEncodingMode; + MemoryEncodingMode encodeModeOfPast = defaultExportEncodingMode; // Storage will always be in filesystem mode! // Somehow, minizip was not able to write data to images. It always created a folder named xyz.png without any data in it... // Another problem is that storing data directly in compressed format will require a lot of time when the compressed file is big (>20MB) diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.h b/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.h index 085a56459efd9118d1c9afa4f7bd85f64f6ba38f..e2f8d4f14ea47c4498cb96a0a0098cfb0c040fde 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.h +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/Memory.h @@ -23,20 +23,21 @@ namespace armarx::armem::server::ltm::disk Memory(); Memory(const std::filesystem::path&, const std::string&, const MemoryEncodingMode defaultEncodingMode = MemoryEncodingMode::MINIZIP); - void setMemoryID(const MemoryID& id) override; + void init() final; + void setMemoryID(const MemoryID& id) final; - void createPropertyDefinitions(PropertyDefinitionsPtr& properties, const std::string& prefix) override; + void configure(const nlohmann::json& config) final; - bool forEachCoreSegment(std::function<void(CoreSegment&)>&& func) const override; - std::shared_ptr<CoreSegment> findCoreSegment(const std::string& coreSegmentName) const override; + bool forEachCoreSegment(std::function<void(CoreSegment&)>&& func) const final; + std::shared_ptr<CoreSegment> findCoreSegment(const std::string& coreSegmentName) const final; protected: - void _loadAllReferences(armem::wm::Memory&) override; - void _resolve(armem::wm::Memory&) override; - void _directlyStore(const armem::wm::Memory&) override; + void _loadAllReferences(armem::wm::Memory&) final; + void _resolve(armem::wm::Memory&) final; + void _directlyStore(const armem::wm::Memory&) final; private: - MemoryEncodingMode exportEncodingMode = MemoryEncodingMode::MINIZIP; + MemoryEncodingMode defaultExportEncodingMode = MemoryEncodingMode::MINIZIP; unsigned long maxExportIndex = 0; unsigned long sizeToCompressDataInMegaBytes = long(1) * 1024; // 1GB diff --git a/source/RobotAPI/libraries/armem/server/ltm/io/Recording.h b/source/RobotAPI/libraries/armem/server/ltm/io/Recording.h index 3d1def0b1c8803f772bf23a8863f62a4adc86704..1bdd4d0586c3bafc7806852868380ecd30692be3 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/io/Recording.h +++ b/source/RobotAPI/libraries/armem/server/ltm/io/Recording.h @@ -105,19 +105,4 @@ namespace armarx::armem::server::ltm }; void toIce(dto::RecordStatusResult& ice, const RecordStatusResult& input); void fromIce(const dto::RecordStatusResult& ice, RecordStatusResult& input); - - - - /* =========================== - * GetServerStructureResult - * =========================== - struct GetServerStructureResult : public detail::SuccessHeader - { - armem::wm::Memory serverStructure; - - static GetServerStructureResult fromIce(const dto::GetServerStructureResult& ice); - dto::GetServerStructureResult toIce() const; - }; - void toIce(dto::GetServerStructureResult& ice, const GetServerStructureResult& input); - void fromIce(const dto::GetServerStructureResult& ice, GetServerStructureResult& input);*/ } diff --git a/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp b/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp index a7ce55ca1fd4a857d8d3bddac0fbf7a0308e2962..a0e13eddbea2173dffcc1db69d9e1ff55c55bc99 100644 --- a/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp +++ b/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp @@ -45,7 +45,8 @@ namespace armarx::armem::server::plugins parent().offeringTopic(memoryTopicName); ARMARX_TRACE; - longtermMemory.init(workingMemory.id()); + longtermMemory.setMemoryID(workingMemory.id()); + longtermMemory.init(); }