26 #include <VirtualRobot/IK/DifferentialIK.h>
27 #include <VirtualRobot/LinkedCoordinate.h>
30 using namespace FindAndGraspObjectGroup;
45 ControlMode controlMode = ePositionControl;
59 ChannelRefPtr markerChannel = getInput<ChannelRef>(
"markerChannel");
162 std::string robotNodeSetName = getInput<std::string>(
"kinematicChain");
163 std::string tcpNodeName = getInput<std::string>(
"tcpName");
164 ARMARX_DEBUG <<
"robot node set: " << robotNodeSetName <<
", tcp: " << tcpNodeName;
166 VirtualRobot::RobotNodeSetPtr robotNodeSet = localRobot->getRobotNodeSet(robotNodeSetName);
167 VirtualRobot::RobotNodePtr tcpNode = localRobot->getRobotNode(tcpNodeName);
172 PosePtr rnPose = PosePtr::dynamicCast(context->simulatorProxy->getRobotNodePose(localRobot->getName(), tcpNodeName));
201 FramedPosePtr targetFramedPose = getInput<FramedPose>(
"targetPose");
204 Eigen::Matrix4f targetGlobalPose = localRobot->getRobotNode(targetFramedPose->getFrame())->toGlobalCoordinateSystem(targetPose);
212 std::string refFrame = targetFramedPose->getFrame();
220 Eigen::VectorXf errorCartVec(6);
221 ARMARX_DEBUG <<
"target: " << targetGlobalPose.block(0, 3, 3, 1).transpose();
222 ARMARX_DEBUG <<
"tcp: " << tcpGlobalPose.block(0, 3, 3, 1).transpose();
223 errorCartVec.block(0, 0, 3, 1) = targetGlobalPose.block(0, 3, 3, 1) - tcpGlobalPose.block(0, 3, 3, 1);
226 Eigen::Matrix4f orientation = targetGlobalPose * tcpGlobalPose.inverse();
227 Eigen::AngleAxis<float> aa(orientation.block<3, 3>(0, 0));
228 errorCartVec.tail(3) = aa.axis() * aa.angle();
230 ARMARX_DEBUG <<
"Cartesian error (RAW)" << errorCartVec.transpose();
233 float distance = errorCartVec.head(3).norm();
244 float stepSize = getInput<float>(
"stepSize");
245 errorCartVec = errorCartVec * stepSize;
247 float IKCutCartErrorMM = getInput<float>(
"IKCutCartErrorMM");
249 if (errorCartVec.head(3).norm() > IKCutCartErrorMM)
251 errorCartVec = errorCartVec / errorCartVec.head(3).norm() * IKCutCartErrorMM;
255 ARMARX_DEBUG <<
"Cartesian error (SCALED, cut:" << IKCutCartErrorMM <<
" mm)" << errorCartVec.transpose();
257 bool useOrientation = getInput<bool>(
"useOrientation");
260 VirtualRobot::DifferentialIK dIK(robotNodeSet);
262 Eigen::VectorXf errorJoint(robotNodeSet->getSize());
271 startTime = IceUtil::Time::now();
273 Eigen::MatrixXf Ji = dIK.getPseudoInverseJacobianMatrix(tcpNode, VirtualRobot::IKSolver::All);
275 endTime = IceUtil::Time::now();
279 errorJoint = Ji * errorCartVec;
283 startTime = IceUtil::Time::now();
289 endTime = IceUtil::Time::now();
294 Eigen::VectorXf errorPosition(3);
295 errorPosition(0) = errorCartVec(0);
296 errorPosition(1) = errorCartVec(1);
297 errorPosition(2) = errorCartVec(2);
301 errorJoint = Ji * errorPosition;
306 if (
interval.toMilliSeconds() > 80.0)
308 float diffClock = (
float)(((
float)(endT - startT) / (
float)CLOCKS_PER_SEC) * 1000.0f);
309 ARMARX_WARNING <<
"Jacobi calculation time:" <<
interval.toMilliSeconds() <<
" ms (wall time!). Pure CPU time:" << diffClock <<
"ms";
312 float VEL_GAIN = 1.0f;
313 float VEL_MAX_COEFF = 1.0f;
314 ARMARX_DEBUG <<
"JointVelocities " << errorJoint.transpose();
315 ARMARX_DEBUG <<
"JointVelocities GAIN" << errorJoint.transpose() * VEL_GAIN;
316 float maxV = fabs(errorJoint.maxCoeff());
318 if (maxV > VEL_MAX_COEFF)
320 errorJoint = errorJoint / maxV * VEL_MAX_COEFF;
321 ARMARX_DEBUG <<
"JointVelocities VEL_MAX_COEFF" << errorJoint.transpose() * VEL_GAIN;
328 NameControlModeMap controlModes;
329 const std::vector< VirtualRobot::RobotNodePtr > nodes = robotNodeSet->getAllRobotNodes();
331 for (
size_t i = 0; i < nodes.size(); i++)
333 VirtualRobot::RobotNodePtr n = nodes[i];
334 targetVelocities[n->getName()] = errorJoint(i) * VEL_GAIN;
335 targetAngles[n->getName()] = n->getJointValue() + errorJoint(i);
336 controlModes[n->getName()] = controlMode;
343 case ePositionControl:
349 case eVelocityControl:
354 case ePositionVelocityControl:
370 sendEvent<EvCalcVelocitiesDone>();
383 VirtualRobot::LinkedCoordinate markerPose
386 return markerPose.getInFrame(refFrame);
392 return "CalcVelocities";