28 NJointControllerRegistration<NJointTSMixedImpedanceVelocityMPController>
30 "NJointTSMixedImpedanceVelocityMPController");
33 const RobotUnitPtr& robotUnit,
34 const NJointControllerConfigPtr& config,
44 return "NJointTSMixedImpedanceVelocityMPController";
50 const Ice::Current& iceCurrent)
54 for (
auto& pair :
limb)
56 pair.second->rtFirstRun.store(
true);
64 std::lock_guard<std::recursive_mutex> lock(
mtx_mps);
67 std::map<std::string, bool> mpRunning;
70 mpRunning[_mp.second.mp->getMPName()] = _mp.second.mp->isRunning();
71 if (_mp.second.mp->isFinished())
75 if (_mp.second.mp->getRole() ==
"taskspace")
77 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
78 if (_mp.second.mp->isFirstRun())
83 const std::vector<double> mpStart = _mp.second.mp->getStartVec();
86 arm->rtStatusInNonRT.currentPose,
89 "TSMP initial start pose",
90 arm->nonRtConfig.safeDistanceMMToGoal,
91 arm->nonRtConfig.safeRotAngleDegreeToGoal,
92 _mp.second.mp->getMPName() +
"mp_set_target"))
94 ARMARX_INFO <<
"deviation from current pose too large, reset MP start pose";
95 _mp.second.mp->validateInitialState(
100 mp::TSMPInputPtr in = std::dynamic_pointer_cast<mp::TSMPInput>(_mp.second.input);
101 in->pose = arm->rtStatusInNonRT.currentPose;
102 in->vel = arm->rtStatusInNonRT.currentTwist;
103 in->deltaT = arm->rtStatusInNonRT.deltaT;
105 else if (_mp.second.mp->getRole() ==
"nullspace")
107 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
108 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
110 arm->rtStatusInNonRT.jointPos.size());
111 in->angleRadian = arm->rtStatusInNonRT.jointPos;
112 in->angularVel = arm->rtStatusInNonRT.qvelFiltered;
113 in->deltaT = arm->rtStatusInNonRT.deltaT;
115 else if (_mp.second.mp->getRole() ==
"hand")
117 auto&
hand =
hands->hands.at(_mp.second.mp->getNodeSetName());
118 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
120 hand->bufferRTToNonRT.getUpToDateReadBuffer().jointPosition.value();
121 in->deltaT =
hand->bufferRTToNonRT.getReadBuffer().deltaT;
137 for (
auto& _mp :
mps)
139 if (not mpRunning.at(_mp.second.mp->getMPName()))
143 for (
auto& ftGuard :
mpConfig.ftGuard)
145 if (ftGuard.mpName == _mp.second.mp->getMPName())
147 bool const forceGuard =
148 (ftGuard.force.has_value() and
149 ftGuard.force.value() >= _mp.second.mp->getCanonicalValue());
150 bool const torqueGuard =
151 (ftGuard.torque.has_value() and
152 ftGuard.torque.value() >= _mp.second.mp->getCanonicalValue());
154 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
155 bool const resetForce =
156 not arm->controller.ftsensor.isForceGuardEnabled() and forceGuard;
157 bool const resetTorque =
158 not arm->controller.ftsensor.isTorqueGuardEnabled() and torqueGuard;
159 if (resetForce or resetTorque)
161 ARMARX_INFO <<
"Triggering force torque safety guard for "
162 << arm->kinematicChainName <<
" at can value "
163 << _mp.second.mp->getCanonicalValue();
166 arm->nonRtConfig.ftConfig.enableSafeGuardForce = forceGuard;
167 arm->nonRtConfig.ftConfig.enableSafeGuardTorque = torqueGuard;
168 arm->controller.ftsensor.enableSafeGuard(resetForce, resetTorque);
172 if (_mp.second.mp->getRole() ==
"taskspace")
174 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
176 std::dynamic_pointer_cast<mp::TSMPOutput>(_mp.second.output);
181 arm->rtStatusInNonRT.currentPose,
185 arm->nonRtConfig.safeDistanceMMToGoal,
186 arm->nonRtConfig.safeRotAngleDegreeToGoal,
187 _mp.second.mp->getMPName() +
"mp_set_target");
188 arm->nonRtConfig.desiredPose = out->pose;
189 arm->nonRtConfig.desiredTwist = out->vel;
191 else if (_mp.second.mp->getRole() ==
"nullspace")
193 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
195 std::dynamic_pointer_cast<mp::JSMPOutput>(_mp.second.output);
197 arm->nonRtConfig.desiredNullspaceJointAngles.value() = out->angleRadian;
199 else if (_mp.second.mp->getRole() ==
"hand")
202 std::dynamic_pointer_cast<mp::JSMPOutput>(_mp.second.output);
203 auto&
hand =
hands->hands.at(_mp.second.mp->getNodeSetName());
204 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
206 out->angleRadian.size());
207 hand->targetNonRT.jointPosition.value() = out->angleRadian;
209 if (mpRunning.at(_mp.second.mp->getMPName()) and _mp.second.mp->isFinished())
211 ARMARX_INFO <<
"reset buffer for nonRtConfig of " << _mp.second.mp->getMPName();
212 for (
auto& pair :
limb)
214 auto& arm = pair.second;
215 arm->bufferConfigUserToNonRt.reinitAllBuffers(arm->nonRtConfig);
217 for (
auto& pair :
limb)
219 userConfig.limbs.at(pair.first) = pair.second->nonRtConfig;