ObjectLocalizationMemoryUpdater.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::Core
17* @author Kai Welke <welke@kit.edu>
18* @copyright 2012 Kai Welke
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25#include <string>
26
30
31#include <RobotAPI/interface/core/RobotState.h>
32#include <RobotAPI/interface/units/TCPControlUnit.h>
33
42
43namespace memoryx
44{
46 using ObjectLocalizationMemoryUpdaterPtr = IceInternal::Handle<ObjectLocalizationMemoryUpdater>;
47
49 {
52 {
53 defineOptionalProperty<std::string>("RobotStateComponentName",
54 "RobotStateComponent",
55 "Name of the RobotStateComponent");
57 "WorkingMemoryName",
58 "WorkingMemory",
59 "Name of the WorkingMemory component that should be used");
61 "LongtermMemoryName",
62 "LongtermMemory",
63 "Name of the LongtermMemory component that should be used");
65 "RobotStateObserverName",
66 "RobotStateObserver",
67 "Name of the RobotStateObserver that can be used for observing the head motion");
69 "GazeTCPName",
70 "VirtualCentralGaze",
71 "Name of the gaze tcp that can be used for observing the head motion");
72 defineOptionalProperty<std::string>("CommonPlacesLearnerName",
73 "",
74 "Name of the CommonPlacesLearner that will be "
75 "trained when object instances are updated");
77 "CheckFieldOfView", false, "Check if detected object is inside field of view.");
78 defineOptionalProperty<float>("ExistenceCertaintyReductionFactorWhenLocalizationFailed",
79 0.95f,
80 "Existence certainty will be reduced by this factor when "
81 "a localization returns without result");
83 "CameraOpeningAngle",
84 30.0f * M_PI / 180.0f,
85 "Very conservative estimation of the camera opening angle, in radians");
87 "MaximalObjectDistance",
88 1500.0f,
89 "Maximal distance an object may have from the camera to be localized");
90 defineOptionalProperty<std::string>("RobotNodeNameLeftCamera",
91 "EyeLeftCamera",
92 "Name of the robot node of the left camera");
93 defineOptionalProperty<std::string>("RobotNodeNameRightCamera",
94 "EyeRightCamera",
95 "Name of the robot node of the right camera");
97 "HeadMotionVelocityLimit",
98 100,
99 "Maximal velocity of the head up to which localizations are executed. Speed is in "
100 "mm/s at a the virtual gaze tcp");
102 "HandNodeNameLeft", "TCP L", "Name of the robot node for the left hand/TCP");
104 "HandNodeNameRight", "TCP R", "Name of the robot node for the right hand/TCP");
105
107 "KBMReferenceNodeName",
108 "Cameras",
109 "Name of the robot node on which the KBM resides. Data should be provided wrt. to "
110 "its coordinate frame (i.e., not be transformed by the robot model which "
111 "introduces a new source of error).");
113 "KBMLeftArmNodeSetName",
114 "LeftArm",
115 "Name of the robot node set for the kinematic chain for the left arm.");
117 "KBMRightArmNodeSetName",
118 "RightArm",
119 "Name of the robot node set for the kinematic chain for the right arm.");
120 }
121 };
122
123 /**
124 * @class ObjectLocalizationMemoryUpdater
125 * @ingroup WorkingMemory
126 *
127 * The ObjectLocalizationMemoryUpdater triggers the localization of object classes based on the content of
128 * the object classes working memory segment and generates object instances in the object instances
129 * if objects have been localized.
130 *
131 * The localization is triggered by adding a LocalizationQuery to the corresponding ObjectClass entity
132 * via the ObjectRecognitionWrapper:
133 */
135 virtual public WorkingMemoryUpdater,
136 virtual public ObjectLocalizationMemoryUpdaterBase
137 {
138 public:
140 void setSegmentNames(std::string classSegmentName, std::string instanceSegmentName);
141 void setReferenceFrame(const std::string& referenceFrameName);
142
149
150 std::string
151 getDefaultName() const override
152 {
153 return "ObjectLocalizationMemoryUpdater";
154 }
155
156
157 protected:
158 // inherited from managedIceObject
159 void onInitComponent() override;
160 void onConnectComponent() override;
161 void onDisconnectComponent() override;
162
163 // inherited from WorkingMemoryListenerInterface
164 void
165 reportEntityCreated(const std::string& segmentName,
166 const EntityBasePtr& entity,
167 const Ice::Current& c = Ice::emptyCurrent) override
168 {
169 }
170
171 void reportEntityUpdated(const std::string& segmentName,
172 const EntityBasePtr& entityOld,
173 const EntityBasePtr& entityNew,
174 const Ice::Current& c = Ice::emptyCurrent) override;
175
176 void
177 reportEntityRemoved(const std::string& segmentName,
178 const EntityBasePtr& entity,
179 const Ice::Current& c = Ice::emptyCurrent) override
180 {
181 }
182
183 void
184 reportSnapshotLoaded(const std::string& segmentName,
185 const Ice::Current& c = Ice::emptyCurrent) override
186 {
187 }
188
189 void
190 reportSnapshotCompletelyLoaded(const Ice::Current& c = Ice::emptyCurrent) override
191 {
192 }
193
194 void
195 reportMemoryCleared(const std::string& segmentName,
196 const Ice::Current& c = Ice::emptyCurrent) override
197 {
198 }
199
200 private:
201 // main scheduler
202 void runJobs();
203 void scheduleJobs();
204
205
206 // asynchronous localization
207 void startLocalization(const LocalizationJobContainerPtr& jobContainer);
208 void localizationFinished(const Ice::AsyncResultPtr& r);
209 /**
210 * @brief finishJobContainer stops all LocalizationJob instances associated with \p jobContainer and updates all pending queries.
211 * @param jobContainer
212 */
213 void finishJobContainer(LocalizationJobContainerPtr jobContainer);
214
215 // running state handling of recognition methods
216 bool isRecognitionMethodRunning(const std::string& recognitionMethod);
217 void setRecognitionMethodRunningState(const std::string& recognitionMethod, bool running);
218
219 // utility methods
220 ObjectLocalizerInterfacePrx getProxyCached(const std::string& recognitionMethod);
221 LocalizationQueryList getMissingQueries(const LocalizationQueryList& queriesBase,
222 const LocalizationQueryList& queriesCompare);
223 void updateQueries(const LocalizationJobContainerPtr& jobContainer);
224 bool checkObjectVisibility(armarx::FramedPositionPtr pos);
225 void setMotionModel(ObjectInstancePtr& objectInstance);
226 void predictPoses();
227
228 // working memory segments
229 std::string workingMemoryName;
230 std::string classSegmentName;
231 std::string instanceSegmentName;
232 std::string agentInstancesSegmentName;
233 ObjectInstanceMemorySegmentPtr objectInstanceSegment;
234 ObjectClassMemorySegmentBasePtr objectClassSegment;
235 AgentInstancesSegmentPtr agentInstancesSegment;
236 std::string referenceFrameName;
237 std::string agentName;
238
239 // job scheduling
241 std::mutex jobsMutex;
242 std::mutex predictionMutex;
243 std::vector<LocalizationJobPtr> jobs;
244
245 // recognition method running state
246 std::mutex recognitionMethodStateMutex;
247 std::map<std::string, bool> recognitionMethodRunning;
248
249 // proxy cache
250 std::map<std::string, ObjectLocalizerInterfacePrx> knownObjectProxies;
251 armarx::RobotStateComponentInterfacePrx robotStateInterfacePrx;
252
253 // observes the head motion speed
254 armarx::ObserverInterfacePrx robotStateObserverProxy;
255 armarx::DataFieldIdentifierPtr headTCPVelocityDatafieldID;
256 float headMotionVelocityLimit;
257
258 // CommonPlacesLearner to train
259 memoryx::CommonPlacesLearnerInterfacePrx commonPlacesLearnerProxy;
260
261 // opening angle of the used cameras
262 bool checkFieldOfView;
263 float cameraOpeningAngle;
264 std::string robotNodeNameLeftCamera, robotNodeNameRightCamera, handNodeNameLeft,
265 handNodeNameRight;
266
267 LongtermMemoryInterfacePrx longtermMemoryPrx;
268 };
269} // namespace memoryx
270
271namespace std
272{
273 template <typename T>
274 ostream&
275 operator<<(ostream& str, const std::set<T>& set)
276 {
277 str << "Set(" << set.size() << "):\n";
278
279 for (const auto& elem : set)
280 {
281 str << "\t" << elem << "\n";
282 }
283
284 return str;
285 }
286} // namespace std
#define ARMARXCORE_IMPORT_EXPORT
#define M_PI
Definition MathTools.h:17
constexpr T c
std::string str(const T &t)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
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)
The ObjectLocalizationMemoryUpdater triggers the localization of object classes based on the content ...
void reportEntityCreated(const std::string &segmentName, const EntityBasePtr &entity, const Ice::Current &c=Ice::emptyCurrent) override
void reportMemoryCleared(const std::string &segmentName, const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportSnapshotCompletelyLoaded(const Ice::Current &c=Ice::emptyCurrent) override
void reportSnapshotLoaded(const std::string &segmentName, const Ice::Current &c=Ice::emptyCurrent) override
void reportEntityRemoved(const std::string &segmentName, const EntityBasePtr &entity, const Ice::Current &c=Ice::emptyCurrent) override
void setReferenceFrame(const std::string &referenceFrameName)
std::string getDefaultName() const override
Retrieve default name of component.
void setSegmentNames(std::string classSegmentName, std::string instanceSegmentName)
WorkingMemoryUpdater()
Constructs a new working memory updater method.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.
VirtualRobot headers.
IceUtil::Handle< LocalizationJobContainer > LocalizationJobContainerPtr
IceInternal::Handle< ObjectInstanceMemorySegment > ObjectInstanceMemorySegmentPtr
IceInternal::Handle< AgentInstancesSegment > AgentInstancesSegmentPtr
IceInternal::Handle< ObjectLocalizationMemoryUpdater > ObjectLocalizationMemoryUpdaterPtr
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
ARMARXCORE_IMPORT_EXPORT ostream & operator<<(ostream &stream, const armarx::RunningTaskIceBase &task)