Skip to content
Snippets Groups Projects

Implement 'PointAt'-skill

Merged Patrick Dormanns requested to merge feat/pointing-skill into main
4 files
+ 69
48
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -14,6 +14,7 @@ namespace armarx::control::pointing::core
{
Pointing::Pointing(const Remote& remote) : remote_(remote)
{
setTag("Pointing");
}
void
@@ -32,13 +33,13 @@ namespace armarx::control::pointing::core
Eigen::Vector3f target = params.target.toGlobalEigen(robot);
visualizeTarget(target);
armarx::TrajectoryPtr traj = computTrajectory(robot, params.side, target);
armarx::TrajectoryPtr traj = computeArmTrajectory(robot, params.side, target);
addWristTrajectory(robot, params.side, traj);
if (params.handShape)
{
auto shapeJointValues = GetShapeJointValues(robot, params.side, *params.handShape);
auto shapeJointValues = getShapeJointValues(robot, params.side, *params.handShape);
addHandTrajectory(robot, traj, shapeJointValues);
}
@@ -64,7 +65,7 @@ namespace armarx::control::pointing::core
if (not robot)
{
ARMARX_ERROR << "Could not get synchronized robot '" << remote_.robotName << "'";
throw PointingFailedException();
throw armarx::exceptions::local::PointingFailedException();
}
return robot;
}
@@ -81,7 +82,7 @@ namespace armarx::control::pointing::core
}
TrajectoryPtr
Pointing::computTrajectory(VirtualRobot::RobotPtr robot, Side side, Eigen::Vector3f target)
Pointing::computeArmTrajectory(VirtualRobot::RobotPtr robot, Side side, Eigen::Vector3f target)
{
ARMARX_VERBOSE << "Computing trajectory...";
auto ik = PointingIK(robot, side, target);
@@ -96,15 +97,17 @@ namespace armarx::control::pointing::core
if (ik.optimize() < 1e-6)
{
ARMARX_WARNING << "PointingIK didn't find a solution";
throw PointingFailedException();
throw armarx::exceptions::local::PointingFailedException();
}
if (aborted)
{
ARMARX_INFO << "Pointing aborted.";
throw PointingAbortedException();
ARMARX_INFO << "Pointing aborted";
throw armarx::exceptions::local::PointingAbortedException();
}
} while (not ik.isTargetReached());
ARMARX_VERBOSE << "Done computing trajectory";
return ik.getTrajectory();
}
@@ -129,6 +132,33 @@ namespace armarx::control::pointing::core
});
}
std::map<std::string, float>
Pointing::getShapeJointValues(VirtualRobot::RobotPtr robot,
Side side,
const std::string& shapeName)
{
auto humanMapping = robot->getHumanMapping();
ARMARX_CHECK(humanMapping) << "Robot '" << robot->getName() << "' has no human mapping";
auto armDescription = (side == LEFT) ? humanMapping->leftArm : humanMapping->rightArm;
auto tcp = armDescription.segments.tcp.nodeName;
// get endeffector whichs tcp-name matches the tcp-name of the according hand
auto eefs = robot->getEndEffectors();
auto eef = std::find_if(eefs.begin(),
eefs.end(),
[&tcp](VirtualRobot::EndEffectorPtr eef)
{ return eef->getTcpName() == tcp; });
ARMARX_CHECK(eef != eefs.end());
auto shape = (*eef)->getPreshape(shapeName);
if (not shape)
{
ARMARX_ERROR << "Hand '" << (*eef)->getName() << "' has no shape '" << shapeName << "'";
throw armarx::exceptions::local::PointingFailedException();
}
return shape->getRobotNodeJointValueMap();
}
void
Pointing::addHandTrajectory(VirtualRobot::RobotPtr robot,
armarx::TrajectoryPtr traj,
@@ -160,28 +190,11 @@ namespace armarx::control::pointing::core
{
ARMARX_INFO << "Pointing aborted. Stopping trajectory";
remote_.trajectoryPlayer->stopTrajectoryPlayer();
throw PointingAbortedException();
throw armarx::exceptions::local::PointingAbortedException();
}
clock.waitFor(Duration::MilliSeconds(10));
}
ARMARX_INFO << "Pointing target reached";
}
std::map<std::string, float>
Pointing::GetShapeJointValues(VirtualRobot::RobotPtr robot,
Side side,
const std::string& shapeName)
{
auto eefName = std::string("Hand_") + (side == Side::LEFT ? "L" : "R") + "_EEF"; // TODO
auto eef = robot->getEndEffector(eefName);
auto shape = eef->getPreshape(shapeName);
if (not shape)
{
ARMARX_ERROR << "Hand '" << eefName << "' has no shape '" << shape << "'";
throw PointingFailedException();
}
return shape->getRobotNodeJointValueMap();
}
} // namespace armarx::control::pointing::core
Loading