Skip to content
Snippets Groups Projects
Commit 337d018b authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

ltm updates and fixes to grasp memory

parent a519c1e1
Branches dev
No related tags found
No related merge requests found
......@@ -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));
}
}
}
......
......@@ -64,8 +64,6 @@ namespace armarx::armem::server::grasp
DebugObserverInterfacePrx debugObserver;
std::string memoryName = "Grasp";
// segments
armem::grasping::segment::KnownGraspProviderSegment knownGraspProviderSegment;
......
......@@ -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:
......
......@@ -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;
......
......@@ -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)
......
......@@ -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
......
......@@ -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);*/
}
......@@ -45,7 +45,8 @@ namespace armarx::armem::server::plugins
parent().offeringTopic(memoryTopicName);
ARMARX_TRACE;
longtermMemory.init(workingMemory.id());
longtermMemory.setMemoryID(workingMemory.id());
longtermMemory.init();
}
......
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