30 #include <RobotAPI/interface/units/KinematicUnitInterface.h>
33 #include <VirtualRobot/RobotConfig.h>
36 using namespace MotionControlGroup;
45 MoveJointsGeneratedBase <
MoveJoints >(stateData)
51 timeoutEvent = setTimeoutEvent(in.gettimeoutInMs(), createEventEvTimeout());
64 std::vector< std::string> jointNames;
65 std::vector< float> targetJointValues;
67 if (in.isjointNamesSet() && in.istargetJointValuesSet())
69 jointNames = in.getjointNames();
70 targetJointValues = in.gettargetJointValues();
72 else if (in.isalternativeJointMapSet())
74 auto map = in.getalternativeJointMap();
76 for (
const auto& elem : map)
78 jointNames.push_back(elem.first);
79 targetJointValues.push_back(elem.second);
84 throw LocalException(
"You must either specify the alternativeJointMap param or the targetJointValues and jointNames params.");
87 if (jointNames.size() != targetJointValues.size())
89 throw LocalException(
"Sizes of joint name list and joint value list do not match!");
92 if (jointNames.size() == 0)
94 emitEvJointTargetReached();
100 NameControlModeMap controlModes;
101 bool useNativeController = in.getUseNativePositionControl();
102 for (
size_t i = 0; i < jointNames.size(); i++)
104 targetJointAngles[jointNames.at(i)] = targetJointValues.at(i);
105 controlModes[jointNames.at(i)] = useNativeController ? ePositionControl : eVelocityControl;
106 ARMARX_DEBUG <<
"setting joint angle for joint '" << jointNames.at(i) <<
"' to " << targetJointValues.at(i) << std::endl;
110 if (in.isjointMaxSpeedsSet() && getInput<SingleTypeVariantList>(
"jointMaxSpeeds")->getSize() == (
int)jointNames.size())
114 for (
size_t i = 0; i < jointNames.size(); i++)
116 targetJointVelocities[jointNames.at(i)] = maxJointValues->getVariant(i)->getFloat();
121 float maxVel = in.getjointMaxSpeed();
123 for (
size_t i = 0; i < jointNames.size(); i++)
125 targetJointVelocities[jointNames.at(i)] = maxVel;
131 float tolerance = getInput<float>(
"jointTargetTolerance");
134 for (
size_t i = 0; i < jointNames.size(); i++)
136 ARMARX_DEBUG <<
"creating condition (" << i <<
" of " << jointNames.size() <<
") for value " << targetJointValues.at(i) <<
flush;
138 cond = cond && approx;
139 jointValueMap[jointNames.at(i)] = targetJointValues.at(i);
141 local.setCommandedJoints(jointValueMap);
142 ARMARX_DEBUG <<
"installing condition: EvJointTargetReached" << std::endl;
144 ARMARX_DEBUG <<
"condition installed: EvJointTargetReached" << std::endl;
147 if (useNativeController)
155 for (
auto& joint : jointValueMap)
160 auto currentValues = context->
getRobot()->getConfig()->getRobotNodeJointValueMap();
162 ARMARX_INFO <<
"Joint target tolerance: " << tolerance;
170 float accelerationTime = in.getAccelerationTime();
171 float maxVel = in.getjointMaxSpeed();
172 while (!isRunningTaskStopped())
176 currentValues = context->
getRobot()->getConfig()->getRobotNodeJointValueMap();;
179 for (
auto&
value : jointValueMap)
181 float delta = fabs((
value.second - currentValues[
value.first]));
182 maxDelta =
std::max(delta, maxDelta);
188 float motionDuration = maxDelta / maxVel;
190 targetJointVelocities.clear();
192 for (
auto&
value : jointValueMap)
194 float delta = (
value.second - currentValues[
value.first]);
195 targetJointVelocities[
value.first] = delta / motionDuration;
202 for (
auto&
value : jointValueMap)
204 float delta = ((
value.second - currentValues[
value.first]));
205 currentDeltas[
value.first] = delta;
206 float slowdownFactor = (1 / (1 + exp(-(fabs(delta) - 0.1) / 0.04))) ;
207 float newVel =
std::min(fabs(targetJointVelocities[
value.first]), fabs(delta) * slowdownFactor * 10);
208 if (newVel * delta < 0)
213 currentTargetJointVelocities[
value.first] = newVel;
218 context->
getKinematicUnit()->setJointVelocities(currentTargetJointVelocities);
222 if (in.getSetVelocitiesToZeroAtEnd())
224 for (
auto& joint : jointValueMap)
226 targetJointVelocities[joint.first] = 0.0f;
232 if (in.getHoldPositionAfterwards())
234 currentValues = context->
getRobot()->getConfig()->getRobotNodeJointValueMap();
236 for (
auto& joint : jointValueMap)
238 controlModes[joint.first] = ePositionControl;
254 while (!isRunningTaskFinished())
260 auto jointValueMap = local.getCommandedJoints();
262 for (
auto& joint : jointValueMap)
265 targetJointVelocities[joint.first] = 0.0f;
268 auto currentValues = context->
getRobot()->getConfig()->getRobotNodeJointValueMap();
271 float tolerance = getInput<float>(
"jointTargetTolerance");
272 ARMARX_INFO <<
"Joint target tolerance: " << tolerance;
274 for (
auto&
value : jointValueMap)
276 differences[
value.first] = (
value.second - currentValues[
value.first]);