27 #include <VirtualRobot/VirtualRobot.h>
28 #include <VirtualRobot/XML/RobotIO.h>
29 #include <VirtualRobot/RobotNodeSet.h>
30 #include <VirtualRobot/Nodes/RobotNode.h>
31 #include <VirtualRobot/VirtualRobotException.h>
45 std::string jointName = robotNode->getName();
63 mapVelToPosVel = getProperty<bool>(
"MapVelocityToPositionVelocity").getValue();
76 cycleTime = 1000.f / getProperty<float>(
"ControlFrequency").getValue();
85 execTask->setDelayWarningTolerance(100);
108 if (state.jointAngles.size() > 0)
111 for (
const auto& actualJointAngle : state.jointAngles)
115 angleValues[actualJointAngle.first] = actualJointAngle.second;
126 for (
const auto& actualVelocity : state.jointVelocities)
130 velocitiyValues[actualVelocity.first] = actualVelocity.second;
136 for (
const auto& actualJointTorque : state.jointTorques)
140 torqueValues[actualJointTorque.first] = actualJointTorque.second;
146 if (angleValues.size() > 0)
148 listenerPrx->reportJointAngles(angleValues, state.timestampInMicroSeconds,
true);
150 if (velocitiyValues.size() > 0)
152 listenerPrx->reportJointVelocities(velocitiyValues, state.timestampInMicroSeconds,
true);
154 if (torqueValues.size() > 0)
156 listenerPrx->reportJointTorques(torqueValues, state.timestampInMicroSeconds,
true);
162 NameControlModeMap result;
171 result[nodeName] = ePositionControl;
175 result[nodeName] =
c->second;
188 NameControlModeMap::const_iterator itAng = targetJointModes.begin();
190 while (itAng != targetJointModes.end())
196 listenerPrx->reportControlModeChanged(targetJointModes, IceUtil::Time::now().toMicroSeconds(),
true);
207 NameValueMap::const_iterator itAng = targetJointAngles.begin();
209 while (itAng != targetJointAngles.end())
219 NameValueMap::const_iterator itVel = targetJointVelocities.begin();
221 while (itVel != targetJointVelocities.end())
233 NameValueMap::const_iterator itAng = targetJointTorques.begin();
235 while (itAng != targetJointTorques.end())
257 for (
const auto& joint : joints)
272 for (
const auto& joint : joints)
292 float factorLoopTime = 1.1f;
306 switch (itMode->second)
308 case ePositionControl:
316 case eVelocityControl:
326 float posTarget =
currentJointValues[itMode->first] + it->second * loopTime * factorLoopTime;
327 applyPosVelMap_pos[itMode->first] = posTarget;
328 applyPosVelMap_vel[itMode->first] = it->second;
349 case ePositionVelocityControl:
369 if (applyPosMap.size() > 0)
371 batchPrx->actuateRobotJointsPos(
robotName, applyPosMap);
374 if (applyVelMap.size() > 0)
376 batchPrx->actuateRobotJointsVel(
robotName, applyVelMap);
379 if (applyTorMap.size() > 0)
381 batchPrx->actuateRobotJointsTorque(
robotName, applyTorMap);
384 if (applyPosVelMap_pos.size() > 0)
386 batchPrx->actuateRobotJoints(
robotName, applyPosVelMap_pos, applyPosVelMap_vel);
388 batchPrx->ice_flushBatchRequests();
404 const ::armarx::SimulatedRobotState robotState = simulatorPrx->getRobotState(robotName);
406 ::armarx::NameStatusMap jointStatus;
407 for (
const auto& [jointName, _] : currentControlModes)
409 jointStatus[jointName] = {
410 .operation = eOnline,
413 .emergencyStop =
false
417 return {.jointModes = currentControlModes,
418 .jointAngles = robotState.jointAngles,
419 .jointVelocities = robotState.jointVelocities,
420 .jointAccelerations = {},
421 .jointTorques = robotState.jointTorques,
423 .jointMotorTemperatures = {},
424 .jointStatus = jointStatus};