Skip to content
Snippets Groups Projects
Commit 6559dca3 authored by Patrick Hegemann's avatar Patrick Hegemann
Browse files

Move statechart memory to SkillsMemory and get it working

parent 77eca533
No related branches found
No related tags found
2 merge requests!157armem/dev => master,!142Statechart memory in the SkillsMemory
......@@ -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;
}
}
......@@ -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);
};
}
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