From a9bff1489047550e9b5e078485f5f9cbcd440493 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Mon, 30 Aug 2021 09:20:56 +0200 Subject: [PATCH] Update usages --- .../ExampleMemoryClient.cpp | 10 ++++--- .../VirtualRobotReaderExampleClient.cpp | 2 +- .../server/ExampleMemory/ExampleMemory.cpp | 10 +++---- .../server/ExampleMemory/ExampleMemory.h | 2 -- .../GeneralPurposeMemory.cpp | 13 ++++----- .../GeneralPurposeMemory.h | 18 +++++++----- .../server/MotionMemory/MotionMemory.cpp | 14 +++++---- .../armem/server/MotionMemory/MotionMemory.h | 3 +- .../server/ObjectMemory/ObjectMemory.cpp | 29 +++++++++---------- .../RobotStateMemory/RobotStateMemory.cpp | 14 ++++----- .../server/SkillsMemory/SkillsMemory.cpp | 28 ++++++++++-------- .../armem/server/SkillsMemory/SkillsMemory.h | 8 +++-- 12 files changed, 80 insertions(+), 71 deletions(-) diff --git a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp index 3678ecd55..acf354925 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 8ab75efc7..552f68ac7 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 879809064..86db99394 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 37d20608b..86741dcff 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 3b17f4fc8..02a4c51c8 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 c91e38d07..fe0aa7989 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 15253dffb..f44ee6007 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 0218f0106..2363dae59 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 40ceb2864..23a821016 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 582cf2058..2b6edb972 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 6c86b6afa..2899736c9 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 ebf0b02c4..0c64f6751 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); + }; } -- GitLab