27 #include "VisualServoGroupStatechartContext.generated.h"
38 #include <VirtualRobot/ManipulationObject.h>
39 #include <VirtualRobot/Grasping/Grasp.h>
40 #include <VirtualRobot/Grasping/GraspSet.h>
41 #include <VirtualRobot/XML/ObjectIO.h>
46 using namespace VisualServoGroup;
63 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
64 local.setStartTimeRef(ChannelRefPtr::dynamicCast(context->systemObserverPrx->startTimer(
"VisualServoTowardsObjectStartTime")));
67 std::string objectName;
68 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx = context->getPriorKnowledge()->getObjectClassesSegment();
69 memoryx::CommonStorageInterfacePrx databasePrx = context->getPriorKnowledge()->getCommonStorage();
71 memoryx::EntityBasePtr entity;
72 if (in.isPreselectedObjectInstanceChannelSet())
74 ARMARX_INFO <<
"Using preselected instance " << in.getPreselectedObjectInstanceChannel()->output();
75 objectName = in.getPreselectedObjectInstanceChannel()->getDataField(
"className")->getString();
79 objectName = in.getObjectMemoryChannel()->getDataField(
"className")->getString();
81 entity = classesSegmentPrx->getEntityByName(objectName);
82 auto chainName = in.getKinematicChainName();
86 VirtualRobot::ManipulationObjectPtr mo = simoxWrapper->getManipulationObject();
88 auto tcpObjectClass = classesSegmentPrx->getObjectClassByName(in.getHandNameInMemory());
91 context->getEntityDrawerTopic()->setObjectVisu(
"VisualServoHandVisu",
"tcpTarget_" + chainName, tcpObjectClass,
new Pose());
92 context->getEntityDrawerTopic()->updateObjectTransparency(
"VisualServoHandVisu",
"tcpTarget_" + chainName, 0.3);
96 ARMARX_IMPORTANT <<
"Could not get objectclass for tcp " << in.getHandNameInMemory() <<
" for visu purposes";
100 std::string graspSetName = getInput<std::string>(
"GraspSetName");
102 if (mo->getGraspSet(graspSetName))
104 std::string graspName = getInput<std::string>(
"GraspDefinitionName");
105 VirtualRobot::GraspPtr grasp = mo->getGraspSet(graspSetName)->getGrasp(graspName);
109 ARMARX_ERROR <<
"No grasp with name " << graspName <<
" found! ";
114 transformationFromObjectToTCPPose = grasp->getTransformation().inverse();
116 ARMARX_VERBOSE <<
"Grasp " << graspName <<
" has value:\n" << grasp->getTransformation();
121 ARMARX_ERROR <<
"No grasp set with name " << graspSetName <<
" found! ";
125 Eigen::Matrix4f desiredTcpOffsetToObjectEigen = transformationFromObjectToTCPPose;
126 PosePtr desiredTcpOffsetToObject =
new Pose(desiredTcpOffsetToObjectEigen);
127 setLocal(
"DesiredTcpOffsetToObject", *desiredTcpOffsetToObject);
131 context->getTCPControlUnit()->request();
146 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
148 context->getTCPControlUnit()->release();
152 context->getDebugDrawerTopic()->removePoseDebugLayerVisu(
"objectPose");
153 context->systemObserverPrx->removeTimer(local.getStartTimeRef());
154 context->getEntityDrawerTopic()->removeLayer(
"VisualServoHandVisu");
162 return "VisualServoTowardsObject";