diff --git a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp index 3678ecd55d64e033e03c1e5f7400db875054cc87..acf354925ab3d4404ae6aee9e455243e3e92a174 100644 --- a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp @@ -76,8 +76,8 @@ namespace armarx ARMARX_IMPORTANT << "Waiting for memory '" << p.usedMemoryName << "' ..."; try { - memoryReader = memoryNameSystem.useReader(p.usedMemoryName); - memoryWriter = memoryNameSystem.useWriter(p.usedMemoryName); + memoryReader = memoryNameSystem().useReader(p.usedMemoryName); + memoryWriter = memoryNameSystem().useWriter(p.usedMemoryName); } catch (const armem::error::CouldNotResolveMemoryServer& e) { @@ -93,12 +93,14 @@ namespace armarx // Subscribe to example_entity updates // Using a lambda: - memoryNameSystem.subscribe(exampleEntityID, [&](const armem::MemoryID & exampleEntityID, const std::vector<armem::MemoryID>& snapshotIDs) + memoryNameSystem().subscribe( + exampleEntityID, + [&](const armem::MemoryID & exampleEntityID, const std::vector<armem::MemoryID>& snapshotIDs) { ARMARX_INFO << "Entity " << exampleEntityID << " was updated by " << snapshotIDs.size() << " snapshots."; }); // Using a member function: - memoryNameSystem.subscribe(exampleEntityID, this, &ExampleMemoryClient::processExampleEntityUpdate); + memoryNameSystem().subscribe(exampleEntityID, this, &ExampleMemoryClient::processExampleEntityUpdate); task = new RunningTask<ExampleMemoryClient>(this, &ExampleMemoryClient::run); diff --git a/source/RobotAPI/components/armem/client/VirtualRobotReaderExampleClient/VirtualRobotReaderExampleClient.cpp b/source/RobotAPI/components/armem/client/VirtualRobotReaderExampleClient/VirtualRobotReaderExampleClient.cpp index 8ab75efc78ddad8492598356df374266947fe515..552f68ac7ea45c24a0041dbedaff43a06c3e2c31 100644 --- a/source/RobotAPI/components/armem/client/VirtualRobotReaderExampleClient/VirtualRobotReaderExampleClient.cpp +++ b/source/RobotAPI/components/armem/client/VirtualRobotReaderExampleClient/VirtualRobotReaderExampleClient.cpp @@ -31,7 +31,7 @@ namespace armarx::robot_state { VirtualRobotReaderExampleClient::VirtualRobotReaderExampleClient() : - virtualRobotReader(this->memoryNameSystem) {} + virtualRobotReader(this->memoryNameSystem()) {} armarx::PropertyDefinitionsPtr VirtualRobotReaderExampleClient::createPropertyDefinitions() { diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp index 879809064b9cdb1429b49925e54ba5765cb534cf..86db9939460d3661a0f358df3f5e41f76f7acf2d 100644 --- a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp +++ b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp @@ -40,7 +40,7 @@ namespace armarx defs->topic(debugObserver); - defs->optional(p.memoryName, "memory.Name", "Name of this memory (server)."); + workingMemory().name() = "Example"; p.core._defaultSegmentsStr = simox::alg::join(p.core.defaultCoreSegments, ", "); defs->optional(p.core._defaultSegmentsStr, "core.DefaultSegments", @@ -60,10 +60,8 @@ namespace armarx void ExampleMemory::onInitComponent() { - this->setMemoryName(p.memoryName); - // Usually, the memory server will specify a number of core segments with a specific aron type. - workingMemory.addCoreSegment("ExampleData", armem::example::ExampleData::toAronType()); + workingMemory().addCoreSegment("ExampleData", armem::example::ExampleData::toAronType()); // For illustration purposes, we add more segments (without types). bool trim = true; @@ -72,7 +70,7 @@ namespace armarx for (const std::string& name : p.core.defaultCoreSegments) { - workingMemory.addCoreSegment(name); + workingMemory().addCoreSegment(name); } } @@ -126,7 +124,7 @@ namespace armarx { // Core segments are locked by MemoryRemoteGui. - tab.memoryGroup = armem::server::MemoryRemoteGui().makeGroupBox(workingMemory); + tab.memoryGroup = armem::server::MemoryRemoteGui().makeGroupBox(workingMemory()); } VBoxLayout root = {tab.memoryGroup, VSpacer()}; diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.h b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.h index 37d20608bea3c0c14cda73332693768899d6ce90..86741dcff79045c02e04c1bf7b7f68df60ccacdc 100644 --- a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.h +++ b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.h @@ -85,8 +85,6 @@ namespace armarx struct Properties { - std::string memoryName = "Example"; - struct CoreSegments { std::vector<std::string> defaultCoreSegments = { "ExampleModality", "ExampleConcept" }; diff --git a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp index 3b17f4fc879dfb49fd1b816f8e4b0e450e3f926f..02a4c51c8c501b28c63e589537b957c0bab7cc7e 100644 --- a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp +++ b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp @@ -29,6 +29,7 @@ #include <RobotAPI/libraries/armem/core/error.h> #include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> + namespace armarx { GeneralPurposeMemory::GeneralPurposeMemory() @@ -38,6 +39,9 @@ namespace armarx armarx::PropertyDefinitionsPtr GeneralPurposeMemory::createPropertyDefinitions() { armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + + workingMemory().name() = "GeneralPurpose"; + return defs; } @@ -50,7 +54,6 @@ namespace armarx void GeneralPurposeMemory::onInitComponent() { - workingMemory.name() = memoryName; } @@ -70,17 +73,11 @@ namespace armarx - // WRITING armem::data::AddSegmentsResult GeneralPurposeMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) { + // Allowing adding core segments. armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, addCoreSegmentOnUsage); return result; } - - armem::data::CommitResult GeneralPurposeMemory::commit(const armem::data::Commit& commit, const Ice::Current&) - { - armem::data::CommitResult result = ComponentPluginUser::commit(commit); - return result; - } } diff --git a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.h b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.h index c91e38d07df966ec61c06653bc7d828358275797..fe0aa7989fbe6108ae7b162777b9746dd77c0e78 100644 --- a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.h +++ b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.h @@ -25,7 +25,6 @@ #include <ArmarXCore/core/Component.h> -#include <ArmarXCore/interface/observers/ObserverInterface.h> #include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> #include <RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h> @@ -50,16 +49,24 @@ namespace armarx virtual public armem::server::ComponentPluginUser { public: + GeneralPurposeMemory(); /// @see armarx::ManagedIceObject::getDefaultName() std::string getDefaultName() const override; + public: - armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) override; - armem::data::CommitResult commit(const armem::data::Commit& commit, const Ice::Current&) override; + + armem::data::AddSegmentsResult + addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) override; + protected: + + /// @see PropertyUser::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + /// @see armarx::ManagedIceObject::onInitComponent() void onInitComponent() override; @@ -72,12 +79,9 @@ namespace armarx /// @see armarx::ManagedIceObject::onExitComponent() void onExitComponent() override; - /// @see PropertyUser::createPropertyDefinitions() - armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; - private: - std::string memoryName = "GeneralPurposeMemory"; + bool addCoreSegmentOnUsage = true; }; diff --git a/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp index 15253dffb3eb8c7e49c114d2a7659627cd797071..f44ee600791e3bfaae64b9c119b458241c4a8ab4 100644 --- a/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp +++ b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.cpp @@ -35,16 +35,17 @@ namespace armarx { armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + workingMemory().name() = "Motion"; + const std::string prefix = "mem."; - defs->optional(memoryName, prefix + "MemoryName", "Name of this memory (server)."); mdbMotions.defineProperties(defs, prefix + "mdbmotions."); return defs; } + MotionMemory::MotionMemory() : - mdbMotions(armem::server::ComponentPluginUser::iceMemory) + mdbMotions(armem::server::ComponentPluginUser::iceAdapter()) { - } @@ -53,23 +54,26 @@ namespace armarx return "MotionMemory"; } + void MotionMemory::onInitComponent() { - this->setMemoryName(memoryName); - mdbMotions.onInit(); } + void MotionMemory::onConnectComponent() { mdbMotions.onConnect(); } + void MotionMemory::onDisconnectComponent() { } + void MotionMemory::onExitComponent() { } + } diff --git a/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h index 0218f010631a8f752985dce148c892bed145f5b3..2363dae593ffe51693cec3cca45ce8eef54b206c 100644 --- a/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h +++ b/source/RobotAPI/components/armem/server/MotionMemory/MotionMemory.h @@ -28,6 +28,7 @@ #include <RobotAPI/libraries/armem_motions/server/MotionDatabase/MDBMotions/Segment.h> + namespace armarx { /** @@ -52,6 +53,7 @@ namespace armarx /// @see armarx::ManagedIceObject::getDefaultName() std::string getDefaultName() const override; + protected: armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; @@ -63,7 +65,6 @@ namespace armarx private: - std::string memoryName = "Motion"; armem::server::motions::mdb::Segment mdbMotions; // TODO: mdt Segment diff --git a/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp index 40ceb2864360a7f9412091a39870c8a51846f015..23a8210166eada153da6fe5542c37676bd61d4a0 100644 --- a/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp +++ b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp @@ -33,7 +33,16 @@ namespace armarx::armem::server::obj { armarx::PropertyDefinitionsPtr defs(new ComponentPropertyDefinitions(getConfigIdentifier())); - // Offer + const std::string prefix = "mem."; + workingMemory().name() = defaultMemoryName; + + classSegment.defineProperties(defs, prefix + "cls."); + instance::SegmentAdapter::defineProperties(defs, prefix + "inst."); + + attachmentSegment.defineProperties(defs, prefix + "attachments."); + + + // Publish defs->topic(debugObserver); // Subscribe @@ -44,25 +53,15 @@ namespace armarx::armem::server::obj defs->defineOptionalProperty<std::string>("cmp.KinematicUnitObserverName", "KinematicUnitObserver", "Name of the kinematic unit observer."); - const std::string prefix = "mem."; - - workingMemory.name() = defaultMemoryName; - defs->optional(workingMemory.name(), prefix + "MemoryName", "Name of this memory server."); - - classSegment.defineProperties(defs, prefix + "cls."); - instance::SegmentAdapter::defineProperties(defs, prefix + "inst."); - - attachmentSegment.defineProperties(defs, prefix + "attachments."); - return defs; } ObjectMemory::ObjectMemory() : server::ComponentPluginUser(), - instance::SegmentAdapter(server::ComponentPluginUser::iceMemory), - classSegment(server::ComponentPluginUser::iceMemory), - attachmentSegment(server::ComponentPluginUser::iceMemory) + instance::SegmentAdapter(server::ComponentPluginUser::iceAdapter()), + classSegment(server::ComponentPluginUser::iceAdapter()), + attachmentSegment(server::ComponentPluginUser::iceAdapter()) { } @@ -80,8 +79,6 @@ namespace armarx::armem::server::obj void ObjectMemory::onInitComponent() { - workingMemory.name() = defaultMemoryName; - const auto initSegmentWithCatch = [&](const std::string & segmentName, const auto&& fn) { try diff --git a/source/RobotAPI/components/armem/server/RobotStateMemory/RobotStateMemory.cpp b/source/RobotAPI/components/armem/server/RobotStateMemory/RobotStateMemory.cpp index 582cf20586d119f1ef232cb32c706bbd1eef1e4e..2b6edb972a904b10b8893c67d4564f286d0ea9dd 100644 --- a/source/RobotAPI/components/armem/server/RobotStateMemory/RobotStateMemory.cpp +++ b/source/RobotAPI/components/armem/server/RobotStateMemory/RobotStateMemory.cpp @@ -44,11 +44,11 @@ namespace armarx::armem::server::robot_state { - RobotStateMemory::RobotStateMemory() - : descriptionSegment(server::ComponentPluginUser::iceMemory), - proprioceptionSegment(server::ComponentPluginUser::iceMemory), - localizationSegment(server::ComponentPluginUser::iceMemory), - commonVisu(descriptionSegment, proprioceptionSegment, localizationSegment) + RobotStateMemory::RobotStateMemory() : + descriptionSegment(server::ComponentPluginUser::iceAdapter()), + proprioceptionSegment(server::ComponentPluginUser::iceAdapter()), + localizationSegment(server::ComponentPluginUser::iceAdapter()), + commonVisu(descriptionSegment, proprioceptionSegment, localizationSegment) { addPlugin(debugObserver); ARMARX_CHECK_NOT_NULL(debugObserver); @@ -69,7 +69,7 @@ namespace armarx::armem::server::robot_state const std::string prefix = "mem."; this->setMemoryName("RobotState"); - defs->optional(workingMemory.name(), prefix + "MemoryName", "Name of this memory server."); + defs->optional(workingMemory().name(), prefix + "MemoryName", "Name of this memory server."); const std::string robotUnitPrefix{sensorValuePrefix}; @@ -158,7 +158,7 @@ namespace armarx::armem::server::robot_state { robotUnit.writer.run( robotUnit.pollFrequency, robotUnit.dataQueue, robotUnit.dataMutex, - iceMemory, localizationSegment + iceAdapter(), localizationSegment ); }, "Robot State Writer"); diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp index 6c86b6afa76fe043b4dea16affb609f7db049caf..2899736c93b1437772dea19f9cd83ce15610f4c2 100644 --- a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp +++ b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp @@ -38,13 +38,19 @@ namespace armarx { + SkillsMemory::SkillsMemory() - = default; + { + } + armarx::PropertyDefinitionsPtr SkillsMemory::createPropertyDefinitions() { armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + workingMemory().name() = "Skills"; + + // Publish defs->topic(debugObserver); @@ -53,9 +59,6 @@ namespace armarx defs->optional(p.statechartTransitionsProviderSegmentName, "TransitionsProviderSegmentName", "Name of the provider segment for statechart transitions."); defs->optional(p.statechartTransitionsTopicName, "tpc.sub.ProfilerListener", "Name of the ProfilerListenerInterface topics to subscribe."); - const std::string prefix = "mem."; - defs->optional(p.memoryName, prefix + "MemoryName", "Name of this memory server."); - return defs; } @@ -68,12 +71,10 @@ namespace armarx void SkillsMemory::onInitComponent() { - workingMemory.name() = p.memoryName; - - { - armarx::armem::server::wm::CoreSegment& c = workingMemory.addCoreSegment(p.statechartCoreSegmentName, armarx::armem::arondto::Statechart::Transition::toAronType()); - c.addProviderSegment("Transitions", armarx::armem::arondto::Statechart::Transition::toAronType()); - } + armarx::armem::server::wm::CoreSegment& c = workingMemory().addCoreSegment( + p.statechartCoreSegmentName, + armarx::armem::arondto::Statechart::Transition::toAronType()); + c.addProviderSegment("Transitions", armarx::armem::arondto::Statechart::Transition::toAronType()); } @@ -132,6 +133,7 @@ namespace armarx [this](const std::vector<StatechartListener::Transition>& transitions, armarx::StatechartListener & source) { + (void) source; // Unused. this->reportTransitions(transitions); }); @@ -150,6 +152,7 @@ namespace armarx return listener; } + void SkillsMemory::reportTransitions(const std::vector<StatechartListener::Transition>& transitions) { @@ -160,7 +163,7 @@ namespace armarx armem::EntityUpdate update; update.entityID = armem::MemoryID() - .withMemoryName(p.memoryName) + .withMemoryName(workingMemory().name()) .withCoreSegmentName(p.statechartCoreSegmentName) .withProviderSegmentName(p.statechartTransitionsProviderSegmentName) .withEntityName(entityName); @@ -172,7 +175,7 @@ namespace armarx try { - workingMemory.update(update); + workingMemory().update(update); } catch (const armem::error::ArMemError& e) { @@ -181,6 +184,7 @@ namespace armarx } } + std::string SkillsMemory::getStatechartName(std::string stateName) { const std::string delimiter = "->"; diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h index ebf0b02c48f90e31b5f93321343b12a66a2723c9..0c64f675160bb12c3937aee8561e58868d8abb28 100644 --- a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h +++ b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h @@ -53,18 +53,22 @@ namespace armarx // , virtual public armarx::ArVizComponentPluginUser { public: + SkillsMemory(); /// @see armarx::ManagedIceObject::getDefaultName() std::string getDefaultName() const override; + // WritingInterface interface public: + armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) override; armem::data::CommitResult commit(const armem::data::Commit& commit, const Ice::Current&) override; protected: + /// @see armarx::ManagedIceObject::onInitComponent() void onInitComponent() override; @@ -82,12 +86,11 @@ namespace armarx private: + DebugObserverInterfacePrx debugObserver; struct Properties { - std::string memoryName = "Skills"; - // Statechart transition logging std::string statechartCoreSegmentName = "Statechart"; std::string statechartTransitionsProviderSegmentName = "Transitions"; @@ -110,5 +113,6 @@ namespace armarx // Gets the statechart name from a state name (takes first two levels of the hierarchy) static std::string getStatechartName(std::string stateName); + }; }