6 #include <SimoxUtility/math/compare/is_equal.h>
7 #include <SimoxUtility/math/convert/mat4f_to_pos.h>
8 #include <SimoxUtility/math/convert/mat4f_to_quat.h>
9 #include <VirtualRobot/MathTools.h>
17 return targetJointTorques.size();
26 ik.reset(
new VirtualRobot::DifferentialIK(
27 rns, rns->getRobot()->getRootNode(), VirtualRobot::JacobiProvider::eSVDDamped));
29 const auto size = rns->getSize();
32 tcptwist.resize(size);
33 nullqerror.resize(size);
34 nullspaceTorque.resize(size);
35 targetJointTorques.resize(size);
40 const Eigen::VectorXf&
43 std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors,
44 std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors,
45 std::vector<const SensorValue1DoFActuatorPosition*> positionSensors)
57 const Eigen::MatrixXf jacobi = ik->getJacobianMatrix(
58 tcp, VirtualRobot::IKSolver::CartesianSelection::All);
61 const Eigen::MatrixXf jtpinv = ik->computePseudoInverseJacobianMatrix(
62 jacobi.transpose(), lambda);
64 for (
size_t i = 0; i < velocitySensors.size(); ++i)
66 qpos(i) = positionSensors[i]->position;
67 qvel(i) = velocitySensors[i]->velocity;
72 const Eigen::Vector3f currentTCPLinearVelocity{
73 0.001f * tcptwist(0), 0.001f * tcptwist(1), 0.001f * tcptwist(2)};
74 const Eigen::Vector3f currentTCPAngularVelocity{tcptwist(3), tcptwist(4), tcptwist(5)};
76 const Eigen::Vector3f currentTCPPosition = tcp->getPositionInRootFrame();
77 const Eigen::Vector3f tcpForces =
79 const Eigen::Vector3f tcpDesiredForce =
80 tcpForces - cfg.
Dpos.cwiseProduct(currentTCPLinearVelocity);
90 const Eigen::Vector3f rpy = VirtualRobot::MathTools::eigen3f2rpy(diffMat);
91 const Eigen::Vector3f tcpDesiredTorque =
92 cfg.
Kori.cwiseProduct(rpy) - cfg.
Dori.cwiseProduct(currentTCPAngularVelocity);
94 tcpDesiredWrench << 0.001 * tcpDesiredForce, tcpDesiredTorque;
99 for (
int i = 0; i < nullqerror.rows(); ++i)
101 if (fabs(nullqerror(i)) < 0.09)
106 nullspaceTorque = cfg.
Knull.cwiseProduct(nullqerror) - cfg.
Dnull.cwiseProduct(qvel);
109 jacobi.transpose() * tcpDesiredWrench + (I - jacobi.transpose() * jtpinv) * nullspaceTorque;
110 for (
int i = 0; i < targetJointTorques.size(); ++i)
112 targetJointTorques(i) =
124 return targetJointTorques;