27 #include "VisualServoGroupStatechartContext.generated.h"
38 #include <VirtualRobot/Grasping/Grasp.h>
39 #include <VirtualRobot/Grasping/GraspSet.h>
40 #include <VirtualRobot/ManipulationObject.h>
41 #include <VirtualRobot/XML/ObjectIO.h>
45 using namespace VisualServoGroup;
49 VisualServoTowardsObject::SubClassRegistry
62 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
63 local.setStartTimeRef(ChannelRefPtr::dynamicCast(
64 context->systemObserverPrx->startTimer(
"VisualServoTowardsObjectStartTime")));
67 std::string objectName;
68 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
69 context->getPriorKnowledge()->getObjectClassesSegment();
70 memoryx::CommonStorageInterfacePrx databasePrx =
71 context->getPriorKnowledge()->getCommonStorage();
73 memoryx::EntityBasePtr entity;
74 if (in.isPreselectedObjectInstanceChannelSet())
77 << in.getPreselectedObjectInstanceChannel()->output();
79 in.getPreselectedObjectInstanceChannel()->getDataField(
"className")->getString();
83 objectName = in.getObjectMemoryChannel()->getDataField(
"className")->getString();
85 entity = classesSegmentPrx->getEntityByName(objectName);
86 auto chainName = in.getKinematicChainName();
91 VirtualRobot::ManipulationObjectPtr mo = simoxWrapper->getManipulationObject();
93 auto tcpObjectClass = classesSegmentPrx->getObjectClassByName(in.getHandNameInMemory());
96 context->getEntityDrawerTopic()->setObjectVisu(
97 "VisualServoHandVisu",
"tcpTarget_" + chainName, tcpObjectClass,
new Pose());
98 context->getEntityDrawerTopic()->updateObjectTransparency(
99 "VisualServoHandVisu",
"tcpTarget_" + chainName, 0.3);
103 ARMARX_IMPORTANT <<
"Could not get objectclass for tcp " << in.getHandNameInMemory()
104 <<
" for visu purposes";
108 std::string graspSetName = getInput<std::string>(
"GraspSetName");
110 if (mo->getGraspSet(graspSetName))
112 std::string graspName = getInput<std::string>(
"GraspDefinitionName");
113 VirtualRobot::GraspPtr grasp = mo->getGraspSet(graspSetName)->getGrasp(graspName);
117 ARMARX_ERROR <<
"No grasp with name " << graspName <<
" found! ";
122 transformationFromObjectToTCPPose = grasp->getTransformation().inverse();
125 << grasp->getTransformation();
130 ARMARX_ERROR <<
"No grasp set with name " << graspSetName <<
" found! ";
134 Eigen::Matrix4f desiredTcpOffsetToObjectEigen = transformationFromObjectToTCPPose;
135 PosePtr desiredTcpOffsetToObject =
new Pose(desiredTcpOffsetToObjectEigen);
136 setLocal(
"DesiredTcpOffsetToObject", *desiredTcpOffsetToObject);
140 context->getTCPControlUnit()->request();
150 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
152 context->getTCPControlUnit()->release();
156 context->getDebugDrawerTopic()->removePoseDebugLayerVisu(
"objectPose");
157 context->systemObserverPrx->removeTimer(local.getStartTimeRef());
158 context->getEntityDrawerTopic()->removeLayer(
"VisualServoHandVisu");
165 return "VisualServoTowardsObject";