28 NJointControllerRegistration<NJointTSCollisionAvoidanceImpedanceMPController>
30 "NJointTSCollisionAvoidanceImpedanceMPController");
34 const NJointControllerConfigPtr& config,
45 return "NJointTSCollisionAvoidanceImpedanceMPController";
51 const Ice::Current& iceCurrent)
55 for (
auto& pair :
limb)
57 pair.second->rtFirstRun.store(
true);
65 std::lock_guard<std::recursive_mutex> lock(
mtx_mps);
68 std::map<std::string, bool> mpRunning;
71 mpRunning[_mp.second.mp->getMPName()] = _mp.second.mp->isRunning();
72 if (_mp.second.mp->isFinished())
76 if (_mp.second.mp->getRole() ==
"taskspace")
78 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
79 if (_mp.second.mp->isFirstRun())
81 _mp.second.mp->validateInitialState(
common::mat4ToDVec(arm->rtStatusInNonRT.currentPose));
83 mp::TSMPInputPtr in = std::dynamic_pointer_cast<mp::TSMPInput>(_mp.second.input);
84 in->pose = arm->rtStatusInNonRT.currentPose;
85 in->vel = arm->rtStatusInNonRT.currentTwist;
86 in->deltaT = arm->rtStatusInNonRT.deltaT;
88 else if (_mp.second.mp->getRole() ==
"nullspace")
90 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
91 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
93 arm->rtStatusInNonRT.jointPos.size());
94 in->angleRadian = arm->rtStatusInNonRT.jointPos;
95 in->angularVel = arm->rtStatusInNonRT.qvelFiltered;
96 in->deltaT = arm->rtStatusInNonRT.deltaT;
98 else if (_mp.second.mp->getRole() ==
"hand")
100 auto&
hand =
hands->hands.at(_mp.second.mp->getNodeSetName());
101 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
103 hand->bufferRTToNonRT.getUpToDateReadBuffer().jointPosition.value();
104 in->deltaT =
hand->bufferRTToNonRT.getReadBuffer().deltaT;
120 for (
auto& _mp :
mps)
122 if (not mpRunning.at(_mp.second.mp->getMPName()))
126 for (
auto& ftGuard :
mpConfig.ftGuard)
128 if (ftGuard.mpName == _mp.second.mp->getMPName())
130 bool const forceGuard =
131 (ftGuard.force.has_value() and
132 ftGuard.force.value() >= _mp.second.mp->getCanonicalValue());
133 bool const torqueGuard =
134 (ftGuard.torque.has_value() and
135 ftGuard.torque.value() >= _mp.second.mp->getCanonicalValue());
137 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
138 bool const resetForce =
139 not arm->nonRtConfig.ftConfig.enableSafeGuardForce and forceGuard;
140 bool const resetTorque =
141 not arm->nonRtConfig.ftConfig.enableSafeGuardTorque and torqueGuard;
142 if (resetForce or resetTorque)
144 ARMARX_INFO <<
"Triggering force torque safety guard for "
145 << arm->kinematicChainName <<
" at can value "
146 << _mp.second.mp->getCanonicalValue();
149 arm->nonRtConfig.ftConfig.enableSafeGuardForce = forceGuard;
150 arm->nonRtConfig.ftConfig.enableSafeGuardTorque = torqueGuard;
151 arm->controller.ftsensor.enableSafeGuard(resetForce, resetTorque);
155 if (_mp.second.mp->getRole() ==
"taskspace")
157 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
159 std::dynamic_pointer_cast<mp::TSMPOutput>(_mp.second.output);
165 "current pose",
"TSMP pose",
166 arm->nonRtConfig.safeDistanceMMToGoal,
167 arm->nonRtConfig.safeRotAngleDegreeToGoal,
168 _mp.second.mp->getMPName() +
"mp_set_target");
169 arm->nonRtConfig.desiredPose = out->pose;
170 arm->nonRtConfig.desiredTwist = out->vel;
172 else if (_mp.second.mp->getRole() ==
"nullspace")
174 auto& arm =
limb.at(_mp.second.mp->getNodeSetName());
176 std::dynamic_pointer_cast<mp::JSMPOutput>(_mp.second.output);
178 arm->nonRtConfig.desiredNullspaceJointAngles.value() = out->angleRadian;
180 else if (_mp.second.mp->getRole() ==
"hand")
183 std::dynamic_pointer_cast<mp::JSMPOutput>(_mp.second.output);
184 auto&
hand =
hands->hands.at(_mp.second.mp->getNodeSetName());
185 mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(_mp.second.input);
187 out->angleRadian.size());
188 hand->targetNonRT.jointPosition.value() = out->angleRadian;
190 if (mpRunning.at(_mp.second.mp->getMPName()) and _mp.second.mp->isFinished())
192 ARMARX_INFO <<
"reset buffer for nonRtConfig of " << _mp.second.mp->getMPName();
193 for (
auto& pair :
limb)
195 auto& arm = pair.second;
196 arm->bufferConfigUserToNonRt.reinitAllBuffers(arm->nonRtConfig);
198 for (
auto& pair :
limb)
200 userConfig.limbs.at(pair.first) = pair.second->nonRtConfig;