3 #include <VirtualRobot/Robot.h>
4 #include <VirtualRobot/RobotNodeSet.h>
14 for (
auto& pair : cfg)
16 auto handNodeSet = rtRobot->getRobotNodeSet(pair.first);
17 hands.emplace(pair.first, std::make_unique<HandData>(handNodeSet, pair.second));
25 const std::string& jointName)
28 hands.at(handNodeSet)->sensorDevices.append(sv, jointName);
31 auto* casted_ct = ct->
asA<ControlTarget1DoFActuatorPosition>();
33 hands.at(handNodeSet)->targets.push_back(casted_ct);
39 for (
auto& pair :
hands)
41 auto& hand = pair.second;
42 hand->bufferNonRTToRT.getWriteBuffer() = hand->targetNonRT;
43 hand->bufferNonRTToRT.commitWrite();
50 for (
auto& pair :
hands)
52 auto& hand = pair.second;
53 hand->targetNonRT = hand->bufferUserToNonRT.getUpToDateReadBuffer();
54 hand->rtsInNonRT = hand->bufferRTToNonRT.getUpToDateReadBuffer();
61 for (
auto& pair :
hands)
63 pair.second->rts.deltaT = deltaT;
64 pair.second->rts.accumulateTime += deltaT;
65 pair.second->sensorDevices.getJointAngles(pair.second->rts.jointPosition.value());
66 pair.second->bufferRTToNonRT.getWriteBuffer() = pair.second->rts;
67 pair.second->bufferRTToNonRT.commitWrite();
74 for (
auto& pair :
hands)
76 pair.second->setTarget();
83 for (
auto& pair : cfg)
85 if (pair.second.jointPosition.has_value())
87 auto&
target =
hands.at(pair.first)->bufferUserToNonRT.getWriteBuffer();
88 target.jointPosition = pair.second.jointPosition;
89 hands.at(pair.first)->bufferUserToNonRT.commitWrite();
97 for (
auto& pair :
hands)
99 cfgToUpdate.at(pair.first) = pair.second->bufferNonRTToRT.getUpToDateReadBuffer();
106 for (
auto& pair :
hands)
108 cfgToUpdate.at(pair.first) = pair.second->targetNonRT;
109 pair.second->bufferNonRTToRT.reinitAllBuffers(pair.second->targetNonRT);
110 pair.second->bufferUserToNonRT.reinitAllBuffers(pair.second->targetNonRT);
118 auto rtData = hand->bufferConfigRTToOnPublish.getUpToDateReadBuffer();
120 if (rtData.jointPosition.has_value())
123 debugObs->setDebugChannel(
"hand_" + hand->kinematicChainName, datafields);
130 for (
auto& pair :
hands)
139 for (
auto& pair :
hands)
141 ARMARX_INFO <<
"rtPreActivate for hand " << pair.first;
142 pair.second->rtPreActivate();
164 targetRT = bufferNonRTToRT.getUpToDateReadBuffer();
165 if (targetRT.jointPosition.has_value())
168 for (
size_t i = 0; i < targets.size(); i++)
170 targets[i]->position = targetRT.jointPosition.value()(i);
173 bufferConfigRTToOnPublish.getWriteBuffer() = targetRT;
174 bufferConfigRTToOnPublish.commitWrite();
179 kinematicChainName(robotNodeSet->getName()),
180 jointNames(robotNodeSet->getNodeNames()),
181 nJoints(robotNodeSet->getSize()),
186 rts.jointPosition = Eigen::VectorXf::Zero(
nJoints);
188 jointLimMin = Eigen::Map<Eigen::VectorXf>(robotNodeSet->getNodeLimitsLo().data(),
nJoints);
189 jointLimMax = Eigen::Map<Eigen::VectorXf>(robotNodeSet->getNodeLimitsHi().data(),
nJoints);
198 <<
"In your class constructor, did you forget to call HandControlBase::appendDevice( "
201 sensorDevices.getJointAngles(rts.jointPosition.value());
202 rts.jointPosition.value() =
203 rts.jointPosition.value().cwiseMax(jointLimMin).cwiseMin(jointLimMax);
205 if (not targetRT.jointPosition.has_value())
207 targetRT.jointPosition = rts.jointPosition;
208 targetNonRT = targetRT;
211 nonRTAccumulateTime = 0.0;
213 ARMARX_CHECK_EQUAL(
static_cast<size_t>(targetRT.jointPosition.value().size()), nJoints);
214 bufferNonRTToRT.reinitAllBuffers(targetRT);
215 bufferRTToNonRT.reinitAllBuffers(rts);
216 bufferUserToNonRT.reinitAllBuffers(targetRT);
217 bufferRTToUser.reinitAllBuffers(targetRT);
218 bufferConfigRTToOnPublish.reinitAllBuffers(targetRT);
219 ARMARX_INFO_S << kinematicChainName <<
" joints " << targetRT.jointPosition.value();