diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp index dfbd682a8694e65480459d51c2689c13be3c8506..15f2a5e83f48171e4c5d3f8bc364dc196f031ca2 100644 --- a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp +++ b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp @@ -27,8 +27,6 @@ #include <ArmarXCore/core/exceptions/local/ExpressionException.h> #include <ArmarXCore/core/time/TimeUtil.h> -//#include <SimoxUtility/algorithm/string.h> - #include <RobotAPI/libraries/armem/core/error.h> #include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> @@ -46,8 +44,6 @@ namespace armarx defs->topic(debugObserver); // Subscribe - // defs->defineOptionalProperty("tpc.sub.ProfilerListener", p.statechartTransitionsTopicName, - // "Name of the ProfilerListenerInterface topics to subscribe."); defs->optional(p.statechartTransitionsTopicName, "tpc.sub.ProfilerListener", "Name of the ProfilerListenerInterface topics to subscribe."); const std::string prefix = "mem."; @@ -67,12 +63,9 @@ namespace armarx { workingMemory.name() = p.memoryName; - // getProperty(p.statechartTransitionsTopicName, "tpc.sub.StatechartListener"); - { - armem::data::CoreSegment& core = workingMemory.addCoreSegment("Statechart"); - workingMemory. - // statechartTransitionsProviderSegmentID = core.p ("Transitions",armarx::statechart::aron::Transition::toInitialAronType()).id(); + armarx::armem::wm::CoreSegment& c = workingMemory.addCoreSegment(statechartCoreSegmentName, armarx::statechart::aron::Transition::toInitialAronType()); + c.addProviderSegment("Transitions", armarx::statechart::aron::Transition::toInitialAronType()); } } @@ -155,13 +148,18 @@ namespace armarx { for (const StatechartListener::Transition& t : transitions) { - const std::string& entityName = std::to_string(t.processId); + const std::string& entityName = getStatechartName(t.targetStateIdentifier); IceUtil::Time transitionTime = IceUtil::Time::microSeconds(t.timestamp); armem::EntityUpdate update; - update.entityID = statechartTransitionsProviderSegmentID.withEntityName(entityName); - update.timeCreated = transitionTime; + update.entityID = armem::MemoryID() + .withMemoryName(p.memoryName) + .withCoreSegmentName(statechartCoreSegmentName) + .withProviderSegmentName(statechartTransitionsProviderSegmentName) + .withEntityName(entityName); + ARMARX_INFO << "update.entityId = " << update.entityID; + update.timeCreated = transitionTime; armarx::statechart::aron::Transition data; data.processId = t.processId; @@ -186,7 +184,7 @@ namespace armarx } } - std::shared_ptr<armarx::statechart::aron::ParameterMap> SkillsMemory::toParameterMap(const armarx::StateParameterMap& map) + std::shared_ptr<armarx::statechart::aron::ParameterMap> SkillsMemory::toAronParameterMap(const armarx::StateParameterMap& map) { std::shared_ptr<armarx::statechart::aron::ParameterMap> aronMap(new armarx::statechart::aron::ParameterMap); for (auto const& [key, val] : map) @@ -195,4 +193,26 @@ namespace armarx } return aronMap; } + + std::string SkillsMemory::getStatechartName(std::string stateName) + { + const std::string delimiter = "->"; + const int maxLevels = 2; + + size_t pos; + int levels = 0; + std::string statechartName; + while ((pos = stateName.find(delimiter)) != std::string::npos && levels < maxLevels) + { + if (levels != 0) + { + statechartName += delimiter; + } + statechartName += stateName.substr(0, pos); + stateName.erase(0, pos + delimiter.length()); + levels++; + } + + return statechartName; + } } diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h index cb1acff6ffd4945e2ab1bb866aa0d5d33b9ea2a9..43ff19e38a108fb15503c9f75cde991ef996565f 100644 --- a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h +++ b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h @@ -93,7 +93,6 @@ namespace armarx struct CoreSegments { - // std::vector<std::string> defaultCoreSegments = { "Transitions" }; bool addOnUsage = false; }; CoreSegments core; @@ -101,14 +100,15 @@ namespace armarx Properties p; // Statechart transition logging - armem::MemoryID statechartTransitionsProviderSegmentID; + const std::string statechartCoreSegmentName = "Statechart"; + const std::string statechartTransitionsProviderSegmentName = "Transitions"; IceInternal::Handle<StatechartListener> createStatechartListener(const std::string& topicName, const std::string& _name = ""); - IceInternal::Handle<armarx::StatechartListener> statechartListener; void reportTransitions(const std::vector<StatechartListener::Transition>& transitions); + // Converts an armarx::eStateType to the corresponding aron enum value std::map<armarx::eStateType, armarx::statechart::aron::StateType> toAronStateEnum = { {eNormalState, armarx::statechart::aron::StateType::NORMAL}, @@ -117,6 +117,9 @@ namespace armarx {eDynamicRemoteState, armarx::statechart::aron::StateType::DYNAMIC_REMOTE}, {eUndefined, armarx::statechart::aron::StateType::UNDEFINED}, }; + // Converts an armarx::StateParameterMap to aron static std::shared_ptr<armarx::statechart::aron::ParameterMap> toAronParameterMap(const armarx::StateParameterMap&); + // Gets the statechart name from a state name (takes first two levels of the hierarchy) + static std::string getStatechartName(std::string stateName); }; }