28 NJointControllerRegistration<NJointTSCollisionAvoidanceMixedImpedanceVelocityMPController>
30 "NJointTSCollisionAvoidanceMixedImpedanceVelocityMPController");
34 const RobotUnitPtr& robotUnit,
35 const NJointControllerConfigPtr& config,
45 const Ice::Current&)
const
47 return "NJointTSCollisionAvoidanceMixedImpedanceVelocityMPController";
53 const Ice::Current& iceCurrent)
57 for (
auto& pair :
limb)
59 pair.second->rtFirstRun.store(
true);
67 std::lock_guard<std::recursive_mutex> lock(
mtx_mps);
70 std::map<std::string, bool> mpRunning;
73 mpRunning[_mp.second.mp->getMPName()] = _mp.second.mp->isRunning();
74 if (_mp.second.mp->isFinished())
78 if (_mp.second.mp->getRole() ==
"taskspace")
80 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
81 if (_mp.second.mp->isFirstRun())
86 const std::vector<double> mpStart = _mp.second.mp->getStartVec();
89 arm->rtStatusInNonRT.currentPose,
92 "TSMP initial start pose",
93 arm->nonRtConfig.safeDistanceMMToGoal,
94 arm->nonRtConfig.safeRotAngleDegreeToGoal,
95 _mp.second.mp->getMPName() +
"mp_set_target"))
97 ARMARX_INFO <<
"-- deviation from current pose too large, reset MP start pose";
98 _mp.second.mp->validateInitialState(
103 mp::TSMPInputPtr in = std::dynamic_pointer_cast<mp::TSMPInput>(_mp.second.input);
104 in->pose = arm->rtStatusInNonRT.currentPose;
105 in->vel = arm->rtStatusInNonRT.currentTwist;
106 in->deltaT = arm->rtStatusInNonRT.deltaT;
108 else if (_mp.second.mp->getRole() ==
"nullspace")
110 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
111 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
113 arm->rtStatusInNonRT.jointPos.size());
114 in->angleRadian = arm->rtStatusInNonRT.jointPos;
115 in->angularVel = arm->rtStatusInNonRT.qvelFiltered;
116 in->deltaT = arm->rtStatusInNonRT.deltaT;
118 else if (_mp.second.mp->getRole() ==
"hand")
120 auto&
hand =
hands->hands.at(_mp.second.mp->getNodeSetName());
121 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
123 hand->bufferRTToNonRT.getUpToDateReadBuffer().jointPosition.value();
124 in->deltaT =
hand->bufferRTToNonRT.getReadBuffer().deltaT;
140 for (
auto& _mp :
mps)
142 if (not mpRunning.at(_mp.second.mp->getMPName()))
146 for (
auto& ftGuard :
mpConfig.ftGuard)
148 if (ftGuard.mpName == _mp.second.mp->getMPName())
150 bool const forceGuard =
151 (ftGuard.force.has_value() and
152 ftGuard.force.value() >= _mp.second.mp->getCanonicalValue());
153 bool const torqueGuard =
154 (ftGuard.torque.has_value() and
155 ftGuard.torque.value() >= _mp.second.mp->getCanonicalValue());
157 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
158 bool const resetForce =
159 not arm->controller.ftsensor.isForceGuardEnabled() and forceGuard;
160 bool const resetTorque =
161 not arm->controller.ftsensor.isTorqueGuardEnabled() and torqueGuard;
162 if (resetForce or resetTorque)
164 ARMARX_INFO <<
"Triggering force torque safety guard for "
165 << arm->kinematicChainName <<
" at can value "
166 << _mp.second.mp->getCanonicalValue();
169 arm->nonRtConfig.ftConfig.enableSafeGuardForce = forceGuard;
170 arm->nonRtConfig.ftConfig.enableSafeGuardTorque = torqueGuard;
171 arm->controller.ftsensor.enableSafeGuard(resetForce, resetTorque);
175 if (_mp.second.mp->getRole() ==
"taskspace")
177 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
179 std::dynamic_pointer_cast<mp::TSMPOutput>(_mp.second.output);
185 "current pose",
"TSMP pose",
186 arm->nonRtConfig.safeDistanceMMToGoal,
187 arm->nonRtConfig.safeRotAngleDegreeToGoal,
188 _mp.second.mp->getMPName() +
"mp_set_target");
189 arm->nonRtConfig.desiredPose = out->pose;
190 arm->nonRtConfig.desiredTwist = out->vel;
192 else if (_mp.second.mp->getRole() ==
"nullspace")
194 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
196 std::dynamic_pointer_cast<mp::JSMPOutput>(_mp.second.output);
198 arm->nonRtConfig.desiredNullspaceJointAngles.value() = out->angleRadian;
200 else if (_mp.second.mp->getRole() ==
"hand")
203 std::dynamic_pointer_cast<mp::JSMPOutput>(_mp.second.output);
204 auto&
hand =
hands->hands.at(_mp.second.mp->getNodeSetName());
205 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
207 out->angleRadian.size());
208 hand->targetNonRT.jointPosition.value() = out->angleRadian;
210 if (mpRunning.at(_mp.second.mp->getMPName()) and _mp.second.mp->isFinished())
212 ARMARX_INFO <<
"reset buffer for nonRtConfig of " << _mp.second.mp->getMPName();
213 for (
auto& pair :
limb)
215 auto& arm = pair.second;
216 arm->bufferConfigUserToNonRt.reinitAllBuffers(arm->nonRtConfig);
218 for (
auto& pair :
limb)
220 userConfig.limbs.at(pair.first) = pair.second->nonRtConfig;