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 "WorkingMemory.h"
24 
25 #include "MissingAttributeFusion.h"
30 #include <MemoryX/interface/memorytypes/MemorySegments.h>
43 
44 namespace memoryx
45 {
46  const std::string OBJ_INSTANCES_SEGMENT_NAME = "objectInstances";
47  const std::string OBJ_CLASSES_SEGMENT_NAME = "objectClasses";
48  const std::string OBJ_RELATIONS_SEGMENT_NAME = "objectRelations";
49  const std::string ACTIVE_OAC_SEGMENT_NAME = "activeOac";
50  const std::string AGENT_INSTANCES_SEGMENT_NAME = "agentInstances";
51  const std::string WORLD_STATE_SEGMENT_NAME = "worldState";
52  const std::string AFFORDANCE_SEGMENT_NAME = "affordances";
53  const std::string ENVIRONMENTAL_PRIMITIVE_SEGMENT_NAME = "environmentalPrimitives";
54  const std::string DMP_SEGMENT_NAME = "dmpEntity";
55 
56  const std::string OBJ_LOCALIZATION_UPDATER_NAME = "objectLocalization";
57 
58  void
60  {
61  }
62 
63  void
65  {
66  if (!usePriorMemory)
67  {
68  ARMARX_FATAL << "WorkingMemory will not work when started UsePriorMemory=no";
69  return;
70  }
71 
72  float matchThreshold = getProperty<float>("MatchThreshold").getValue();
73  bool matchByClassName = getProperty<bool>("MatchByClassName").getValue();
74 
75  // create object instances segment
76  ObjectInstanceMemorySegmentPtr objectInstancesSegment =
77  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(
90 
91 
92  // create object instances segment
93  addSegment(OBJ_INSTANCES_SEGMENT_NAME, objectInstancesSegment);
94 
95  // create object classes segment
96  ObjectClassMemorySegmentPtr objectClassesSegment =
98  addSegment(OBJ_CLASSES_SEGMENT_NAME, objectClassesSegment);
99 
100  // create object relations segment
102 
103  // Create agent entities segment.
105 
106  // Create world state segment.
108 
109  // Create affordance segment
111 
112  // Create Environmental Primitive segment
114 
115  if (useLongtermMemory)
116  {
117  // create active oac segment
120  }
121 
122  // create updater required for object localization
123  if (locUpdater)
124  {
125  locUpdater->setSegmentNames(OBJ_CLASSES_SEGMENT_NAME, OBJ_INSTANCES_SEGMENT_NAME);
127  }
128  else
129  {
130  ARMARX_WARNING << "No Location Updater set!";
131  }
132  }
133 
134  void
136  {
137  this->locUpdater = updater;
138  }
139 
140  ObjectInstanceMemorySegmentBasePrx
142  {
143  return ObjectInstanceMemorySegmentBasePrx::uncheckedCast(
145  }
146 
147  ObjectClassMemorySegmentBasePrx
149  {
150  return ObjectClassMemorySegmentBasePrx::uncheckedCast(getSegment(OBJ_CLASSES_SEGMENT_NAME));
151  }
152 
153  RelationMemorySegmentBasePrx
154  WorkingMemory::getRelationsSegment(const ::Ice::Current&)
155  {
156  return RelationMemorySegmentBasePrx::uncheckedCast(getSegment(OBJ_RELATIONS_SEGMENT_NAME));
157  }
158 
159  ActiveOacMemorySegmentBasePrx
160  WorkingMemory::getActiveOacSegment(const ::Ice::Current&)
161  {
162  return ActiveOacMemorySegmentBasePrx::uncheckedCast(getSegment(ACTIVE_OAC_SEGMENT_NAME));
163  }
164 
165  AgentInstancesSegmentBasePrx
167  {
168  return AgentInstancesSegmentBasePrx::uncheckedCast(
170  }
171 
172  WorldStateSegmentBasePrx
174  {
175  return WorldStateSegmentBasePrx::uncheckedCast(getSegment(WORLD_STATE_SEGMENT_NAME));
176  }
177 
178  AffordanceSegmentBasePrx
180  {
181  return AffordanceSegmentBasePrx::uncheckedCast(getSegment(AFFORDANCE_SEGMENT_NAME));
182  }
183 
184  EnvironmentalPrimitiveSegmentBasePrx
186  {
187  return EnvironmentalPrimitiveSegmentBasePrx::uncheckedCast(
189  }
190 
191  std::string
192  WorkingMemory::getMemoryName(const Ice::Current&) const
193  {
194  return getName();
195  }
196 
197  ObjectLocalizationMemoryUpdaterBasePrx
199  {
200  return ObjectLocalizationMemoryUpdaterBasePrx::uncheckedCast(
202  }
203 
204  CommonStorageInterfacePrx
205  WorkingMemory::getCommonStorage(const ::Ice::Current&) const
206  {
207  return dataBasePrx;
208  }
209 
210  PriorKnowledgeInterfacePrx
211  WorkingMemory::getPriorKnowledge(const ::Ice::Current&) const
212  {
213  return priorKnowledgePrx;
214  }
215 
216  OacMemorySegmentBasePrx
217  WorkingMemory::getOacSegment(const ::Ice::Current&)
218  {
219  return longtermMemoryPrx->getOacSegment();
220  }
221 } // namespace memoryx
memoryx::OBJ_INSTANCES_SEGMENT_NAME
const std::string OBJ_INSTANCES_SEGMENT_NAME
Definition: WorkingMemory.cpp:46
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:366
memoryx::WorkingMemory::setUpdater
void setUpdater(ObjectLocalizationMemoryUpdaterPtr locUpdater)
Definition: WorkingMemory.cpp:135
memoryx::WorldStateSegment
Definition: WorldStateSegment.h:38
memoryx::WorkingMemory::getObjectLocalizationUpdater
ObjectLocalizationMemoryUpdaterBasePrx getObjectLocalizationUpdater(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:198
ObjectLocalizationMemoryUpdater.h
memoryx::AbstractWorkingMemory::registerUpdater
WorkingMemoryUpdaterBasePrx registerUpdater(const std::string &updaterName, const WorkingMemoryUpdaterBasePtr &updater, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractWorkingMemory.cpp:139
PriorAttributeEnrichmentFusion.h
memoryx::WorkingMemory::getPriorKnowledge
PriorKnowledgeInterfacePrx getPriorKnowledge(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorkingMemory.cpp:211
memoryx::WorkingMemory::getMemoryName
std::string getMemoryName(const Ice::Current &) const override
Definition: WorkingMemory.cpp:192
memoryx::AbstractWorkingMemory::dataBasePrx
CommonStorageInterfacePrx dataBasePrx
Definition: AbstractWorkingMemory.h:156
memoryx::WorkingMemory::getObjectInstancesSegment
ObjectInstanceMemorySegmentBasePrx getObjectInstancesSegment(const ::Ice::Current &=Ice::emptyCurrent) override
getObjectInstancesSegment Get the segment where all object instances are stored.
Definition: WorkingMemory.cpp:141
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:148
memoryx::PriorAttributeEnrichmentFusion
Definition: PriorAttributeEnrichmentFusion.h:38
MotionModelRestoreFusion.h
memoryx::ObjectClassMemorySegment
The object class segment is a specialized segment of the SegmentedMemory.
Definition: ObjectClassMemorySegment.h:42
EnvironmentalPrimitiveSegment.h
memoryx::KalmanFilterFusion
Definition: KalmanFilterFusion.h:38
memoryx::RelationMemorySegment
Definition: RelationsMemorySegment.h:33
ARMARX_FATAL
#define ARMARX_FATAL
Definition: Logging.h:199
memoryx::WorkingMemory::getAffordanceSegment
AffordanceSegmentBasePrx getAffordanceSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:179
IceInternal::Handle< ObjectInstanceMemorySegment >
memoryx::WorkingMemory::onInitWorkingMemory
void onInitWorkingMemory() override
Definition: WorkingMemory.cpp:59
ObjectInstanceMemorySegment.h
memoryx::WorkingMemory::getOacSegment
virtual OacMemorySegmentBasePrx getOacSegment(const ::Ice::Current &=Ice::emptyCurrent)
Definition: WorkingMemory.cpp:217
memoryx::AbstractWorkingMemory::priorKnowledgePrx
PriorKnowledgeInterfacePrx priorKnowledgePrx
Definition: AbstractWorkingMemory.h:157
memoryx::AgentInstancesSegment
Definition: AgentInstancesSegment.h:35
memoryx::AbstractWorkingMemory::longtermMemoryPrx
LongtermMemoryInterfacePrx longtermMemoryPrx
Definition: AbstractWorkingMemory.h:158
AgentInstancesSegment.h
memoryx::AbstractWorkingMemory::getUpdater
WorkingMemoryUpdaterBasePrx getUpdater(const std::string &updaterName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractWorkingMemory.cpp:164
memoryx::ENVIRONMENTAL_PRIMITIVE_SEGMENT_NAME
const std::string ENVIRONMENTAL_PRIMITIVE_SEGMENT_NAME
Definition: WorkingMemory.cpp:53
MemoryXCoreObjectFactories.h
AffordanceSegment.h
WorkingMemory.h
memoryx::WorkingMemory::getEnvironmentalPrimitiveSegment
EnvironmentalPrimitiveSegmentBasePrx getEnvironmentalPrimitiveSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:185
memoryx::DMP_SEGMENT_NAME
const std::string DMP_SEGMENT_NAME
Definition: WorkingMemory.cpp:54
memoryx::MotionModelRestoreFusion
Definition: MotionModelRestoreFusion.h:37
memoryx::OBJ_LOCALIZATION_UPDATER_NAME
const std::string OBJ_LOCALIZATION_UPDATER_NAME
Definition: WorkingMemory.cpp:56
memoryx::WorkingMemory::getCommonStorage
CommonStorageInterfacePrx getCommonStorage(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: WorkingMemory.cpp:205
MissingAttributeFusion.h
memoryx::AFFORDANCE_SEGMENT_NAME
const std::string AFFORDANCE_SEGMENT_NAME
Definition: WorkingMemory.cpp:52
memoryx::OBJ_RELATIONS_SEGMENT_NAME
const std::string OBJ_RELATIONS_SEGMENT_NAME
Definition: WorkingMemory.cpp:48
memoryx::AffordanceSegment
Definition: AffordanceSegment.h:35
ActiveOacMemorySegment.h
memoryx::WorkingMemory::getWorldStateSegment
WorldStateSegmentBasePrx getWorldStateSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:173
memoryx::WorkingMemory::onConnectWorkingMemory
void onConnectWorkingMemory() override
Definition: WorkingMemory.cpp:64
memoryx::OBJ_CLASSES_SEGMENT_NAME
const std::string OBJ_CLASSES_SEGMENT_NAME
Definition: WorkingMemory.cpp:47
RelationsMemorySegment.h
memoryx::WorkingMemory::getAgentInstancesSegment
AgentInstancesSegmentBasePrx getAgentInstancesSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:166
memoryx::WORLD_STATE_SEGMENT_NAME
const std::string WORLD_STATE_SEGMENT_NAME
Definition: WorkingMemory.cpp:51
memoryx::ACTIVE_OAC_SEGMENT_NAME
const std::string ACTIVE_OAC_SEGMENT_NAME
Definition: WorkingMemory.cpp:49
ObjectClassMemorySegment.h
memoryx::WorkingMemory::getActiveOacSegment
ActiveOacMemorySegmentBasePrx getActiveOacSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:160
MemoryXTypesObjectFactories.h
memoryx::AbstractWorkingMemory::addSegment
AbstractMemorySegmentPrx addSegment(const std::string &segmentName, const AbstractMemorySegmentPtr &segment, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AbstractWorkingMemory.cpp:118
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
memoryx::AbstractWorkingMemory::useLongtermMemory
bool useLongtermMemory
Definition: AbstractWorkingMemory.h:166
memoryx::SegmentedMemory::getSegment
AbstractMemorySegmentPrx getSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: SegmentedMemory.cpp:81
memoryx::EnvironmentalPrimitiveSegment
Definition: EnvironmentalPrimitiveSegment.h:35
memoryx::WorkingMemory::getRelationsSegment
RelationMemorySegmentBasePrx getRelationsSegment(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemory.cpp:154
memoryx::ObjectInstanceMemorySegment
Definition: ObjectInstanceMemorySegment.h:41
memoryx::AbstractWorkingMemory::usePriorMemory
bool usePriorMemory
Definition: AbstractWorkingMemory.h:165
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
AttributeReplacementFusion.h
MemoryXUpdaterObjectFactories.h
memoryx::ActiveOacMemorySegment
Definition: ActiveOacMemorySegment.h:35
memoryx::AGENT_INSTANCES_SEGMENT_NAME
const std::string AGENT_INSTANCES_SEGMENT_NAME
Definition: WorkingMemory.cpp:50
KalmanFilterFusion.h