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 
43 namespace memoryx
44 {
45  class ObjectLocalizationMemoryUpdater;
47 
49  {
52  {
53  defineOptionalProperty<std::string>("RobotStateComponentName",
54  "RobotStateComponent",
55  "Name of the RobotStateComponent");
56  defineOptionalProperty<std::string>(
57  "WorkingMemoryName",
58  "WorkingMemory",
59  "Name of the WorkingMemory component that should be used");
60  defineOptionalProperty<std::string>(
61  "LongtermMemoryName",
62  "LongtermMemory",
63  "Name of the LongtermMemory component that should be used");
64  defineOptionalProperty<std::string>(
65  "RobotStateObserverName",
66  "RobotStateObserver",
67  "Name of the RobotStateObserver that can be used for observing the head motion");
68  defineOptionalProperty<std::string>(
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");
76  defineOptionalProperty<bool>(
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");
82  defineOptionalProperty<float>(
83  "CameraOpeningAngle",
84  30.0f * M_PI / 180.0f,
85  "Very conservative estimation of the camera opening angle, in radians");
86  defineOptionalProperty<float>(
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");
96  defineOptionalProperty<float>(
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");
101  defineOptionalProperty<std::string>(
102  "HandNodeNameLeft", "TCP L", "Name of the robot node for the left hand/TCP");
103  defineOptionalProperty<std::string>(
104  "HandNodeNameRight", "TCP R", "Name of the robot node for the right hand/TCP");
105 
106  defineOptionalProperty<std::string>(
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).");
112  defineOptionalProperty<std::string>(
113  "KBMLeftArmNodeSetName",
114  "LeftArm",
115  "Name of the robot node set for the kinematic chain for the left arm.");
116  defineOptionalProperty<std::string>(
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 
145  {
147  new ObjectLocalizationMemoryUpdaterProperties(getConfigIdentifier()));
148  }
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 
271 namespace 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
memoryx::ObjectLocalizationMemoryUpdater::reportEntityCreated
void reportEntityCreated(const std::string &segmentName, const EntityBasePtr &entity, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationMemoryUpdater.h:165
memoryx::ObjectLocalizationMemoryUpdater::reportSnapshotCompletelyLoaded
void reportSnapshotCompletelyLoaded(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationMemoryUpdater.h:190
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:43
memoryx::ObjectLocalizationMemoryUpdaterProperties
Definition: ObjectLocalizationMemoryUpdater.h:48
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
PeriodicTask.h
LocalizationQuery.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
DataFieldIdentifier.h
memoryx::ObjectLocalizationMemoryUpdater::reportSnapshotLoaded
void reportSnapshotLoaded(const std::string &segmentName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationMemoryUpdater.h:184
ObjectClass.h
IceInternal::Handle< ObjectLocalizationMemoryUpdater >
ObjectInstanceMemorySegment.h
memoryx::WorkingMemoryUpdater
Base class for all working memory updater processes.
Definition: WorkingMemoryUpdater.h:56
LocalizationJob.h
M_PI
#define M_PI
Definition: MathTools.h:17
memoryx::ObjectLocalizationMemoryUpdater::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ObjectLocalizationMemoryUpdater.h:151
WorkingMemoryUpdater.h
memoryx::ObjectLocalizationMemoryUpdater
Definition: ObjectLocalizationMemoryUpdater.h:134
AgentInstancesSegment.h
LocalizationJobContainer.h
memoryx::ObjectLocalizationMemoryUpdaterPtr
IceInternal::Handle< ObjectLocalizationMemoryUpdater > ObjectLocalizationMemoryUpdaterPtr
Definition: WorkingMemory.h:36
CommonPlacesLearner.h
std::operator<<
ARMARXCORE_IMPORT_EXPORT ostream & operator<<(ostream &stream, const armarx::RunningTaskIceBase &task)
memoryx::ObjectLocalizationMemoryUpdaterProperties::ObjectLocalizationMemoryUpdaterProperties
ObjectLocalizationMemoryUpdaterProperties(std::string prefix)
Definition: ObjectLocalizationMemoryUpdater.h:50
memoryx::ObjectLocalizationMemoryUpdater::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ObjectLocalizationMemoryUpdater.h:144
std
Definition: Application.h:66
set
set(LIBS ArmarXCoreInterfaces ${CMAKE_THREAD_LIBS_INIT} ${dl_LIBRARIES} ${rt_LIBRARIES} ${QT_LIBRARIES} ${Boost_LIBRARIES} BoostAssertionHandler ArmarXCPPUtility SimoxUtility) set(LIB_FILES ArmarXManager.cpp ArmarXMultipleObjectsScheduler.cpp ArmarXObjectScheduler.cpp ManagedIceObject.cpp ManagedIceObjectPlugin.cpp Component.cpp ComponentPlugin.cpp IceGridAdmin.cpp ArmarXObjectObserver.cpp IceManager.cpp PackagePath.cpp RemoteReferenceCount.cpp logging/LoggingUtil.cpp logging/Logging.cpp logging/LogSender.cpp logging/ArmarXLogBuf.cpp system/ArmarXDataPath.cpp system/DynamicLibrary.cpp system/ProcessWatcher.cpp system/FactoryCollectionBase.cpp system/cmake/CMakePackageFinder.cpp system/cmake/CMakePackageFinderCache.cpp system/cmake/ArmarXPackageToolInterface.cpp system/RemoteObjectNode.cpp services/sharedmemory/HardwareId.cpp services/tasks/RunningTask.cpp services/tasks/ThreadList.cpp services/tasks/ThreadPool.cpp services/profiler/Profiler.cpp services/profiler/FileLoggingStrategy.cpp services/profiler/IceLoggingStrategy.cpp application/Application.cpp application/ApplicationOptions.cpp application/ApplicationProcessFacet.cpp application/ApplicationNetworkStats.cpp application/properties/PropertyUser.cpp application/properties/Property.cpp application/properties/PropertyDefinition.cpp application/properties/PropertyDefinitionContainer.cpp application/properties/PropertyDefinitionHelpFormatter.cpp application/properties/PropertyDefinitionConfigFormatter.cpp application/properties/PropertyDefinitionBriefHelpFormatter.cpp application/properties/PropertyDefinitionXmlFormatter.cpp application/properties/PropertyDefinitionDoxygenFormatter.cpp application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.cpp application/properties/PropertyDefinitionContainerBriefHelpFormatter.cpp application/properties/IceProperties.cpp exceptions/Exception.cpp exceptions/local/UnexpectedEnumValueException.cpp util/FileSystemPathBuilder.cpp util/StringHelpers.cpp util/IceReportSkipper.cpp util/Throttler.cpp util/distributed/AMDCallbackCollection.cpp util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.cpp util/distributed/RemoteHandle/RemoteHandle.cpp util/distributed/RemoteHandle/RemoteHandleControlBlock.cpp time/ice_conversions.cpp time/json_conversions.cpp time/CallbackWaitLock.cpp time/Clock.cpp time/ClockType.cpp time/ClockTypeNames.cpp time/CycleUtil.cpp time/DateTime.cpp time/Duration.cpp time/Frequency.cpp time/LocalTimeServer.cpp time/Metronome.cpp time/ScopedStopWatch.cpp time/StopWatch.cpp time/Timer.cpp time/TimeKeeper.cpp time/TimeUtil.cpp csv/CsvWriter.cpp csv/CsvReader.cpp eigen/conversions.cpp eigen/ice_conversions.cpp) set(LIB_HEADERS ArmarXManager.h ArmarXDummyManager.h ArmarXMultipleObjectsScheduler.h ArmarXObjectObserver.h ArmarXObjectScheduler.h ArmarXFwd.h Component.h ComponentPlugin.h ComponentFactories.h CoreObjectFactories.h IceGridAdmin.h IceManager.h IceManagerImpl.h json_conversions.h ManagedIceObject.h ManagedIceObjectPlugin.h ManagedIceObjectImpl.h ManagedIceObjectDependency.h ManagedIceObjectRegistryInterface.h PackagePath.h RemoteReferenceCount.h system/ImportExport.h system/ImportExportComponent.h system/AbstractFactoryMethod.h system/FactoryCollectionBase.h system/Synchronization.h system/ArmarXDataPath.h system/DynamicLibrary.h system/ProcessWatcher.h system/ConditionSynchronization.h system/cmake/CMakePackageFinder.h system/cmake/CMakePackageFinderCache.h system/cmake/FindPackageX.cmake system/cmake/ArmarXPackageToolInterface.h system/RemoteObjectNode.h logging/LoggingUtil.h logging/LogSender.h logging/Logging.h logging/ArmarXLogBuf.h logging/SpamFilterData.h services/tasks/RunningTask.h services/tasks/PeriodicTask.h services/tasks/ThreadList.h services/tasks/TaskUtil.h services/tasks/ThreadPool.h services/sharedmemory/SharedMemoryProvider.h services/sharedmemory/SharedMemoryConsumer.h services/sharedmemory/IceSharedMemoryProvider.h services/sharedmemory/IceSharedMemoryConsumer.h services/sharedmemory/HardwareIdentifierProvider.h services/sharedmemory/HardwareId.h services/sharedmemory/exceptions/SharedMemoryExceptions.h services/profiler/Profiler.h services/profiler/LoggingStrategy.h services/profiler/FileLoggingStrategy.h services/profiler/IceLoggingStrategy.h application/Application.h application/ApplicationOptions.h application/ApplicationProcessFacet.h application/ApplicationNetworkStats.h application/properties/forward_declarations.h application/properties/Properties.h application/properties/Property.h application/properties/PluginEigen.h application/properties/PluginEnumNames.h application/properties/PluginCfgStruct.h application/properties/PluginAll.h application/properties/PropertyUser.h application/properties/PropertyDefinition.h application/properties/PropertyDefinition.hpp application/properties/PropertyDefinitionInterface.h application/properties/PropertyDefinitionContainer.h application/properties/PropertyDefinitionFormatter.h application/properties/PropertyDefinitionContainerFormatter.h application/properties/PropertyDefinitionConfigFormatter.h application/properties/PropertyDefinitionHelpFormatter.h application/properties/PropertyDefinitionBriefHelpFormatter.h application/properties/PropertyDefinitionXmlFormatter.h application/properties/PropertyDefinitionDoxygenFormatter.h application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.h application/properties/PropertyDefinitionContainerBriefHelpFormatter.h application/properties/ProxyPropertyDefinition.h application/properties/IceProperties.h exceptions/Exception.h exceptions/LocalException.h exceptions/local/DynamicLibraryException.h exceptions/local/ExpressionException.h exceptions/local/FileIOException.h exceptions/local/InvalidPropertyValueException.h exceptions/local/MissingRequiredPropertyException.h exceptions/local/PropertyInheritanceCycleException.h exceptions/local/ProxyNotInitializedException.h exceptions/local/UnexpectedEnumValueException.h exceptions/local/UnmappedValueException.h exceptions/local/ValueRangeExceededException.h exceptions/user/NotImplementedYetException.h rapidxml/rapidxml.hpp rapidxml/rapidxml_print.hpp rapidxml/rapidxml_iterators.hpp rapidxml/rapidxml_utils.hpp rapidxml/wrapper/RapidXmlReader.h rapidxml/wrapper/RapidXmlWriter.h rapidxml/wrapper/DefaultRapidXmlReader.h rapidxml/wrapper/MultiNodeRapidXMLReader.h util/IceBlobToObject.h util/ObjectToIceBlob.h util/FileSystemPathBuilder.h util/FiniteStateMachine.h util/StringHelpers.h util/StringHelperTemplates.h util/algorithm.h util/OnScopeExit.h util/Predicates.h util/Preprocessor.h util/PropagateConst.h util/Registrar.h util/TemplateMetaProgramming.h util/TripleBuffer.h util/IceReportSkipper.h util/Throttler.h util/distributed/AMDCallbackCollection.h util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h util/distributed/RemoteHandle/RemoteHandle.h util/distributed/RemoteHandle/RemoteHandleControlBlock.h util/SimpleStatemachine.h time.h time_minimal.h time/forward_declarations.h time/ice_conversions.h time/json_conversions.h time/CallbackWaitLock.h time/Clock.h time/ClockType.h time/ClockTypeNames.h time/CycleUtil.h time/DateTime.h time/Duration.h time/Frequency.h time/LocalTimeServer.h time/Metronome.h time/ScopedStopWatch.h time/StopWatch.h time/Timer.h time/TimeUtil.h time/TimeKeeper.h csv/CsvWriter.h csv/CsvReader.h eigen/conversions.h eigen/ice_conversions.h ice_conversions.h ice_conversions/ice_conversions_boost_templates.h ice_conversions/ice_conversions_templates.h ice_conversions/ice_conversions_templates.tpp $
Definition: CMakeLists.txt:12
IceUtil::Handle< class PropertyDefinitionContainer >
memoryx::ObjectLocalizationMemoryUpdater::reportMemoryCleared
void reportMemoryCleared(const std::string &segmentName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationMemoryUpdater.h:195
memoryx::ObjectLocalizationMemoryUpdater::reportEntityRemoved
void reportEntityRemoved(const std::string &segmentName, const EntityBasePtr &entity, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationMemoryUpdater.h:177
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
ImportExport.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
memoryx::WorkingMemoryUpdaterProperties
Definition: WorkingMemoryUpdater.h:39