ObjectMemoryObserver.h
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::Observers
17 * @author Kai Welke (welke at kit dot edu), David Schiebener (david dot schiebener at kit dot edu)
18 * @copyright 2012 Humanoids Group, HIS, KIT
19 * @license http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 #pragma once
23 
24 // core
25 #include <ArmarXCore/interface/observers/ObserverInterface.h>
28 #include <ArmarXCore/interface/observers/VariantBase.h>
32 
33 // memory interface
34 #include <MemoryX/interface/workingmemory/AbstractWorkingMemoryInterface.h>
35 #include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
36 #include <MemoryX/interface/memorytypes/MemorySegments.h>
37 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
38 
39 // memoryx
43 
44 #include <string>
45 #include <mutex>
46 
47 
48 namespace memoryx
49 {
50 
51 
54  {
55  public:
58  {
59  defineOptionalProperty<std::string>("WorkingMemoryListenerTopic", "WorkingMemoryUpdates", "Topic for working memory updates");
60  defineOptionalProperty<std::string>("WorkingMemoryProxy", "WorkingMemory", "Proxy of working memory");
61  defineOptionalProperty<std::string>("PriorKnowledgeProxy", "PriorKnowledge", "Proxy of PriorKnowledge");
62  }
63  };
64 
65  /**
66  * VisionX ObjectMemoryObserver.
67  *
68  * The ObjectMemoryObserver allows installing conditions on all known objects.
69  * It receives reports from the ObjectMemory about those objects which are being localized.
70  *
71  * It offers a channel for every known object that contains information about the object
72  * pose, if it has been found and how certain the localization is.
73  *
74  * It also offers a channel that contains the names of all objects which have been localized
75  * successfully.
76  *
77  */
79  virtual public armarx::Observer,
80  virtual public ObjectMemoryObserverInterface
81  {
82  public:
83  // framework hooks
84  void onInitObserver() override;
85  void onConnectObserver() override;
86 
87  // implementation of ObjectMemoryObserverInterface
88  armarx::ChannelRefBasePtr requestObjectClassOnce(const std::string& objectClassName, const IceUtil::Optional<Ice::Int>& priority, const ::Ice::Current& c = Ice::emptyCurrent) override;
89  armarx::ChannelRefBasePtr requestObjectClassRepeated(const std::string& objectClassName, int cycleTimeMS, const IceUtil::Optional<Ice::Int>& priority, const ::Ice::Current& c = Ice::emptyCurrent) override;
90  void releaseObjectClass(const armarx::ChannelRefBasePtr& objectClassChannel, const ::Ice::Current& c = Ice::emptyCurrent) override;
91 
92  ChannelRefBaseSequence getObjectInstances(const armarx::ChannelRefBasePtr& objectClassChannel, const ::Ice::Current& c = Ice::emptyCurrent) override;
93  ChannelRefBaseSequence getObjectInstancesByClass(const std::string& objectClassName, const ::Ice::Current& c = Ice::emptyCurrent) override;
94  armarx::ChannelRefBasePtr getFirstObjectInstance(const armarx::ChannelRefBasePtr& objectClassChannel, const Ice::Current& c = Ice::emptyCurrent) override;
95  armarx::ChannelRefBasePtr getFirstObjectInstanceByClass(const std::string& objectClassName, const Ice::Current& c = Ice::emptyCurrent) override;
96  // ObjectMemoryObserverInterface interface
97  armarx::ChannelRefBasePtr getObjectInstanceById(const std::string&, const ::Ice::Current& c = ::Ice::Current()) override;
98  // TODO: implement user frames
99  armarx::ChannelRefBasePtr addFrame(const std::string& frameName, const ::Ice::Current& c = Ice::emptyCurrent);
100  void removeFrame(const armarx::ChannelRefBasePtr& frameChannel, const ::Ice::Current& c = Ice::emptyCurrent);
101 
102  // implementation of WorkingMemoryListenerInterface
103  void reportEntityCreated(const std::string& segmentName, const EntityBasePtr& entity, const ::Ice::Current& c = Ice::emptyCurrent) override;
104  void reportEntityUpdated(const std::string& segmentName, const EntityBasePtr& entityOld, const EntityBasePtr& entityNew, const ::Ice::Current& c = Ice::emptyCurrent) override;
105  void reportEntityRemoved(const std::string& segmentName, const EntityBasePtr& entity, const ::Ice::Current& c = Ice::emptyCurrent) override;
106  void reportSnapshotLoaded(const std::string& segmentName, const ::Ice::Current& c = Ice::emptyCurrent) override;
107  void reportSnapshotCompletelyLoaded(const Ice::Current& c = Ice::emptyCurrent) override { }
108  void reportMemoryCleared(const std::string& segmentName, const ::Ice::Current& c = Ice::emptyCurrent) override;
109 
110  // Implementation of ManagedIceObject interface
111  std::string getDefaultName() const override
112  {
113  return "ObjectMemoryObserver";
114  }
115 
116  /**
117  * @see PropertyUser::createPropertyDefinitions()
118  */
120  {
124  }
125  private:
126  // utility methods
127  armarx::ChannelRefPtr createObjectLocalizationQueryChannel(const LocalizationQueryPtr& query);
128  void updateObjectLocalizationQueryChannel(const LocalizationQueryPtr& query);
129 
130  std::vector<armarx::ChannelRefPtr> getObjectClassQueries(const std::string& objectClassName);
131 
132  void createObjectInstanceChannel(const ObjectInstancePtr& instance);
133  void updateObjectInstanceChannel(const ObjectInstancePtr& instance);
134  std::string getInstanceChannelName(const EntityBasePtr& instance, const ::Ice::Current& c = Ice::emptyCurrent) const override;
135 
136  // proxies
137  AbstractWorkingMemoryInterfacePrx proxyWorkingMemory;
138  ObjectInstanceMemorySegmentBasePrx objectInstancesSegment;
139  ObjectClassMemorySegmentBasePrx objectClassesSegment;
140  PriorKnowledgeInterfacePrx priorKnowledge;
141  PersistentObjectClassSegmentBasePrx priorObjectClassesSegment;
142 
143  // id handling
144  unsigned int uniqueId;
145  std::mutex idMutex;
146  unsigned int getUniqueId()
147  {
148  std::unique_lock lock(idMutex);
149  return uniqueId++;
150  }
151  };
152 }
153 
memoryx::ObjectMemoryObserver::getFirstObjectInstance
armarx::ChannelRefBasePtr getFirstObjectInstance(const armarx::ChannelRefBasePtr &objectClassChannel, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:230
armarx::Observer
Baseclass for all ArmarX Observers.
Definition: Observer.h:80
memoryx::ObjectMemoryObserver::requestObjectClassOnce
armarx::ChannelRefBasePtr requestObjectClassOnce(const std::string &objectClassName, const IceUtil::Optional< Ice::Int > &priority, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:82
memoryx::ObjectMemoryObserver::requestObjectClassRepeated
armarx::ChannelRefBasePtr requestObjectClassRepeated(const std::string &objectClassName, int cycleTimeMS, const IceUtil::Optional< Ice::Int > &priority, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:87
memoryx::ObjectMemoryObserver::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ObjectMemoryObserver.h:111
memoryx::ObjectMemoryObserver::getObjectInstanceById
armarx::ChannelRefBasePtr getObjectInstanceById(const std::string &, const ::Ice::Current &c=::Ice::Current()) override
Definition: ObjectMemoryObserver.cpp:504
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
memoryx::ObjectMemoryObserver::addFrame
armarx::ChannelRefBasePtr addFrame(const std::string &frameName, const ::Ice::Current &c=Ice::emptyCurrent)
memoryx::ObjectMemoryObserver::reportEntityUpdated
void reportEntityUpdated(const std::string &segmentName, const EntityBasePtr &entityOld, const EntityBasePtr &entityNew, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:288
LocalizationQuery.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::ObjectMemoryObserver::reportSnapshotLoaded
void reportSnapshotLoaded(const std::string &segmentName, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:378
memoryx::ObjectMemoryObserver::removeFrame
void removeFrame(const armarx::ChannelRefBasePtr &frameChannel, const ::Ice::Current &c=Ice::emptyCurrent)
memoryx::ObjectMemoryObserver::reportMemoryCleared
void reportMemoryCleared(const std::string &segmentName, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:382
ObjectClass.h
Observer.h
memoryx::ObjectMemoryObserver::getFirstObjectInstanceByClass
armarx::ChannelRefBasePtr getFirstObjectInstanceByClass(const std::string &objectClassName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:244
memoryx::ObjectMemoryObserver::reportEntityCreated
void reportEntityCreated(const std::string &segmentName, const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:264
memoryx::ObjectMemoryObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: ObjectMemoryObserver.cpp:49
IceInternal::Handle< ChannelRef >
memoryx::ObjectMemoryObserverPropertyDefinitions
Definition: ObjectMemoryObserver.h:52
memoryx::ObjectMemoryObserver::reportSnapshotCompletelyLoaded
void reportSnapshotCompletelyLoaded(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.h:107
armarx::ObserverPropertyDefinitions::ObserverPropertyDefinitions
ObserverPropertyDefinitions(std::string prefix)
Definition: Observer.h:54
memoryx::ObjectMemoryObserver::releaseObjectClass
void releaseObjectClass(const armarx::ChannelRefBasePtr &objectClassChannel, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:127
memoryx::ObjectMemoryObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: ObjectMemoryObserver.cpp:67
Component.h
memoryx::ObjectMemoryObserverPropertyDefinitions::ObjectMemoryObserverPropertyDefinitions
ObjectMemoryObserverPropertyDefinitions(std::string prefix)
Definition: ObjectMemoryObserver.h:56
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
ObjectInstance.h
memoryx::ObjectMemoryObserver
VisionX ObjectMemoryObserver.
Definition: ObjectMemoryObserver.h:78
memoryx::ObjectMemoryObserver::reportEntityRemoved
void reportEntityRemoved(const std::string &segmentName, const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:345
IceUtil::Handle< class PropertyDefinitionContainer >
memoryx::ObjectMemoryObserver::getObjectInstances
ChannelRefBaseSequence getObjectInstances(const armarx::ChannelRefBasePtr &objectClassChannel, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:258
ImportExport.h
memoryx::ObjectMemoryObserver::getObjectInstancesByClass
ChannelRefBaseSequence getObjectInstancesByClass(const std::string &objectClassName, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectMemoryObserver.cpp:159
memoryx::ObjectMemoryObserver::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ObjectMemoryObserver.h:119
ConditionCheck.h
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::ObserverPropertyDefinitions
Definition: Observer.h:50
ChannelRef.h