18 ARMARX_ERROR <<
"Exactly one of the parameters 'shapeName' and 'jointAngles' must be "
19 "set. However, neither has been set.";
24 ARMARX_ERROR <<
"Exactly one of the parameters 'shapeName' and 'jointAngles' must be "
25 "set. However, both have been set.";
39 const auto defShapes =
40 ::armarx::SingleTypeVariantListPtr::dynamicCast(handUnit->getShapeNames())
41 ->toStdVector<std::string>();
43 if (not std::any_of(defShapes.begin(),
45 [&shape](
const auto& defShape) { return shape == defShape; }))
48 <<
"' not defined. Defined shapes: " << defShapes;
53 ARMARX_INFO <<
"Setting shape of hand '" << handUnit->getHandName() <<
"' to '" << shape
56 handUnit->setShape(shape);
60 return waitUntilFinished(handUnit->getShapeJointValues(shape));
68 ARMARX_INFO <<
"Setting joint angles of hand '" << handUnit->getHandName()
82 ShapeHand::waitUntilFinished(
const NameValueMap& targetAngles)
85 const auto movementTimeout =
getParameters().waitUntilFinished->movementTimeout;
87 ARMARX_INFO <<
"Waiting until target position is reached"
88 << (movementTimeout ?
" or movement times out" :
"");
94 } pastJointAngles{handUnit->getCurrentJointValues(),
DateTime::Now()};
100 bool movementTimedOut =
false;
104 const auto currentAngles = handUnit->getCurrentJointValues();
108 for (
const auto& [jointName, targetAngle] : targetAngles)
110 if (
std::abs(targetAngle - currentAngles.at(jointName)) > getAccuracy(jointName))
115 <<
"' is: " <<
std::abs(targetAngle - currentAngles.at(jointName)) <<
" > "
116 << getAccuracy(jointName) <<
"(accuracy)";
122 if (movementTimeout and (
DateTime::Now() - pastJointAngles.time).toSecondsDouble() >=
123 movementTimeout.value())
125 movementTimedOut =
true;
126 for (
const auto& [jointName, targetAngle] : targetAngles)
128 if (
std::abs(currentAngles.at(jointName) -
129 pastJointAngles.angles.at(jointName)) > getAccuracy(jointName))
131 movementTimedOut =
false;
133 <<
deactivateSpam(1) <<
"Joint '" << jointName <<
"' still moving: "
134 <<
std::abs(currentAngles.at(jointName) -
135 pastJointAngles.angles.at(jointName))
136 <<
" > " << getAccuracy(jointName) <<
"(accuracy)"
137 <<
"in the last " << movementTimeout.value() <<
"s (movement timeout)";
144 clock.waitFor(sleepTime);
151 else if (movementTimedOut)
153 ARMARX_INFO <<
"Movement timed out! Joints stopped moving. Not waiting anymore until "
154 "target postion is reached";
159 <<
"Skill aborted. Not waiting anymore until target position is reached";
167 ShapeHand::getAccuracy(
const std::string& jointName)
169 const auto accuracy =
getParameters().waitUntilFinished->accuracy;
170 const auto& accuracyOverride =
getParameters().waitUntilFinished->accuracyOverride;
172 return accuracyOverride.count(jointName) > 0 ? accuracyOverride.at(jointName) : accuracy;
187 arondto::ShapeHandParams params;
189 params.shapeName =
"Open";
190 params.waitUntilFinished =
getParameters().waitUntilFinished;
207 arondto::ShapeHandParams params;
209 params.shapeName =
"Close";
210 params.waitUntilFinished =
getParameters().waitUntilFinished;