57 if (!
cfg.enablePhaseStop)
64 TSMPInputPtr in = std::dynamic_pointer_cast<TSMPInput>(input);
65 TSMPOutputPtr out = std::dynamic_pointer_cast<TSMPOutput>(output);
67 Eigen::Matrix4f currentPose = in->pose;
77 getError(currentPose, targetPosition, targetQuaternion, posiError, oriError);
80 double poseError = posiError + (
cfg.psMM2Radian * oriError);
89 phase.
phaseStop =
cfg.maxValue / (1 + exp(-
cfg.slop * (poseError - phaseDist)));
117 TSMPInputPtr in = std::dynamic_pointer_cast<TSMPInput>(input);
118 TSMPOutputPtr out = std::dynamic_pointer_cast<TSMPOutput>(output);
131 double timeDuration =
cfg.durationSec;
141 ARMARX_INFO <<
" -- Discrete mode: MP " <<
cfg.name <<
" finished in " << duration
148 Eigen::Matrix4f currentPose = in->pose;
150 double deltaT = in->deltaT;
200 canonicalValue -= tau * deltaT / ((1 + phaseStop) * timeDuration);
202 std::vector<mplib::representation::MPState> targetState =
203 std::dynamic_pointer_cast<mplib::representation::vmp::TaskSpacePrincipalComponentVMP>(
208 for (
size_t i = 0; i < 3; ++i)
210 currentState[i].vel = tau * targetState[i].vel *
cfg.amplitude / timeDuration;
217 if (
cfg.enablePhaseStop and
cfg.enablePhaseStopMPC)
219 for (
size_t i = 0; i < 3; i++)
224 const double vel1 = (
cfg.psKpPos * (
targetPoseVec[i] - currentPose(i, 3))) -
225 (
cfg.psKdPos * currentVel(i));
228 out->vel(i) = mpcFactor * vel0 + (1 - mpcFactor) * vel1;
233 for (
size_t i = 0; i < 3; i++)
244 targetState[3].vel, targetState[4].vel, targetState[5].vel, targetState[6].vel};
248 angularVel0.w() *= 2;
249 angularVel0.x() *= 2;
250 angularVel0.y() *= 2;
251 angularVel0.z() *= 2;
257 angularVel0.coeffs() = -angularVel0.coeffs();
273 angularVel0.vec() = tau * angularVel0.vec() *
cfg.amplitude / timeDuration;
288 for (
size_t i = 3; i < 7; ++i)
291 tau * targetState[i].vel *
cfg.amplitude / timeDuration;
295 if (
cfg.enablePhaseStop and
cfg.enablePhaseStopMPC)
302 Eigen::Matrix3f desiredMat(targetQuaternionf);
303 Eigen::Matrix3f currentMat = currentPose.block<3, 3>(0, 0);
306 Eigen::Matrix3f diffMat = desiredMat * currentMat.inverse();
307 Eigen::Vector3f diffRPY = VirtualRobot::MathTools::eigen3f2rpy(diffMat);
308 Eigen::Vector3f angularVel1 =
309 cfg.psKpOri * diffRPY -
cfg.psKdOri * currentVel.tail<3>();
313 mpcFactor * angularVel0.x() / timeDuration + (1 - mpcFactor) * angularVel1(0);
315 mpcFactor * angularVel0.y() / timeDuration + (1 - mpcFactor) * angularVel1(1);
317 mpcFactor * angularVel0.z() / timeDuration + (1 - mpcFactor) * angularVel1(2);
321 out->vel(3) = angularVel0.x();
322 out->vel(4) = angularVel0.y();
323 out->vel(5) = angularVel0.z();
330 std::vector<double> targetVec;
331 for (
const auto& t : targetState)
333 targetVec.push_back(t.pos);
336 auto start = targetVec.end() - 4;
339 double norm = std::sqrt(std::inner_product(
start, targetVec.end(),
start, 0.0));
343 for (
auto it =
start; it != targetVec.end(); ++it)