7 #include <VirtualRobot/IK/DifferentialIK.h>
8 #include <VirtualRobot/MathTools.h>
9 #include <VirtualRobot/Nodes/RobotNode.h>
10 #include <VirtualRobot/Nodes/Sensor.h>
11 #include <VirtualRobot/Robot.h>
12 #include <VirtualRobot/RobotNodeSet.h>
25 NJointControllerRegistration<NJointBimanualForceController>
30 const armarx::NJointControllerConfigPtr& config,
35 cfg = NJointBimanualForceControllerConfigPtr::dynamicCast(config);
39 leftRNS =
rtGetRobot()->getRobotNodeSet(
"LeftArm");
41 for (
size_t i = 0; i < leftRNS->getSize(); ++i)
43 std::string jointName = leftRNS->getNode(i)->getName();
44 leftJointNames.push_back(jointName);
47 leftTargets.push_back(ct->
asA<ControlTarget1DoFActuatorTorque>());
48 const SensorValue1DoFActuatorVelocity* velocitySensor =
49 sv->
asA<SensorValue1DoFActuatorVelocity>();
50 const SensorValue1DoFActuatorPosition* positionSensor =
51 sv->
asA<SensorValue1DoFActuatorPosition>();
63 leftVelocitySensors.push_back(velocitySensor);
64 leftPositionSensors.push_back(positionSensor);
67 rightRNS =
rtGetRobot()->getRobotNodeSet(
"RightArm");
69 for (
size_t i = 0; i < rightRNS->getSize(); ++i)
71 std::string jointName = rightRNS->getNode(i)->getName();
72 rightJointNames.push_back(jointName);
75 rightTargets.push_back(ct->
asA<ControlTarget1DoFActuatorTorque>());
77 const SensorValue1DoFActuatorVelocity* velocitySensor =
78 sv->
asA<SensorValue1DoFActuatorVelocity>();
79 const SensorValue1DoFActuatorPosition* positionSensor =
80 sv->
asA<SensorValue1DoFActuatorPosition>();
91 rightVelocitySensors.push_back(velocitySensor);
92 rightPositionSensors.push_back(positionSensor);
97 const SensorValueBase* svlf = robUnit->getSensorDevice(
"FT L")->getSensorValue();
100 const SensorValueBase* svrf = robUnit->getSensorDevice(
"FT R")->getSensorValue();
103 leftIK.reset(
new VirtualRobot::DifferentialIK(
104 leftRNS, leftRNS->getRobot()->getRootNode(), VirtualRobot::JacobiProvider::eSVDDamped));
105 rightIK.reset(
new VirtualRobot::DifferentialIK(rightRNS,
106 rightRNS->getRobot()->getRootNode(),
107 VirtualRobot::JacobiProvider::eSVDDamped));
113 taskSpaceDMPConfig.
DMPMode = cfg->dmpMode;
114 taskSpaceDMPConfig.
DMPStyle = cfg->dmpType;
130 tcpLeft = leftRNS->getTCP();
131 tcpRight = rightRNS->getTCP();
133 KpImpedance.resize(cfg->KpImpedance.size());
136 for (
int i = 0; i < KpImpedance.size(); ++i)
138 KpImpedance(i) = cfg->KpImpedance.at(i);
141 KdImpedance.resize(cfg->KdImpedance.size());
144 for (
int i = 0; i < KdImpedance.size(); ++i)
146 KdImpedance(i) = cfg->KdImpedance.at(i);
149 KpAdmittance.resize(cfg->KpAdmittance.size());
152 for (
int i = 0; i < KpAdmittance.size(); ++i)
154 KpAdmittance(i) = cfg->KpAdmittance.at(i);
157 KdAdmittance.resize(cfg->KdAdmittance.size());
160 for (
int i = 0; i < KdAdmittance.size(); ++i)
162 KdAdmittance(i) = cfg->KdAdmittance.at(i);
165 KmAdmittance.resize(cfg->KmAdmittance.size());
168 for (
int i = 0; i < KmAdmittance.size(); ++i)
170 KmAdmittance(i) = cfg->KmAdmittance.at(i);
173 leftDesiredJointValues.resize(leftTargets.size());
176 for (
size_t i = 0; i < leftTargets.size(); ++i)
178 leftDesiredJointValues(i) = cfg->leftDesiredJointValues.at(i);
181 rightDesiredJointValues.resize(rightTargets.size());
184 for (
size_t i = 0; i < rightTargets.size(); ++i)
186 rightDesiredJointValues(i) = cfg->rightDesiredJointValues.at(i);
189 KmPID.resize(cfg->KmPID.size());
192 for (
int i = 0; i < KmPID.size(); ++i)
194 KmPID(i) = cfg->KmPID.at(i);
198 modifiedAcc.setZero(12);
199 modifiedTwist.setZero(12);
203 boxInitialPose = VirtualRobot::MathTools::quat2eigen4f(cfg->boxInitialPose[4],
204 cfg->boxInitialPose[5],
205 cfg->boxInitialPose[6],
206 cfg->boxInitialPose[3]);
207 for (
int i = 0; i < 3; ++i)
209 boxInitialPose(i, 3) = cfg->boxInitialPose[i];
212 NJointBimanualForceControllerSensorData initSensorData;
213 initSensorData.deltaT = 0;
214 initSensorData.currentTime = 0;
215 initSensorData.currentPose = boxInitialPose;
216 initSensorData.currentTwist.setZero();
220 NJointBimanualForceControllerInterfaceData initInterfaceData;
221 initInterfaceData.currentLeftPose = tcpLeft->getPoseInRootFrame();
222 initInterfaceData.currentRightPose = tcpRight->getPoseInRootFrame();
225 leftInitialPose = boxInitialPose;
226 leftInitialPose(0, 3) -= cfg->boxWidth;
227 rightInitialPose = boxInitialPose;
228 rightInitialPose(0, 3) += cfg->boxWidth;
230 forcePIDControllers.resize(12);
231 for (
size_t i = 0; i < 6; i++)
234 cfg->forceP[i], cfg->forceI[i], cfg->forceD[i], cfg->forcePIDLimits[i]));
236 cfg->forceP[i], cfg->forceI[i], cfg->forceD[i], cfg->forcePIDLimits[i]));
237 forcePIDControllers.at(i)->reset();
238 forcePIDControllers.at(i + 6)->reset();
242 filterCoeff = cfg->filterCoeff;
244 filteredOldValue.setZero(12);
247 massLeft = cfg->massLeft;
248 CoMVecLeft << cfg->CoMVecLeft[0], cfg->CoMVecLeft[1], cfg->CoMVecLeft[2];
249 forceOffsetLeft << cfg->forceOffsetLeft[0], cfg->forceOffsetLeft[1],
250 cfg->forceOffsetLeft[2];
251 torqueOffsetLeft << cfg->torqueOffsetLeft[0], cfg->torqueOffsetLeft[1],
252 cfg->torqueOffsetLeft[2];
254 massRight = cfg->massRight;
255 CoMVecRight << cfg->CoMVecRight[0], cfg->CoMVecRight[1], cfg->CoMVecRight[2];
256 forceOffsetRight << cfg->forceOffsetRight[0], cfg->forceOffsetRight[1],
257 cfg->forceOffsetRight[2];
258 torqueOffsetRight << cfg->torqueOffsetRight[0], cfg->torqueOffsetRight[1],
259 cfg->torqueOffsetRight[2];
261 sensorFrame2TcpFrameLeft.setZero();
262 sensorFrame2TcpFrameRight.setZero();
265 initData.
boxPose = boxInitialPose;
271 << leftInitialPose <<
"\n right initial pose: \n"
279 targetWrench.setZero(cfg->targetWrench.size());
280 for (
size_t i = 0; i < cfg->targetWrench.size(); ++i)
282 targetWrench(i) = cfg->targetWrench[i];
289 return "NJointBimanualForceController";
315 Eigen::VectorXf currentTwist = controllerSensorData.
getReadBuffer().currentTwist;
317 if (objectDMP->canVal < 1e-8)
322 objectDMP->flow(deltaT, currentPose, currentTwist);
336 modifiedLeftPose = tcpLeft->getPoseInRootFrame();
337 modifiedRightPose = tcpRight->getPoseInRootFrame();
338 modifiedLeftPose.block<3, 1>(0, 3) = modifiedLeftPose.block<3, 1>(0, 3) * 0.001;
339 modifiedRightPose.block<3, 1>(0, 3) = modifiedRightPose.block<3, 1>(0, 3) * 0.001;
342 rtGetRobot()->getSensor(
"FT L")->getRobotNode()->getPoseInRootFrame();
344 rtGetRobot()->getSensor(
"FT R")->getRobotNode()->getPoseInRootFrame();
345 leftSensorFrame.block<3, 1>(0, 3) = leftSensorFrame.block<3, 1>(0, 3) * 0.001;
346 rightSensorFrame.block<3, 1>(0, 3) = rightSensorFrame.block<3, 1>(0, 3) * 0.001;
348 sensorFrame2TcpFrameLeft.block<3, 3>(0, 0) =
349 modifiedLeftPose.block<3, 3>(0, 0).transpose() * leftSensorFrame.block<3, 3>(0, 0);
350 sensorFrame2TcpFrameRight.block<3, 3>(0, 0) =
351 modifiedRightPose.block<3, 3>(0, 0).transpose() *
352 rightSensorFrame.block<3, 3>(0, 0);
353 CoMVecLeft = sensorFrame2TcpFrameLeft.block<3, 3>(0, 0) * CoMVecLeft;
354 CoMVecRight = sensorFrame2TcpFrameRight.block<3, 3>(0, 0) * CoMVecRight;
356 ARMARX_INFO <<
"modified left pose:\n " << modifiedLeftPose;
357 ARMARX_INFO <<
"modified right pose:\n " << modifiedRightPose;
359 double deltaT = timeSinceLastIteration.toSecondsDouble();
363 Eigen::Vector3f rToBoxCoM;
364 rToBoxCoM << cfg->boxWidth, 0, 0;
369 interfaceData.
getWriteBuffer().currentRightPose = currentRightPose;
372 Eigen::VectorXf currentTargetWrench = targetWrench;
373 if (fabs(currentLeftPose(0, 3) - currentRightPose(0, 3)) < 0.8 * 2 * cfg->boxWidth)
375 currentTargetWrench.setZero();
377 currentLeftPose.block<3, 1>(0, 3) = 0.001 * currentLeftPose.block<3, 1>(0, 3);
378 currentRightPose.block<3, 1>(0, 3) = 0.001 * currentRightPose.block<3, 1>(0, 3);
379 Eigen::MatrixXf graspMatrix;
380 graspMatrix.setZero(6, 12);
383 Eigen::Vector3f r = -currentLeftPose.block<3, 3>(0, 0) * rToBoxCoM;
384 graspMatrix(4, 2) = -r(0);
385 graspMatrix(3, 2) = r(1);
386 graspMatrix(3, 1) = -r(2);
387 graspMatrix(4, 0) = r(2);
388 graspMatrix(5, 0) = -r(1);
389 graspMatrix(5, 1) = r(0);
390 r = currentRightPose.block<3, 3>(0, 0) * rToBoxCoM;
391 graspMatrix(4, 8) = -r(0);
392 graspMatrix(3, 8) = r(1);
393 graspMatrix(3, 7) = -r(2);
394 graspMatrix(4, 6) = r(2);
395 graspMatrix(5, 6) = -r(1);
396 graspMatrix(5, 7) = r(0);
398 Eigen::MatrixXf pinvG = leftIK->computePseudoInverseJacobianMatrix(graspMatrix, 0);
399 Eigen::MatrixXf G_range = pinvG * graspMatrix;
404 boxCurrentPose.block<3, 1>(0, 3) =
405 0.5 * (currentLeftPose.block<3, 1>(0, 3) + currentRightPose.block<3, 1>(0, 3));
406 Eigen::VectorXf boxCurrentTwist;
407 boxCurrentTwist.setZero(6);
412 Eigen::MatrixXf jacobiL =
413 leftIK->getJacobianMatrix(tcpLeft, VirtualRobot::IKSolver::CartesianSelection::All);
415 Eigen::VectorXf leftqpos;
416 Eigen::VectorXf leftqvel;
417 leftqpos.resize(leftPositionSensors.size());
418 leftqvel.resize(leftVelocitySensors.size());
419 for (
size_t i = 0; i < leftVelocitySensors.size(); ++i)
421 leftqpos(i) = leftPositionSensors[i]->position;
422 leftqvel(i) = leftVelocitySensors[i]->velocity;
425 Eigen::MatrixXf jacobiR =
426 rightIK->getJacobianMatrix(tcpRight, VirtualRobot::IKSolver::CartesianSelection::All);
429 jacobiL.block<3, 8>(0, 0) = 0.001 * jacobiL.block<3, 8>(0, 0);
430 jacobiR.block<3, 8>(0, 0) = 0.001 * jacobiR.block<3, 8>(0, 0);
432 Eigen::VectorXf rightqpos;
433 Eigen::VectorXf rightqvel;
434 rightqpos.resize(rightPositionSensors.size());
435 rightqvel.resize(rightVelocitySensors.size());
437 for (
size_t i = 0; i < rightVelocitySensors.size(); ++i)
439 rightqpos(i) = rightPositionSensors[i]->position;
440 rightqvel(i) = rightVelocitySensors[i]->velocity;
444 Eigen::VectorXf currentLeftTwist = jacobiL * leftqvel;
445 Eigen::VectorXf currentRightTwist = jacobiR * rightqvel;
446 Eigen::VectorXf currentTwist(12);
447 currentTwist << currentLeftTwist, currentRightTwist;
448 Eigen::MatrixXf pinvGraspMatrixT =
449 leftIK->computePseudoInverseJacobianMatrix(graspMatrix.transpose(), 0);
450 boxCurrentTwist = pinvGraspMatrixT * currentTwist;
453 controllerSensorData.
getWriteBuffer().currentPose = boxCurrentPose;
454 controllerSensorData.
getWriteBuffer().currentTwist = boxCurrentTwist;
463 Eigen::VectorXf leftJointControlWrench;
464 Eigen::VectorXf rightJointControlWrench;
476 Eigen::VectorXf twistDMP = graspMatrix.transpose() * boxTwist;
477 Eigen::VectorXf deltaInitialPose = deltaT * twistDMP;
478 leftInitialPose.block<3, 1>(0, 3) =
479 leftInitialPose.block<3, 1>(0, 3) + deltaInitialPose.block<3, 1>(0, 0);
480 rightInitialPose.block<3, 1>(0, 3) =
481 rightInitialPose.block<3, 1>(0, 3) + deltaInitialPose.block<3, 1>(6, 0);
482 leftInitialPose.block<3, 3>(0, 0) =
483 VirtualRobot::MathTools::rpy2eigen3f(
484 deltaInitialPose(3), deltaInitialPose(4), deltaInitialPose(5)) *
485 leftInitialPose.block<3, 3>(0, 0);
486 rightInitialPose.block<3, 3>(0, 0) =
487 VirtualRobot::MathTools::rpy2eigen3f(
488 deltaInitialPose(9), deltaInitialPose(10), deltaInitialPose(11)) *
489 rightInitialPose.block<3, 3>(0, 0);
493 Eigen::Vector3f gravity;
494 gravity << 0.0, 0.0, -9.8;
495 Eigen::Vector3f localGravityLeft = currentLeftPose.block<3, 3>(0, 0).
transpose() * gravity;
496 Eigen::Vector3f localForceVecLeft = massLeft * localGravityLeft;
497 Eigen::Vector3f localTorqueVecLeft = CoMVecLeft.cross(localForceVecLeft);
499 Eigen::Vector3f localGravityRight =
500 currentRightPose.block<3, 3>(0, 0).
transpose() * gravity;
501 Eigen::Vector3f localForceVecRight = massRight * localGravityRight;
502 Eigen::Vector3f localTorqueVecRight = CoMVecRight.cross(localForceVecRight);
505 Eigen::VectorXf wrenchesMeasured(12);
506 wrenchesMeasured << leftForceTorque->
force - forceOffsetLeft,
507 leftForceTorque->
torque - torqueOffsetLeft, rightForceTorque->
force - forceOffsetRight,
508 rightForceTorque->
torque - torqueOffsetRight;
509 for (
size_t i = 0; i < 12; i++)
511 wrenchesMeasured(i) =
512 (1 - filterCoeff) * wrenchesMeasured(i) + filterCoeff * filteredOldValue(i);
514 filteredOldValue = wrenchesMeasured;
515 wrenchesMeasured.block<3, 1>(0, 0) =
516 sensorFrame2TcpFrameLeft.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(0, 0) -
518 wrenchesMeasured.block<3, 1>(3, 0) =
519 sensorFrame2TcpFrameLeft.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(3, 0) -
521 wrenchesMeasured.block<3, 1>(6, 0) =
522 sensorFrame2TcpFrameRight.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(6, 0) -
524 wrenchesMeasured.block<3, 1>(9, 0) =
525 sensorFrame2TcpFrameRight.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(9, 0) -
527 if (wrenchesMeasured.norm() < cfg->forceThreshold)
529 wrenchesMeasured.setZero();
538 Eigen::VectorXf forcePID(12);
548 for (
size_t i = 0; i < 6; i++)
550 forcePID(i) = cfg->forceP[i] * (currentTargetWrench(i) - wrenchesMeasured(i));
552 cfg->forceP[i] * (currentTargetWrench(i + 6) - wrenchesMeasured(i + 6));
554 Eigen::VectorXf forcePIDInRoot(12);
555 forcePIDInRoot.block<3, 1>(0, 0) =
556 currentLeftPose.block<3, 3>(0, 0) * forcePID.block<3, 1>(0, 0);
557 forcePIDInRoot.block<3, 1>(3, 0) =
558 currentLeftPose.block<3, 3>(0, 0) * forcePID.block<3, 1>(3, 0);
559 forcePIDInRoot.block<3, 1>(6, 0) =
560 currentRightPose.block<3, 3>(0, 0) * forcePID.block<3, 1>(6, 0);
561 forcePIDInRoot.block<3, 1>(9, 0) =
562 currentRightPose.block<3, 3>(0, 0) * forcePID.block<3, 1>(9, 0);
565 Eigen::VectorXf forcePIDInRootForDebug = forcePIDInRoot;
567 Eigen::VectorXf wrenchesMeasuredInRoot(12);
568 wrenchesMeasuredInRoot.block<3, 1>(0, 0) =
569 currentLeftPose.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(0, 0);
570 wrenchesMeasuredInRoot.block<3, 1>(3, 0) =
571 currentLeftPose.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(3, 0);
572 wrenchesMeasuredInRoot.block<3, 1>(6, 0) =
573 currentRightPose.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(6, 0);
574 wrenchesMeasuredInRoot.block<3, 1>(9, 0) =
575 currentRightPose.block<3, 3>(0, 0) * wrenchesMeasured.block<3, 1>(9, 0);
576 Eigen::VectorXf wrenchesConstrained = PG * wrenchesMeasuredInRoot;
581 Eigen::VectorXf poseError(12);
582 poseError.block<3, 1>(0, 0) =
583 leftInitialPose.block<3, 1>(0, 3) - modifiedLeftPose.block<3, 1>(0, 3);
585 leftInitialPose.block<3, 3>(0, 0) * modifiedLeftPose.block<3, 3>(0, 0).transpose();
586 poseError.block<3, 1>(3, 0) = VirtualRobot::MathTools::eigen3f2rpy(diffMat);
587 poseError.block<3, 1>(6, 0) =
588 rightInitialPose.block<3, 1>(0, 3) - modifiedRightPose.block<3, 1>(0, 3);
590 rightInitialPose.block<3, 3>(0, 0) * modifiedRightPose.block<3, 3>(0, 0).transpose();
591 poseError.block<3, 1>(9, 0) = VirtualRobot::MathTools::eigen3f2rpy(diffMat);
594 Eigen::VectorXf twist;
597 for (
size_t i = 0; i < 6; i++)
601 acc(i) = KpAdmittance(i) * poseError(i) - KdAdmittance(i) * modifiedTwist(i) -
602 KmAdmittance(i) * wrenchesConstrained(i) - KmPID(i) * forcePIDInRoot(i);
604 KpAdmittance(i) * poseError(i + 6) - KdAdmittance(i) * modifiedTwist(i + 6) -
605 KmAdmittance(i) * wrenchesConstrained(i + 6) - KmPID(i) * forcePIDInRoot(i + 6);
607 twist = modifiedTwist + 0.5 * deltaT * (acc + modifiedAcc);
608 Eigen::VectorXf deltaPose = 0.5 * deltaT * (twist + modifiedTwist);
610 modifiedTwist = twist;
612 modifiedLeftPose.block<3, 1>(0, 3) =
613 modifiedLeftPose.block<3, 1>(0, 3) + deltaPose.block<3, 1>(0, 0);
614 modifiedRightPose.block<3, 1>(0, 3) =
615 modifiedRightPose.block<3, 1>(0, 3) + deltaPose.block<3, 1>(6, 0);
616 modifiedLeftPose.block<3, 3>(0, 0) =
617 VirtualRobot::MathTools::rpy2eigen3f(deltaPose(3), deltaPose(4), deltaPose(5)) *
618 modifiedLeftPose.block<3, 3>(0, 0);
619 modifiedRightPose.block<3, 3>(0, 0) =
620 VirtualRobot::MathTools::rpy2eigen3f(deltaPose(9), deltaPose(10), deltaPose(11)) *
621 modifiedRightPose.block<3, 3>(0, 0);
635 modifiedLeftPose.block<3, 3>(0, 0) * currentLeftPose.block<3, 3>(0, 0).transpose();
636 poseError.block<3, 1>(0, 0) =
637 modifiedLeftPose.block<3, 1>(0, 3) - currentLeftPose.block<3, 1>(0, 3);
638 poseError.block<3, 1>(3, 0) = VirtualRobot::MathTools::eigen3f2rpy(diffMat);
641 modifiedRightPose.block<3, 3>(0, 0) * currentRightPose.block<3, 3>(0, 0).transpose();
642 poseError.block<3, 1>(6, 0) =
643 modifiedRightPose.block<3, 1>(0, 3) - currentRightPose.block<3, 1>(0, 3);
644 poseError.block<3, 1>(9, 0) = VirtualRobot::MathTools::eigen3f2rpy(diffMat);
646 Eigen::VectorXf forceImpedance(12);
647 for (
size_t i = 0; i < 6; i++)
649 forceImpedance(i) = KpImpedance(i) * poseError(i) - KdImpedance(i) * currentTwist(i);
650 forceImpedance(i + 6) =
651 KpImpedance(i) * poseError(i + 6) - KdImpedance(i) * currentTwist(i + 6);
656 Eigen::VectorXf leftNullspaceTorque =
657 cfg->knull * (leftDesiredJointValues - leftqpos) - cfg->dnull * leftqvel;
658 Eigen::VectorXf rightNullspaceTorque =
659 cfg->knull * (rightDesiredJointValues - rightqpos) - cfg->dnull * rightqvel;
664 forcePIDInRoot.setZero();
665 leftJointControlWrench = forceImpedance.head<6>() + forcePIDInRoot.head<6>();
666 rightJointControlWrench = forceImpedance.tail<6>() + forcePIDInRoot.tail<6>();
667 Eigen::MatrixXf jtpinvL =
668 leftIK->computePseudoInverseJacobianMatrix(jacobiL.transpose(), lambda);
669 Eigen::MatrixXf jtpinvR =
670 rightIK->computePseudoInverseJacobianMatrix(jacobiR.transpose(), lambda);
671 Eigen::VectorXf leftJointDesiredTorques =
672 jacobiL.transpose() * leftJointControlWrench +
673 (I - jacobiL.transpose() * jtpinvL) * leftNullspaceTorque;
674 Eigen::VectorXf rightJointDesiredTorques =
675 jacobiR.transpose() * rightJointControlWrench +
676 (I - jacobiR.transpose() * jtpinvR) * rightNullspaceTorque;
680 for (
size_t i = 0; i < leftTargets.size(); ++i)
682 float desiredTorque = leftJointDesiredTorques(i);
684 if (isnan(desiredTorque))
689 desiredTorque = (desiredTorque > cfg->torqueLimit) ? cfg->torqueLimit : desiredTorque;
690 desiredTorque = (desiredTorque < -cfg->torqueLimit) ? -cfg->torqueLimit : desiredTorque;
692 debugOutputData.
getWriteBuffer().desired_torques[leftJointNames[i]] =
693 leftJointDesiredTorques(i);
695 leftTargets.at(i)->torque = desiredTorque;
699 for (
size_t i = 0; i < rightTargets.size(); ++i)
701 float desiredTorque = rightJointDesiredTorques(i);
703 if (isnan(desiredTorque))
708 desiredTorque = (desiredTorque > cfg->torqueLimit) ? cfg->torqueLimit : desiredTorque;
709 desiredTorque = (desiredTorque < -cfg->torqueLimit) ? -cfg->torqueLimit : desiredTorque;
711 debugOutputData.
getWriteBuffer().desired_torques[rightJointNames[i]] =
712 rightJointDesiredTorques(i);
714 rightTargets.at(i)->torque = desiredTorque;
721 debugOutputData.
getWriteBuffer().wrenchesConstrained = wrenchesConstrained;
722 debugOutputData.
getWriteBuffer().wrenchesMeasuredInRoot = wrenchesMeasuredInRoot;
726 debugOutputData.
getWriteBuffer().modifiedPoseRight_x = modifiedRightPose(0, 3);
727 debugOutputData.
getWriteBuffer().modifiedPoseRight_y = modifiedRightPose(1, 3);
728 debugOutputData.
getWriteBuffer().modifiedPoseRight_z = modifiedRightPose(2, 3);
730 debugOutputData.
getWriteBuffer().currentPoseLeft_x = currentLeftPose(0, 3);
731 debugOutputData.
getWriteBuffer().currentPoseLeft_y = currentLeftPose(1, 3);
732 debugOutputData.
getWriteBuffer().currentPoseLeft_z = currentLeftPose(2, 3);
735 debugOutputData.
getWriteBuffer().modifiedPoseLeft_x = modifiedLeftPose(0, 3);
736 debugOutputData.
getWriteBuffer().modifiedPoseLeft_y = modifiedLeftPose(1, 3);
737 debugOutputData.
getWriteBuffer().modifiedPoseLeft_z = modifiedLeftPose(2, 3);
739 debugOutputData.
getWriteBuffer().currentPoseRight_x = currentRightPose(0, 3);
740 debugOutputData.
getWriteBuffer().currentPoseRight_y = currentRightPose(1, 3);
741 debugOutputData.
getWriteBuffer().currentPoseRight_z = currentRightPose(2, 3);
762 debugOutputData.
getWriteBuffer().forcePID = forcePIDInRootForDebug;
771 objectDMP->learnDMPFromFiles(fileNames);
778 objectDMP->setGoalPoseVec(goals);
793 VirtualRobot::MathTools::eigen4f2quat(leftPose);
794 Eigen::Vector3f boxPosi = (leftPose.block<3, 1>(0, 3) + rightPose.block<3, 1>(0, 3)) / 2;
796 std::vector<double> boxInitialPose;
797 for (
size_t i = 0; i < 3; ++i)
799 boxInitialPose.push_back(boxPosi(i) * 0.001);
801 boxInitialPose.push_back(boxOri.w);
802 boxInitialPose.push_back(boxOri.x);
803 boxInitialPose.push_back(boxOri.y);
804 boxInitialPose.push_back(boxOri.z);
806 virtualtimer = cfg->timeDuration;
807 objectDMP->prepareExecution(boxInitialPose, goals);
815 const Ice::DoubleSeq& viapoint,
820 objectDMP->setViaPose(u, viapoint);
833 datafields[pair.first] =
new Variant(pair.second);
837 for (
int i = 0; i < forceImpedance.rows(); ++i)
839 std::stringstream ss;
841 std::string data_name =
"forceImpedance_" + ss.str();
842 datafields[data_name] =
new Variant(forceImpedance(i));
846 for (
int i = 0; i < forcePID.rows(); ++i)
848 std::stringstream ss;
850 std::string data_name =
"forcePID_" + ss.str();
851 datafields[data_name] =
new Variant(forcePID(i));
856 for (
int i = 0; i < poseError.rows(); ++i)
858 std::stringstream ss;
860 std::string data_name =
"poseError_" + ss.str();
861 datafields[data_name] =
new Variant(poseError(i));
864 Eigen::VectorXf wrenchesConstrained =
866 for (
int i = 0; i < wrenchesConstrained.rows(); ++i)
868 std::stringstream ss;
870 std::string data_name =
"wrenchesConstrained_" + ss.str();
871 datafields[data_name] =
new Variant(wrenchesConstrained(i));
874 Eigen::VectorXf wrenchesMeasuredInRoot =
876 for (
int i = 0; i < wrenchesMeasuredInRoot.rows(); ++i)
878 std::stringstream ss;
880 std::string data_name =
"wrenchesMeasuredInRoot_" + ss.str();
881 datafields[data_name] =
new Variant(wrenchesMeasuredInRoot(i));
904 datafields[
"modifiedPoseRight_x"] =
906 datafields[
"modifiedPoseRight_y"] =
908 datafields[
"modifiedPoseRight_z"] =
910 datafields[
"currentPoseLeft_x"] =
912 datafields[
"currentPoseLeft_y"] =
914 datafields[
"currentPoseLeft_z"] =
918 datafields[
"modifiedPoseLeft_x"] =
920 datafields[
"modifiedPoseLeft_y"] =
922 datafields[
"modifiedPoseLeft_z"] =
925 datafields[
"currentPoseRight_x"] =
927 datafields[
"currentPoseRight_y"] =
929 datafields[
"currentPoseRight_z"] =
931 datafields[
"dmpBoxPose_x"] =
933 datafields[
"dmpBoxPose_y"] =
935 datafields[
"dmpBoxPose_z"] =
941 datafields[
"modifiedTwist_lx"] =
943 datafields[
"modifiedTwist_ly"] =
945 datafields[
"modifiedTwist_lz"] =
947 datafields[
"modifiedTwist_rx"] =
949 datafields[
"modifiedTwist_ry"] =
951 datafields[
"modifiedTwist_rz"] =
959 debugObs->setDebugChannel(
"BimanualForceController", datafields);
966 runTask(
"NJointBimanualForceController",
971 while (
getState() == eManagedIceObjectStarted)
977 c.waitForCycleDuration();