WorkingMemory.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::WorkingMemory
17 * @author Kai Welke ( welke at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "MissingAttributeFusion.h"
25 #include "WorkingMemory.h"
26 
35 
39 
40 
41 #include <MemoryX/interface/memorytypes/MemorySegments.h>
46 
47 namespace memoryx
48 {
49  const std::string OBJ_INSTANCES_SEGMENT_NAME = "objectInstances";
50  const std::string OBJ_CLASSES_SEGMENT_NAME = "objectClasses";
51  const std::string OBJ_RELATIONS_SEGMENT_NAME = "objectRelations";
52  const std::string ACTIVE_OAC_SEGMENT_NAME = "activeOac";
53  const std::string AGENT_INSTANCES_SEGMENT_NAME = "agentInstances";
54  const std::string WORLD_STATE_SEGMENT_NAME = "worldState";
55  const std::string AFFORDANCE_SEGMENT_NAME = "affordances";
56  const std::string ENVIRONMENTAL_PRIMITIVE_SEGMENT_NAME = "environmentalPrimitives";
57  const std::string DMP_SEGMENT_NAME = "dmpEntity";
58 
59  const std::string OBJ_LOCALIZATION_UPDATER_NAME = "objectLocalization";
60 
62  {
63  }
64 
66  {
67  if (!usePriorMemory)
68  {
69  ARMARX_FATAL << "WorkingMemory will not work when started UsePriorMemory=no";
70  return;
71  }
72 
73  float matchThreshold = getProperty<float>("MatchThreshold").getValue();
74  bool matchByClassName = getProperty<bool>("MatchByClassName").getValue();
75 
76  // create object instances segment
77  ObjectInstanceMemorySegmentPtr objectInstancesSegment = new ObjectInstanceMemorySegment(matchThreshold, matchByClassName);
78  // objectInstancesSegment->addFusionMethod(new MissingAttributeFusion());
79  // objectInstancesSegment->addFusionMethod(new AttributeReplacementFusion());
80  objectInstancesSegment->addFusionMethod(new MotionModelRestoreFusion());
81 
82  bool useKalmanFilter = getProperty<bool>("UseKalmanFilter").getValue();
83 
84  if (useKalmanFilter)
85  {
86  objectInstancesSegment->addFusionMethod(new KalmanFilterFusion());
87  }
88  objectInstancesSegment->addFusionMethod(new PriorAttributeEnrichmentFusion(getPriorKnowledge()));
89 
90 
91  // create object instances segment
92  addSegment(OBJ_INSTANCES_SEGMENT_NAME, objectInstancesSegment);
93 
94  // create object classes segment
96  addSegment(OBJ_CLASSES_SEGMENT_NAME, objectClassesSegment);
97 
98  // create object relations segment
100 
101  // Create agent entities segment.
103 
104  // Create world state segment.
106 
107  // Create affordance segment
109 
110  // Create Environmental Primitive segment
112 
113  if (useLongtermMemory)
114  {
115  // create active oac segment
117  }
118 
119  // create updater required for object localization
120  if (locUpdater)
121  {
122  locUpdater->setSegmentNames(OBJ_CLASSES_SEGMENT_NAME, OBJ_INSTANCES_SEGMENT_NAME);
124  }
125  else
126  {
127  ARMARX_WARNING << "No Location Updater set!";
128  }
129  }
130 
132  {
133  this->locUpdater = updater;
134  }
135 
136  ObjectInstanceMemorySegmentBasePrx WorkingMemory::getObjectInstancesSegment(
137  const ::Ice::Current&)
138  {
139  return ObjectInstanceMemorySegmentBasePrx::uncheckedCast(getSegment(OBJ_INSTANCES_SEGMENT_NAME));
140  }
141 
142  ObjectClassMemorySegmentBasePrx WorkingMemory::getObjectClassesSegment(
143  const ::Ice::Current&)
144  {
145  return ObjectClassMemorySegmentBasePrx::uncheckedCast(getSegment(OBJ_CLASSES_SEGMENT_NAME));
146  }
147 
148  RelationMemorySegmentBasePrx WorkingMemory::getRelationsSegment(
149  const ::Ice::Current&)
150  {
151  return RelationMemorySegmentBasePrx::uncheckedCast(getSegment(OBJ_RELATIONS_SEGMENT_NAME));
152  }
153 
154  ActiveOacMemorySegmentBasePrx WorkingMemory::getActiveOacSegment(
155  const ::Ice::Current&)
156  {
157  return ActiveOacMemorySegmentBasePrx::uncheckedCast(getSegment(ACTIVE_OAC_SEGMENT_NAME));
158  }
159 
160  AgentInstancesSegmentBasePrx WorkingMemory::getAgentInstancesSegment(const Ice::Current&)
161  {
162  return AgentInstancesSegmentBasePrx::uncheckedCast(getSegment(AGENT_INSTANCES_SEGMENT_NAME));
163  }
164 
165  WorldStateSegmentBasePrx WorkingMemory::getWorldStateSegment(const Ice::Current&)
166  {
167  return WorldStateSegmentBasePrx::uncheckedCast(getSegment(WORLD_STATE_SEGMENT_NAME));
168  }
169 
170  AffordanceSegmentBasePrx WorkingMemory::getAffordanceSegment(const Ice::Current&)
171  {
172  return AffordanceSegmentBasePrx::uncheckedCast(getSegment(AFFORDANCE_SEGMENT_NAME));
173  }
174 
175  EnvironmentalPrimitiveSegmentBasePrx WorkingMemory::getEnvironmentalPrimitiveSegment(const Ice::Current&)
176  {
177  return EnvironmentalPrimitiveSegmentBasePrx::uncheckedCast(getSegment(ENVIRONMENTAL_PRIMITIVE_SEGMENT_NAME));
178  }
179 
180  std::string WorkingMemory::getMemoryName(const Ice::Current&) const
181  {
182  return getName();
183  }
184 
185  ObjectLocalizationMemoryUpdaterBasePrx WorkingMemory::getObjectLocalizationUpdater(
186  const ::Ice::Current&)
187  {
188  return ObjectLocalizationMemoryUpdaterBasePrx::uncheckedCast(getUpdater(OBJ_LOCALIZATION_UPDATER_NAME));
189  }
190 
191  CommonStorageInterfacePrx WorkingMemory::getCommonStorage(const ::Ice::Current&) const
192  {
193  return dataBasePrx;
194  }
195 
196  PriorKnowledgeInterfacePrx WorkingMemory::getPriorKnowledge(const ::Ice::Current&) const
197  {
198  return priorKnowledgePrx;
199  }
200 
201  OacMemorySegmentBasePrx WorkingMemory::getOacSegment(const ::Ice::Current&)
202  {
203  return longtermMemoryPrx->getOacSegment();
204  }
205 }
memoryx::OBJ_INSTANCES_SEGMENT_NAME
const std::string OBJ_INSTANCES_SEGMENT_NAME
Definition: WorkingMemory.cpp:49
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:353
memoryx::WorkingMemory::setUpdater
void setUpdater(ObjectLocalizationMemoryUpdaterPtr locUpdater)
Definition: WorkingMemory.cpp:131
memoryx::WorldStateSegment
Definition: WorldStateSegment.h:39
memoryx::WorkingMemory::getObjectLocalizationUpdater
ObjectLocalizationMemoryUpdaterBasePrx getObjectLocalizationUpdater(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:185
ObjectLocalizationMemoryUpdater.h
memoryx::AbstractWorkingMemory::registerUpdater
WorkingMemoryUpdaterBasePrx registerUpdater(const std::string &updaterName, const WorkingMemoryUpdaterBasePtr &updater, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractWorkingMemory.cpp:130
PriorAttributeEnrichmentFusion.h
memoryx::WorkingMemory::getPriorKnowledge
PriorKnowledgeInterfacePrx getPriorKnowledge(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorkingMemory.cpp:196
memoryx::WorkingMemory::getMemoryName
std::string getMemoryName(const Ice::Current &) const override
Definition: WorkingMemory.cpp:180
memoryx::AbstractWorkingMemory::dataBasePrx
CommonStorageInterfacePrx dataBasePrx
Definition: AbstractWorkingMemory.h:135
memoryx::WorkingMemory::getObjectInstancesSegment
ObjectInstanceMemorySegmentBasePrx getObjectInstancesSegment(const ::Ice::Current &=Ice::emptyCurrent) override
getObjectInstancesSegment Get the segment where all object instances are stored.
Definition: WorkingMemory.cpp:136
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
WorldStateSegment.h
memoryx::WorkingMemory::getObjectClassesSegment
ObjectClassMemorySegmentBasePrx getObjectClassesSegment(const ::Ice::Current &=Ice::emptyCurrent) override
getObjectClassesSegment Get the segment where all used object classes are stored.
Definition: WorkingMemory.cpp:142
memoryx::PriorAttributeEnrichmentFusion
Definition: PriorAttributeEnrichmentFusion.h:39
MotionModelRestoreFusion.h
memoryx::ObjectClassMemorySegment
The object class segment is a specialized segment of the SegmentedMemory.
Definition: ObjectClassMemorySegment.h:43
EnvironmentalPrimitiveSegment.h
memoryx::KalmanFilterFusion
Definition: KalmanFilterFusion.h:41
memoryx::RelationMemorySegment
Definition: RelationsMemorySegment.h:33
ARMARX_FATAL
#define ARMARX_FATAL
Definition: Logging.h:192
memoryx::WorkingMemory::getAffordanceSegment
AffordanceSegmentBasePrx getAffordanceSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:170
IceInternal::Handle< ObjectInstanceMemorySegment >
memoryx::WorkingMemory::onInitWorkingMemory
void onInitWorkingMemory() override
Definition: WorkingMemory.cpp:61
ObjectInstanceMemorySegment.h
memoryx::WorkingMemory::getOacSegment
virtual OacMemorySegmentBasePrx getOacSegment(const ::Ice::Current &=Ice::emptyCurrent)
Definition: WorkingMemory.cpp:201
memoryx::AbstractWorkingMemory::priorKnowledgePrx
PriorKnowledgeInterfacePrx priorKnowledgePrx
Definition: AbstractWorkingMemory.h:136
memoryx::AgentInstancesSegment
Definition: AgentInstancesSegment.h:37
memoryx::AbstractWorkingMemory::longtermMemoryPrx
LongtermMemoryInterfacePrx longtermMemoryPrx
Definition: AbstractWorkingMemory.h:137
AgentInstancesSegment.h
memoryx::AbstractWorkingMemory::getUpdater
WorkingMemoryUpdaterBasePrx getUpdater(const std::string &updaterName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractWorkingMemory.cpp:151
memoryx::ENVIRONMENTAL_PRIMITIVE_SEGMENT_NAME
const std::string ENVIRONMENTAL_PRIMITIVE_SEGMENT_NAME
Definition: WorkingMemory.cpp:56
MemoryXCoreObjectFactories.h
AffordanceSegment.h
WorkingMemory.h
memoryx::WorkingMemory::getEnvironmentalPrimitiveSegment
EnvironmentalPrimitiveSegmentBasePrx getEnvironmentalPrimitiveSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:175
memoryx::DMP_SEGMENT_NAME
const std::string DMP_SEGMENT_NAME
Definition: WorkingMemory.cpp:57
memoryx::MotionModelRestoreFusion
Definition: MotionModelRestoreFusion.h:36
memoryx::OBJ_LOCALIZATION_UPDATER_NAME
const std::string OBJ_LOCALIZATION_UPDATER_NAME
Definition: WorkingMemory.cpp:59
memoryx::WorkingMemory::getCommonStorage
CommonStorageInterfacePrx getCommonStorage(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorkingMemory.cpp:191
MissingAttributeFusion.h
memoryx::AFFORDANCE_SEGMENT_NAME
const std::string AFFORDANCE_SEGMENT_NAME
Definition: WorkingMemory.cpp:55
memoryx::OBJ_RELATIONS_SEGMENT_NAME
const std::string OBJ_RELATIONS_SEGMENT_NAME
Definition: WorkingMemory.cpp:51
memoryx::AffordanceSegment
Definition: AffordanceSegment.h:36
ActiveOacMemorySegment.h
memoryx::WorkingMemory::getWorldStateSegment
WorldStateSegmentBasePrx getWorldStateSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:165
memoryx::WorkingMemory::onConnectWorkingMemory
void onConnectWorkingMemory() override
Definition: WorkingMemory.cpp:65
memoryx::OBJ_CLASSES_SEGMENT_NAME
const std::string OBJ_CLASSES_SEGMENT_NAME
Definition: WorkingMemory.cpp:50
RelationsMemorySegment.h
memoryx::WorkingMemory::getAgentInstancesSegment
AgentInstancesSegmentBasePrx getAgentInstancesSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:160
memoryx::WORLD_STATE_SEGMENT_NAME
const std::string WORLD_STATE_SEGMENT_NAME
Definition: WorkingMemory.cpp:54
memoryx::ACTIVE_OAC_SEGMENT_NAME
const std::string ACTIVE_OAC_SEGMENT_NAME
Definition: WorkingMemory.cpp:52
ObjectClassMemorySegment.h
memoryx::WorkingMemory::getActiveOacSegment
ActiveOacMemorySegmentBasePrx getActiveOacSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:154
MemoryXTypesObjectFactories.h
memoryx::AbstractWorkingMemory::addSegment
AbstractMemorySegmentPrx addSegment(const std::string &segmentName, const AbstractMemorySegmentPtr &segment, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractWorkingMemory.cpp:113
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
memoryx::AbstractWorkingMemory::useLongtermMemory
bool useLongtermMemory
Definition: AbstractWorkingMemory.h:145
memoryx::SegmentedMemory::getSegment
AbstractMemorySegmentPrx getSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: SegmentedMemory.cpp:75
memoryx::EnvironmentalPrimitiveSegment
Definition: EnvironmentalPrimitiveSegment.h:36
memoryx::WorkingMemory::getRelationsSegment
RelationMemorySegmentBasePrx getRelationsSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:148
memoryx::ObjectInstanceMemorySegment
Definition: ObjectInstanceMemorySegment.h:43
memoryx::AbstractWorkingMemory::usePriorMemory
bool usePriorMemory
Definition: AbstractWorkingMemory.h:144
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
AttributeReplacementFusion.h
MemoryXUpdaterObjectFactories.h
memoryx::ActiveOacMemorySegment
Definition: ActiveOacMemorySegment.h:37
memoryx::AGENT_INSTANCES_SEGMENT_NAME
const std::string AGENT_INSTANCES_SEGMENT_NAME
Definition: WorkingMemory.cpp:53
KalmanFilterFusion.h