29#include <SimoxUtility/algorithm/string/string_tools.h>
39#include <MemoryX/interface/components/LongtermMemoryInterface.h>
40#include <MemoryX/interface/components/WorkingMemoryInterface.h>
41#include <MemoryX/interface/core/EntityBase.h>
50 if (this->workingMemoryController && this->workingMemoryController->getArmarXManager())
52 this->workingMemoryController->getArmarXManager()->removeObjectBlocking(
53 this->workingMemoryController);
59 const memoryx::PriorKnowledgeInterfacePrx& priorKnowledgePrx,
60 const memoryx::WorkingMemoryInterfacePrx& workingMemoryPrx,
61 const std::string& workingMemoryUpdatesTopic,
62 const std::string& objectInstancesSegmentName,
63 const memoryx::LongtermMemoryInterfacePrx& longtermMemoryPrx,
66 this->mainController = mainController;
69 workingMemoryUpdatesTopic,
70 objectInstancesSegmentName,
71 mainController->getMemoryXController());
72 this->longtermMemoryPrx = longtermMemoryPrx;
78 if (snapshotName.empty())
83 if (!simox::alg::starts_with(snapshotName, LONGTERM_SNAPSHOT_PREFIX))
85 snapshotName = std::string(LONGTERM_SNAPSHOT_PREFIX) + snapshotName;
89 this->workingMemoryController->saveSceneInSnapshot(snapshotName, this->longtermMemoryPrx);
96 std::string& snapshotName,
97 const std::vector<std::string>& objectIds)
99 if (snapshotName.empty())
104 if (!simox::alg::starts_with(snapshotName, LONGTERM_SNAPSHOT_PREFIX))
106 snapshotName = std::string(LONGTERM_SNAPSHOT_PREFIX) + snapshotName;
109 bool worked = this->workingMemoryController->saveObjectsInSnapshot(
110 snapshotName, this->longtermMemoryPrx, objectIds);
115std::vector<std::string>
118 std::vector<std::string> addedIds;
120 if (!snapshotName.empty())
124 memoryx::WorkingMemorySnapshotInterfacePrx snapshot =
125 longtermMemoryPrx->getWorkingMemorySnapshotListSegment()->openSnapshot(
127 memoryx::PersistentEntitySegmentBasePrx segObjects =
128 snapshot->getSegment(
"objectInstances");
130 std::vector<memoryx::ObjectInstancePtr> objectInstances;
134 memoryx::EntityIdList ids = segObjects->getAllEntityIds();
136 for (memoryx::EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
139 memoryx::ObjectInstancePtr::dynamicCast(segObjects->getEntityById(*it));
140 objectInstances.push_back(objectInstance);
144 addedIds = this->workingMemoryController->addObjectInstances(objectInstances);
146 catch (
const armarx::LocalException& e)
148 std::cout <<
"SnapshotName could not be loaded: " << snapshotName << std::endl;
158 return workingMemoryController;
161std::shared_ptr<memoryxcontroller::PriorKnowledgeController>
164 return priorKnowledgeController;
170 return mainController.lock();
173std::vector<std::string>
176 return longtermMemoryPrx->getSnapshotNames();
bool saveSceneInSnapshot(std::string &snapshotName)
Saves the whole content of the working memory in a snapshot with the given name.
std::vector< std::string > getAllSnapshots()
Returns a list with the names of all existing snapshots.
void init(const memoryx::PriorKnowledgeInterfacePrx &priorKnowledgePrx, const memoryx::WorkingMemoryInterfacePrx &workingMemoryPrx, const std::string &workingMemoryUpdatesTopic, const std::string &objectInstancesSegmentName, const memoryx::LongtermMemoryInterfacePrx &longtermMemoryPrx, const controller::ControllerPtr &mainController)
Initialisates the MemoryXController.
MemoryXController()
Constructor.
std::vector< std::string > loadSnapshot(const std::string &snapshotName)
Loads the content of the snapshot with the given name and add it to the current working memory.
~MemoryXController()
Destructor.
std::shared_ptr< PriorKnowledgeController > getPriorKnowlegdeController() const
Returns a shared pointer to the PriorKnowledgeController.
IceInternal::Handle< WorkingMemoryController > getWorkingMemoryController() const
Returns a shared pointer to the WorkingMemoryController.
controller::ControllerPtr getController() const
Returns the main controller of this plugin.
bool saveObjectsInSnapshot(std::string &snapshotName, const std::vector< std::string > &objectIds)
Saves all object instances whose ids are given in a snapshot with the given name.
The controller for the communication with the priorknowledge.
The controller for the communication with the working memory.
std::shared_ptr< Controller > ControllerPtr
IceInternal::Handle< ObjectInstance > ObjectInstancePtr