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
27#include <ArmarXCore/interface/observers/ObserverInterface.h>
28#include <ArmarXCore/interface/observers/VariantBase.h>
32
33// memory interface
34#include <MemoryX/interface/components/PriorKnowledgeInterface.h>
35#include <MemoryX/interface/memorytypes/MemorySegments.h>
36#include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
37#include <MemoryX/interface/workingmemory/AbstractWorkingMemoryInterface.h>
38
39// memoryx
40#include <mutex>
41#include <string>
42
46
47namespace memoryx
48{
49
50
52 {
53 public:
56 {
57 defineOptionalProperty<std::string>("WorkingMemoryListenerTopic",
58 "WorkingMemoryUpdates",
59 "Topic for working memory updates");
61 "WorkingMemoryProxy", "WorkingMemory", "Proxy of working memory");
63 "PriorKnowledgeProxy", "PriorKnowledge", "Proxy of PriorKnowledge");
64 }
65 };
66
67 /**
68 * VisionX ObjectMemoryObserver.
69 *
70 * The ObjectMemoryObserver allows installing conditions on all known objects.
71 * It receives reports from the ObjectMemory about those objects which are being localized.
72 *
73 * It offers a channel for every known object that contains information about the object
74 * pose, if it has been found and how certain the localization is.
75 *
76 * It also offers a channel that contains the names of all objects which have been localized
77 * successfully.
78 *
79 */
81 virtual public armarx::Observer,
82 virtual public ObjectMemoryObserverInterface
83 {
84 public:
85 // framework hooks
86 void onInitObserver() override;
87 void onConnectObserver() override;
88
89 // implementation of ObjectMemoryObserverInterface
90 armarx::ChannelRefBasePtr
91 requestObjectClassOnce(const std::string& objectClassName,
92 const IceUtil::Optional<Ice::Int>& priority,
93 const ::Ice::Current& c = Ice::emptyCurrent) override;
94 armarx::ChannelRefBasePtr
95 requestObjectClassRepeated(const std::string& objectClassName,
96 int cycleTimeMS,
97 const IceUtil::Optional<Ice::Int>& priority,
98 const ::Ice::Current& c = Ice::emptyCurrent) override;
99 void releaseObjectClass(const armarx::ChannelRefBasePtr& objectClassChannel,
100 const ::Ice::Current& c = Ice::emptyCurrent) override;
101
102 ChannelRefBaseSequence
103 getObjectInstances(const armarx::ChannelRefBasePtr& objectClassChannel,
104 const ::Ice::Current& c = Ice::emptyCurrent) override;
105 ChannelRefBaseSequence
106 getObjectInstancesByClass(const std::string& objectClassName,
107 const ::Ice::Current& c = Ice::emptyCurrent) override;
108 armarx::ChannelRefBasePtr
109 getFirstObjectInstance(const armarx::ChannelRefBasePtr& objectClassChannel,
110 const Ice::Current& c = Ice::emptyCurrent) override;
111 armarx::ChannelRefBasePtr
112 getFirstObjectInstanceByClass(const std::string& objectClassName,
113 const Ice::Current& c = Ice::emptyCurrent) override;
114 // ObjectMemoryObserverInterface interface
115 armarx::ChannelRefBasePtr
116 getObjectInstanceById(const std::string&,
117 const ::Ice::Current& c = ::Ice::Current()) override;
118 // TODO: implement user frames
119 armarx::ChannelRefBasePtr addFrame(const std::string& frameName,
120 const ::Ice::Current& c = Ice::emptyCurrent);
121 void removeFrame(const armarx::ChannelRefBasePtr& frameChannel,
122 const ::Ice::Current& c = Ice::emptyCurrent);
123
124 // implementation of WorkingMemoryListenerInterface
125 void reportEntityCreated(const std::string& segmentName,
126 const EntityBasePtr& entity,
127 const ::Ice::Current& c = Ice::emptyCurrent) override;
128 void reportEntityUpdated(const std::string& segmentName,
129 const EntityBasePtr& entityOld,
130 const EntityBasePtr& entityNew,
131 const ::Ice::Current& c = Ice::emptyCurrent) override;
132 void reportEntityRemoved(const std::string& segmentName,
133 const EntityBasePtr& entity,
134 const ::Ice::Current& c = Ice::emptyCurrent) override;
135 void reportSnapshotLoaded(const std::string& segmentName,
136 const ::Ice::Current& c = Ice::emptyCurrent) override;
137
138 void
139 reportSnapshotCompletelyLoaded(const Ice::Current& c = Ice::emptyCurrent) override
140 {
141 }
142
143 void reportMemoryCleared(const std::string& segmentName,
144 const ::Ice::Current& c = Ice::emptyCurrent) override;
145
146 // Implementation of ManagedIceObject interface
147 std::string
148 getDefaultName() const override
149 {
150 return "ObjectMemoryObserver";
151 }
152
153 /**
154 * @see PropertyUser::createPropertyDefinitions()
155 */
162
163 private:
164 // utility methods
166 createObjectLocalizationQueryChannel(const LocalizationQueryPtr& query);
167 void updateObjectLocalizationQueryChannel(const LocalizationQueryPtr& query);
168
169 std::vector<armarx::ChannelRefPtr>
170 getObjectClassQueries(const std::string& objectClassName);
171
172 void createObjectInstanceChannel(const ObjectInstancePtr& instance);
173 void updateObjectInstanceChannel(const ObjectInstancePtr& instance);
174 std::string
175 getInstanceChannelName(const EntityBasePtr& instance,
176 const ::Ice::Current& c = Ice::emptyCurrent) const override;
177
178 // proxies
179 AbstractWorkingMemoryInterfacePrx proxyWorkingMemory;
180 ObjectInstanceMemorySegmentBasePrx objectInstancesSegment;
181 ObjectClassMemorySegmentBasePrx objectClassesSegment;
182 PriorKnowledgeInterfacePrx priorKnowledge;
183 PersistentObjectClassSegmentBasePrx priorObjectClassesSegment;
184
185 // id handling
186 unsigned int uniqueId;
187 std::mutex idMutex;
188
189 unsigned int
190 getUniqueId()
191 {
192 std::unique_lock lock(idMutex);
193 return uniqueId++;
194 }
195 };
196} // namespace memoryx
constexpr T c
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
ObserverPropertyDefinitions(std::string prefix)
Definition Observer.h:52
Baseclass for all ArmarX Observers.
Definition Observer.h:87
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
VisionX ObjectMemoryObserver.
armarx::ChannelRefBasePtr getObjectInstanceById(const std::string &, const ::Ice::Current &c=::Ice::Current()) override
armarx::ChannelRefBasePtr addFrame(const std::string &frameName, const ::Ice::Current &c=Ice::emptyCurrent)
void onConnectObserver() override
Framework hook.
void reportEntityRemoved(const std::string &segmentName, const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
void reportEntityUpdated(const std::string &segmentName, const EntityBasePtr &entityOld, const EntityBasePtr &entityNew, const ::Ice::Current &c=Ice::emptyCurrent) override
ChannelRefBaseSequence getObjectInstances(const armarx::ChannelRefBasePtr &objectClassChannel, const ::Ice::Current &c=Ice::emptyCurrent) override
armarx::ChannelRefBasePtr requestObjectClassRepeated(const std::string &objectClassName, int cycleTimeMS, const IceUtil::Optional< Ice::Int > &priority, const ::Ice::Current &c=Ice::emptyCurrent) override
armarx::ChannelRefBasePtr requestObjectClassOnce(const std::string &objectClassName, const IceUtil::Optional< Ice::Int > &priority, const ::Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportEntityCreated(const std::string &segmentName, const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
void reportSnapshotCompletelyLoaded(const Ice::Current &c=Ice::emptyCurrent) override
armarx::ChannelRefBasePtr getFirstObjectInstanceByClass(const std::string &objectClassName, const Ice::Current &c=Ice::emptyCurrent) override
armarx::ChannelRefBasePtr getFirstObjectInstance(const armarx::ChannelRefBasePtr &objectClassChannel, const Ice::Current &c=Ice::emptyCurrent) override
void reportSnapshotLoaded(const std::string &segmentName, const ::Ice::Current &c=Ice::emptyCurrent) override
ChannelRefBaseSequence getObjectInstancesByClass(const std::string &objectClassName, const ::Ice::Current &c=Ice::emptyCurrent) override
void removeFrame(const armarx::ChannelRefBasePtr &frameChannel, const ::Ice::Current &c=Ice::emptyCurrent)
void onInitObserver() override
Framework hook.
void reportMemoryCleared(const std::string &segmentName, const ::Ice::Current &c=Ice::emptyCurrent) override
void releaseObjectClass(const armarx::ChannelRefBasePtr &objectClassChannel, const ::Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
VirtualRobot headers.
IceInternal::Handle< LocalizationQuery > LocalizationQueryPtr
IceInternal::Handle< ObjectInstance > ObjectInstancePtr