33 #include <AffordanceKit/embodiments/Armar3Embodiment.h>
34 #include <AffordanceKit/embodiments/Armar4Embodiment.h>
35 #include <AffordanceKit/embodiments/WalkManEmbodiment.h>
43 hasNewPrimitives(false),
44 lastProcessedTimestamp(0),
62 ARMARX_ERROR <<
"New segmentation available, but failed to access environmental primitives segment";
68 std::string embodimentName = getProperty<std::string>(
"EmbodimentName").getValue();
70 ARMARX_INFO <<
"Using embodiment '" << embodimentName <<
"'";
71 if (embodimentName ==
"Armar3")
73 embodiment.reset(
new AffordanceKit::Armar3Embodiment());
75 else if (embodimentName ==
"Armar4")
77 embodiment.reset(
new AffordanceKit::Armar4Embodiment());
79 else if (embodimentName ==
"WalkMan")
81 embodiment.reset(
new AffordanceKit::WalkManEmbodiment());
85 ARMARX_ERROR <<
"Unknown embodiment '" << embodimentName <<
"' specified. Affordance extraction will not work properly.";
86 embodiment.reset(
new AffordanceKit::Embodiment());
165 std::string affordanceRestrictionString = getProperty<std::string>(
"RestrictToAffordanceList").getValue();
166 if (affordanceRestrictionString !=
"")
168 auto affordanceRestrictionList =
Split(affordanceRestrictionString,
",");
172 std::vector<std::string> affordances;
177 affordances.push_back(
a->getName());
185 affordances.push_back(
a->getName());
189 ARMARX_INFO <<
"Configured affordances: " << affordances;
191 offeringTopic(getProperty<std::string>(
"AffordanceExtractionTopicName").getValue());
192 usingTopic(getProperty<std::string>(
"PrimitiveExtractionTopicName").getValue());
194 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
196 offeringTopic(getProperty<std::string>(
"DebugObserverName").getValue());
205 workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(getProperty<std::string>(
"WorkingMemoryName").getValue());
208 ARMARX_ERROR <<
"Failed to obtain working memory proxy";
215 ARMARX_ERROR <<
"Failed to obtain affordance segment pointer";
222 ARMARX_ERROR <<
"Failed to obtain environmental primitive segment pointer";
226 debugObserver = getTopic<DebugObserverInterfacePrx>(getProperty<std::string>(
"DebugObserverName").getValue());
228 listenerPrx = getTopic<AffordanceExtractionListenerPrx>(getProperty<std::string>(
"AffordanceExtractionTopicName").getValue());
243 void AffordanceExtraction::addObservation(
const PoseBasePtr& endEffectorPose,
const std::string& affordance,
const std::string& primitiveId,
float result,
float certainty,
float sigma_pos,
float sigma_rot,
const Ice::Current&
c)
248 Eigen::Matrix4f pose = PosePtr::dynamicCast(endEffectorPose)->toEigen();
256 ARMARX_INFO <<
"Adding Experiment(primitive=" << primitiveId <<
", affordance=" << affordance <<
", result=" << result <<
", certainty=" << certainty <<
", sigma_pos=" << sigma_pos <<
", sigma_rot=" << sigma_rot <<
")";
263 if (
a->getName() == affordance &&
a->existsForPrimitive(primitive))
265 a->addObservation(AffordanceKit::ObservationPtr(
new AffordanceKit::Observation(primitive, pose, result, certainty, sigma_pos, sigma_rot)));
272 if (
a->getName() == affordance &&
a->existsForPrimitive(primitive))
274 a->addObservation(AffordanceKit::ObservationPtr(
new AffordanceKit::Observation(primitive, pose, result, certainty, sigma_pos, sigma_rot)));
281 ARMARX_WARNING <<
"Discarding experiment, because affordance or primitive were not found.";
313 AffordanceKit::PrimitiveSetPtr primitives;
336 long originalTimestamp = 0;
337 if (primitives->size() > 0)
339 originalTimestamp = (*primitives->begin())->getTimestamp();
341 IceUtil::Time ts = IceUtil::Time::microSeconds(originalTimestamp);
342 std::string timestampString = ts.toDateTime().substr(ts.toDateTime().find(
' ') + 1);
344 ARMARX_INFO <<
"Processing new set of primitives (timestamp: " << timestampString <<
")";
348 ARMARX_INFO <<
"Primitives older than " << timestampString <<
" removed";
351 int spatialStepSize = getProperty<float>(
"SpatialSamplingDistance").getValue();
352 int numOrientationalSteps = getProperty<int>(
"NumOrientationalSamplings").getValue();
372 bool samplingNeeded =
true;
373 for (
auto& primitive : *primitives)
375 if (primitive->getSamplingSize() > 0)
377 samplingNeeded =
false;
383 ARMARX_INFO <<
"Ignoring primitive " << primitive->getId() <<
", sampling size " << primitive->getSamplingSize() <<
" is too large";
384 primitive->resetSampling();
392 ARMARX_INFO <<
"Sampling of primitives took " << (IceUtil::Time::now() - t).toMilliSeconds() <<
" ms";
404 a->evaluatePrimitiveSet(primitives);
405 ARMARX_INFO <<
"Evaluation of affordance '" <<
a->getName() <<
"' took " << (IceUtil::Time::now() - t).toMilliSeconds() <<
" ms";
414 a->evaluatePrimitiveSet(primitives);
415 ARMARX_INFO <<
"Evaluation of affordance '" <<
a->getName() <<
"' took " << (IceUtil::Time::now() - t).toMilliSeconds() <<
" ms";
419 ARMARX_INFO <<
"Total time for affordance extraction: " << (IceUtil::Time::now() - t).toMilliSeconds() <<
" ms";
426 ARMARX_INFO <<
"Affordance extraction interrupted (pipeline step disabled)";
431 t = IceUtil::Time::now();
435 std::string affordanceName =
"";
436 float uncertainty =
s.getTotalUncertainty(affordanceName);
437 float positiveDecisionRate =
s.getPositiveDecisionRate(affordanceName);
438 float negativeDecisionRate =
s.getNegativeDecisionRate(affordanceName);
439 float conflict =
s.getTotalConflict(affordanceName);
442 valueMap[
"uncertainty"] =
new Variant(uncertainty);
443 valueMap[
"positiveDecisionRate"] =
new Variant(positiveDecisionRate);
444 valueMap[
"negativeDecisionRate"] =
new Variant(negativeDecisionRate);
445 valueMap[
"conflict"] =
new Variant(conflict);
468 std::unique_lock lock(enableMutex);
490 std::unique_lock lock(timestampMutex);