33 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
51 usingProxy(getProperty<std::string>(
"WorkingMemoryProxy").getValue());
52 usingProxy(getProperty<std::string>(
"PriorKnowledgeProxy").getValue());
64 usingTopic(getProperty<std::string>(
"WorkingMemoryListenerTopic").getValue());
70 proxyWorkingMemory = getProxy<AbstractWorkingMemoryInterfacePrx>(getProperty<std::string>(
"WorkingMemoryProxy").getValue());
71 getProxy(priorKnowledge, getProperty<std::string>(
"PriorKnowledgeProxy").getValue());
72 priorObjectClassesSegment = priorKnowledge->getObjectClassesSegment();
74 objectInstancesSegment = ObjectInstanceMemorySegmentBasePrx::checkedCast(proxyWorkingMemory->getSegment(
"objectInstances"));
75 objectClassesSegment = ObjectClassMemorySegmentBasePrx::checkedCast(proxyWorkingMemory->getSegment(
"objectClasses"));
89 ARMARX_IMPORTANT <<
"attending to objects of class: " << objectClassName <<
" with cycle time " << cycleTimeMS;
92 ObjectClassList classes = objectClassesSegment->addPriorClassWithSubclasses(objectClassName);
94 if (classes.size() == 0)
101 std::stringstream ss;
102 ss << objectClassName <<
"_query_" << getUniqueId();
103 std::string queryName = ss.str();
106 ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(objectClassesSegment->getEntityByName(objectClassName)->ice_clone());
109 int localizationPriority = armarx::DEFAULT_VIEWTARGET_PRIORITY;
112 localizationPriority = priority.get();
115 recognitionWrapper->addLocalizationQuery(query);
118 armarx::ChannelRefBasePtr queryChannel = createObjectLocalizationQueryChannel(query);
121 objectClassesSegment->updateEntity(objectClass->getId(), objectClass);
132 ARMARX_INFO <<
"Object class query channel " << objectClassChannel->channelName <<
"does not exist - skipping removal";
135 std::string objectClassName = channelRef->getDataField(
"className")->getString();
140 auto entity = objectClassesSegment->getEntityByName(objectClassName);
146 recognitionWrapper->removeLocalizationQuery(objectClassChannel->channelName);
149 objectClassesSegment->updateEntity(objectClass->getId(), objectClass);
152 objectClassesSegment->removePriorClassWithSubclasses(objectClassName);
161 memoryx::ChannelRefBaseSequence channels;
164 ObjectClassList relevantClasses = priorObjectClassesSegment->getClassWithSubclasses(objectClassName);
165 for (ObjectClassBasePtr& objClass : relevantClasses)
167 ARMARX_DEBUG <<
"relevant class: " << objClass->getName();
172 for (armarx::ChannelRegistry::iterator iter = registry.begin() ; iter != registry.end() ; iter++)
175 armarx::ChannelRegistryEntry channelEntry = iter->second;
178 if (channelEntry.dataFields.find(
"instanceName") == channelEntry.dataFields.end())
180 ARMARX_DEBUG <<
"No instance name for " << channelEntry.name;
185 armarx::DataFieldRegistry dataFields = channelEntry.dataFields;
186 armarx::DataFieldRegistry::const_iterator iterDataFields = dataFields.find(
"className");
188 if (iterDataFields == dataFields.end())
190 ARMARX_DEBUG <<
"No class name for " << channelEntry.name;
194 armarx::DataFieldRegistryEntry dataField = iterDataFields->second;
195 if (!dataField.value->getInitialized())
197 ARMARX_DEBUG <<
"className not init. for " << channelEntry.name;
201 std::string channelObjectClassName = dataField.value->getString();
203 bool relevant =
false;
205 for (ObjectClassList::iterator iterClasses = relevantClasses.begin() ; iterClasses != relevantClasses.end() ; iterClasses++)
207 ObjectClassBasePtr objectClass = *iterClasses;
209 if (objectClass->getName() == channelObjectClassName)
218 ARMARX_DEBUG <<
"Adding instance " << iter->first <<
" to result";
234 if (instances.size() > 0)
236 return instances.front();
240 return armarx::ChannelRefBasePtr();
248 if (instances.size() > 0)
250 return instances.front();
254 return armarx::ChannelRefBasePtr();
266 ARMARX_VERBOSE <<
"reportEntityCreated(): " << entity->getName() <<
", segmentName: " << segmentName;
279 ARMARX_ERROR <<
"Object instance " << instance->getName() <<
" already in channel list";
284 createObjectInstanceChannel(instance);
285 updateObjectInstanceChannel(instance);
290 ARMARX_DEBUG <<
deactivateSpam(5, entityNew->getName()) <<
"ObjectMemoryObserver::reportEntityUpdated(): " << entityNew->getName() <<
", segmentName: " << segmentName;
293 if (segmentName ==
"objectClasses")
295 ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(entityNew);
298 LocalizationQueryList queries = recognitionWrapper->getLocalizationQueries();
300 for (LocalizationQueryList::iterator iter = queries.begin() ; iter != queries.end() ; iter++)
304 updateObjectLocalizationQueryChannel(LocalizationQueryPtr::dynamicCast(*iter));
308 createObjectLocalizationQueryChannel(LocalizationQueryPtr::dynamicCast(*iter));
315 if (segmentName ==
"objectInstances")
329 ARMARX_INFO <<
"Object instance " << instance->getName() <<
" not in channel list - creating it";
332 createObjectInstanceChannel(instance);
336 updateObjectInstanceChannel(instance);
347 ARMARX_VERBOSE <<
"reportEntityRemoved(): " << entity->getName() <<
", segmentName: " << segmentName;
359 ARMARX_ERROR <<
"Object instance " << instance->getName() <<
" not in channel list";
368 auto channels = getObjectClassQueries(objClass->getName());
369 for (
auto& channel : channels)
386 if (segmentName ==
"objectClasses" || segmentName ==
"objectInstances")
391 for (
auto& channel : channels)
403 ARMARX_INFO <<
"Creating channel for object class: " << query->className;
404 std::string channelName = query->queryName;
407 offerChannel(channelName,
"object class information for " + query->className);
416 void ObjectMemoryObserver::updateObjectLocalizationQueryChannel(
const LocalizationQueryPtr& query)
418 ARMARX_DEBUG <<
"updateObjectLocalizationQueryChannel()";
421 std::string channelName = query->queryName;
423 setDataField(channelName,
"localizationFinished", query->getFinished());
428 std::vector<armarx::ChannelRefPtr> ObjectMemoryObserver::getObjectClassQueries(
const std::string& objectClassName)
430 std::vector<armarx::ChannelRefPtr> result;
432 for (
auto& pair : registry)
434 armarx::ChannelRegistryEntry& entry = pair.second;
435 auto it = entry.dataFields.find(
"className");
436 if (entry.name.find(
"_query_") != std::string::npos && it != entry.dataFields.end() && it->second.value->getType() ==
armarx::VariantType::String && it->second.value->getString() == objectClassName)
444 void ObjectMemoryObserver::createObjectInstanceChannel(
const ObjectInstancePtr& instance)
447 std::string channelName = getInstanceChannelName(instance);
448 std::string objectInstanceName = instance->getName();
450 ARMARX_INFO <<
"Creating channel " << channelName <<
" for instance: " << objectInstanceName;
453 offerChannel(channelName,
"object instance information for " + objectInstanceName);
468 void ObjectMemoryObserver::updateObjectInstanceChannel(
const ObjectInstancePtr& instance)
472 std::string channelName = getInstanceChannelName(instance);
485 if (instance->getPositionUncertainty())
488 stdDeviation = pow(posUncertaintyDistribution.
getCovariance().determinant(), 0.5 / posUncertaintyDistribution.
getDimensions());
498 std::string ObjectMemoryObserver::getInstanceChannelName(
const EntityBasePtr& instance, const ::Ice::Current&
c)
const
500 std::string channelName = instance->getName() + instance->getId();
506 armarx::ChannelRegistry registry = getAvailableChannels(
false);
508 for (armarx::ChannelRegistry::iterator iter = registry.begin() ; iter != registry.end() ; iter++)
510 armarx::ChannelRegistryEntry channelEntry = iter->second;
513 if (channelEntry.dataFields.find(
"instanceName") == channelEntry.dataFields.end())
518 auto it = channelEntry.dataFields.find(
"id");
519 if (it == channelEntry.dataFields.end())
524 if (it->second.value->getString() ==
id)