30 using namespace MotionControlGroup;
55 auto robot =
c->getLocalRobot();
56 auto sharedRobot =
c->getRobotStateComponent()->getSynchronizedRobot();
58 c->getTCPControlUnit()->request();
60 if (in.isTCPNameSet())
62 tcpName = in.getTCPName();
66 tcpName = robot->getRobotNodeSet(in.getKinematicChainName())->getTCP()->getName();
68 auto tcp = robot->getRobotNode(tcpName);
69 std::string kinematicChainName = in.getKinematicChainName();
71 FramedPosePtr startPose =
new FramedPose(tcp->getPoseInRootFrame(),
c->getRobot()->getRootNode()->getName(),
c->getRobot()->getName());
72 Eigen::Vector3f startPositionInRootFrame = startPose->toEigen().block<3, 1>(0, 3);
73 out.setStartPose(FramedPosePtr::dynamicCast(startPose->clone()));
75 float tcpVelocity = in.getTCPVelocity();
76 Eigen::Vector3f tcpDirectionInRootFrame = in.getMoveDirection()->toRootEigen(robot).normalized();
77 int sleepTimeMilliSec = int(1.0f / in.getControlFrequency() * 1000.0f);
78 bool keepOrientation = in.getKeepStartOrientation();
79 ARMARX_INFO <<
"Keeping orientation: " << keepOrientation;
81 while (!isRunningTaskStopped())
88 Eigen::Vector3f orientationDelta;
89 FramedPosePtr TCPDeltaToGoal = FramedPosePtr::dynamicCast(startPose->clone());
90 TCPDeltaToGoal->changeFrame(robot, tcpName);
91 VirtualRobot::MathTools::eigen4f2rpy(TCPDeltaToGoal->toEigen(), orientationDelta);
92 orientationVel =
new FramedDirection(orientationDelta * 10, tcpName, robot->getName());
95 VirtualRobot::MathTools::eigen4f2axisangle(TCPDeltaToGoal->toEigen(), axis, angleError);
100 Eigen::Vector3f currentTargetPosition = startPositionInRootFrame + timePassed * tcpVelocity * tcpDirectionInRootFrame;
101 positionVel =
new FramedDirection(currentTargetPosition - tcp->getPositionInRootFrame(), robot->getRootNode()->getName(), robot->getName());
103 float distanceTravelled = (tcp->getPositionInRootFrame() - startPositionInRootFrame).
norm();
105 if (distanceTravelled >= in.getMaxDistance())
109 c->getTCPControlUnit()->release();
112 c->getTCPControlUnit()->setTCPVelocity(kinematicChainName, tcpName, positionVel, orientationVel);
117 c->getTCPControlUnit()->setTCPVelocity(kinematicChainName, tcpName, zeroVelocity, zeroVelocity);
119 c->getTCPControlUnit()->release();
124 float distanceTravelled = (tcp->getPositionInRootFrame() - startPositionInRootFrame).
norm();
126 out.setDistanceTravelled(distanceTravelled);
128 FramedPosePtr TCPDeltaToGoal = FramedPosePtr::dynamicCast(startPose->clone());
129 TCPDeltaToGoal->changeFrame(robot, tcpName);
130 Eigen::Vector3f axis;
131 float angleError = 0;
132 VirtualRobot::MathTools::eigen4f2axisangle(TCPDeltaToGoal->toEigen(), axis, angleError);
141 waitForRunningTaskToFinish();