27 #include "GraspObjectGroupStatechartContext.generated.h"
31 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
35 using namespace GraspObjectGroup;
53 GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
54 context->getViewSelection()->activateAutomaticViewSelection();
57 std::string handName = in.getHandNameInMemory();
58 ChannelRefBasePtr handMemoryChannel = context->getObjectMemoryObserver()->requestObjectClassRepeated(handName, 150, armarx::DEFAULT_VIEWTARGET_PRIORITY);
60 if (handMemoryChannel)
62 handMemoryChannel->validate();
63 local.setHandMemoryChannel(ChannelRefPtr::dynamicCast(handMemoryChannel));
67 emitInitializingGraspingFailed();
72 std::string objectName =
"";
74 if (in.isObjectInstanceChannelSet())
77 objectName = in.getObjectInstanceChannel()->getDataField(
"className")->getString();
78 memoryx::ObjectClassPtr obj = memoryx::ObjectClassPtr::dynamicCast(context->getWorkingMemory()->getObjectClassesSegment()->getEntityByName(objectName));
79 ChannelRefBasePtr objectMemoryChannel;
80 if (in.isPregivenObjectClassMemoryChannelSet())
82 objectMemoryChannel = in.getPregivenObjectClassMemoryChannel();
86 objectMemoryChannel = context->getObjectMemoryObserver()->requestObjectClassRepeated(objectName, 1000 / in.getObjectLocalizationFrequency(), armarx::DEFAULT_VIEWTARGET_PRIORITY);
89 if (objectMemoryChannel)
91 local.setObjectMemoryChannel(ChannelRefPtr::dynamicCast(objectMemoryChannel));
95 ARMARX_WARNING <<
"Something went wrong when requesting " << objectName;
100 objectName = in.getObjectName();
101 ChannelRefBasePtr objectMemoryChannel;
102 if (in.isPregivenObjectClassMemoryChannelSet())
104 objectMemoryChannel = in.getPregivenObjectClassMemoryChannel();
108 objectMemoryChannel = context->getObjectMemoryObserver()->requestObjectClassRepeated(objectName, 1000 / in.getObjectLocalizationFrequency(), armarx::DEFAULT_VIEWTARGET_PRIORITY);
110 if (objectMemoryChannel)
112 local.setObjectMemoryChannel(ChannelRefPtr::dynamicCast(objectMemoryChannel));
116 emitInitializingGraspingFailed();
121 std::string speechOutput =
"I will now grasp the " + objectName +
" with my ";
123 if (handName.find(
"left") != std::string::npos || handName.find(
"Left") != std::string::npos)
125 speechOutput +=
"left hand";
129 speechOutput +=
"right hand";
135 std::string kinematicChainName = in.getKinematicChainName();
136 std::string tcpName = context->getRobot()->getRobotNodeSet(kinematicChainName)->getTCP()->getName();
137 local.setTcpNameInRobotModel(tcpName);
147 GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
151 if (!local.isHandMemoryChannelSet())
153 context->getObjectMemoryObserver()->releaseObjectClass(local.getHandMemoryChannel());
156 if (!in.isPregivenObjectClassMemoryChannelSet() && local.isObjectMemoryChannelSet())
158 context->getObjectMemoryObserver()->releaseObjectClass(local.getObjectMemoryChannel());
167 return "GraspObject";