26 #include <VirtualRobot/RobotNodeSet.h>
28 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
30 #include "GraspObjectGroupStatechartContext.generated.h"
35 using namespace GraspObjectGroup;
50 GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
51 context->getViewSelection()->activateAutomaticViewSelection();
54 std::string handName = in.getHandNameInMemory();
55 ChannelRefBasePtr handMemoryChannel =
56 context->getObjectMemoryObserver()->requestObjectClassRepeated(
57 handName, 150, armarx::DEFAULT_VIEWTARGET_PRIORITY);
59 if (handMemoryChannel)
61 handMemoryChannel->validate();
62 local.setHandMemoryChannel(ChannelRefPtr::dynamicCast(handMemoryChannel));
66 emitInitializingGraspingFailed();
71 std::string objectName =
"";
73 if (in.isObjectInstanceChannelSet())
76 objectName = in.getObjectInstanceChannel()->getDataField(
"className")->getString();
78 context->getWorkingMemory()->getObjectClassesSegment()->getEntityByName(objectName));
79 ChannelRefBasePtr objectMemoryChannel;
80 if (in.isPregivenObjectClassMemoryChannelSet())
82 objectMemoryChannel = in.getPregivenObjectClassMemoryChannel();
86 objectMemoryChannel = context->getObjectMemoryObserver()->requestObjectClassRepeated(
88 1000 / in.getObjectLocalizationFrequency(),
89 armarx::DEFAULT_VIEWTARGET_PRIORITY);
92 if (objectMemoryChannel)
94 local.setObjectMemoryChannel(ChannelRefPtr::dynamicCast(objectMemoryChannel));
98 ARMARX_WARNING <<
"Something went wrong when requesting " << objectName;
103 objectName = in.getObjectName();
104 ChannelRefBasePtr objectMemoryChannel;
105 if (in.isPregivenObjectClassMemoryChannelSet())
107 objectMemoryChannel = in.getPregivenObjectClassMemoryChannel();
111 objectMemoryChannel = context->getObjectMemoryObserver()->requestObjectClassRepeated(
113 1000 / in.getObjectLocalizationFrequency(),
114 armarx::DEFAULT_VIEWTARGET_PRIORITY);
116 if (objectMemoryChannel)
118 local.setObjectMemoryChannel(ChannelRefPtr::dynamicCast(objectMemoryChannel));
122 emitInitializingGraspingFailed();
127 std::string speechOutput =
"I will now grasp the " + objectName +
" with my ";
129 if (handName.find(
"left") != std::string::npos || handName.find(
"Left") != std::string::npos)
131 speechOutput +=
"left hand";
135 speechOutput +=
"right hand";
141 std::string kinematicChainName = in.getKinematicChainName();
142 std::string tcpName =
143 context->getRobot()->getRobotNodeSet(kinematicChainName)->getTCP()->getName();
144 local.setTcpNameInRobotModel(tcpName);
150 GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
154 if (!local.isHandMemoryChannelSet())
156 context->getObjectMemoryObserver()->releaseObjectClass(local.getHandMemoryChannel());
159 if (!in.isPregivenObjectClassMemoryChannelSet() && local.isObjectMemoryChannelSet())
161 context->getObjectMemoryObserver()->releaseObjectClass(local.getObjectMemoryChannel());
169 return "GraspObject";