26 #include "VisualServoGroupStatechartContext.generated.h"
31 using namespace VisualServoGroup;
45 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
50 if (in.isObjectInstanceChannelSet())
52 objectInstance = in.getObjectInstanceChannel();
54 else if (in.isObjectClassChannelSet())
56 ChannelRefPtr objectMemoryChannel = in.getObjectClassChannel();
58 if (!context->getObjectMemoryObserver())
61 setTimeoutEvent(500, createEventObjectNotYetLocalized());
65 memoryx::ChannelRefBaseSequence instances = context->getObjectMemoryObserver()->getObjectInstances(objectMemoryChannel);
67 if (instances.size() == 0)
69 ARMARX_WARNING <<
"No instances of the object in the memory - obj channel: " << objectMemoryChannel->output();
70 setTimeoutEvent(500, createEventObjectNotYetLocalized());
74 objectInstance = ChannelRefPtr::dynamicCast(instances.front());
79 throw LocalException(
"Either ObjectInstanceChannel or ObjectMemoryChannel must be set in " + getStateClassName());
86 out.setObjectInstanceChannel(objectInstance);
87 ARMARX_INFO <<
"Checking existenceCertainty: " << objectInstance->getDataField(
"existenceCertainty")->getFloat() <<
" > " << in.getMinimumExistenceCertainty();
88 ARMARX_INFO <<
"Checking positionUncertainty: " << objectInstance->get<
float>(
"uncertaintyOfPosition") <<
" < " << in.getMaximalPositionUncertainty();
90 float existenceCertainty = objectInstance->getDataField(
"existenceCertainty")->getFloat();
91 if (existenceCertainty >= in.getMinimumExistenceCertainty())
93 float positionUncertainty = objectInstance->get<
float>(
"uncertaintyOfPosition");
95 if (existenceCertainty >= in.getGoodExistenceCertainty() && positionUncertainty <= in.getMaximalPositionUncertainty())
97 if (in.getRequestTCPControlUnit())
99 getTcpControlUnit()->request();
101 emitObjectInstanceChannelFound();
105 ARMARX_VERBOSE <<
"Waiting for better localization. Existence certainty: " << existenceCertainty <<
" (min: " << in.getGoodExistenceCertainty()
106 <<
"), position uncertainty: " << positionUncertainty <<
" (max: " << in.getMaximalPositionUncertainty() <<
")";
107 if (in.getRequestTCPControlUnit())
109 getTcpControlUnit()->release();
112 emitWaitForBetterLocalization();
117 ARMARX_WARNING <<
"Object was found earlier but is lost now: Existence certainty is only " << existenceCertainty;
118 emitObjectNotFound();