PointingIK.cpp
Go to the documentation of this file.
1 #include "PointingIK.h"
2 
3 #include <VirtualRobot/Robot.h>
4 #include <VirtualRobot/RobotNodeSet.h>
5 
7 {
8 
10  {
11  auto humanMapping = robot->getHumanMapping();
12  ARMARX_CHECK(humanMapping) << "Robot '" << robot->getName() << "' has no human mapping";
13 
14  auto armDescription = (side == LEFT) ? humanMapping->leftArm : humanMapping->rightArm;
15  auto elbow = armDescription.segments.elbow.nodeName;
16  auto wrist = armDescription.segments.wrist.nodeName;
17  auto palm = armDescription.segments.palm.nodeName;
18 
19  // actuated joints = all arm joints until (excluding) wrist
20  auto nodeSetArm = robot->getRobotNodeSet(armDescription.nodeSet);
21  auto actuatedJoints = nodeSetArm->getNodeNames();
22  actuatedJoints.resize(nodeSetArm->getRobotNodeIndex(wrist));
23 
24  // reduced robot must contain shoulder, elbow, wrist and palm for IK to work
25  reducedRobot_ = std::make_unique<simox::control::simox::robot::Robot>(
26  robot, actuatedJoints, std::vector({wrist, palm}), true);
27 
28  ik_ = std::make_unique<simox::control::method::example::PointingIK>(
29  *reducedRobot_,
30  *reducedRobot_->getNode(wrist),
31  *reducedRobot_->getNode(elbow),
32  side == LEFT ? reducedRobot_->humanMapping()->leftArm
33  : reducedRobot_->humanMapping()->rightArm);
34 
35  ik_->setPointingTarget(target.cast<double>() / 1000); // simox uses meters
36 
37  trajData.assign(ik_->getNodeNames().size(), std::vector<double>());
38  appendTrajData(ik_->getJointValues());
39  }
40 
41  bool
43  {
44  return ik_->isTargetReached();
45  }
46 
47  double
49  {
50  Eigen::VectorXd prevJointValues = ik_->getJointValues();
51  ik_->optimize();
52  appendTrajData(ik_->getJointValues());
53  return (ik_->getJointValues() - prevJointValues).norm();
54  }
55 
58  {
59  return new Trajectory(trajData, Ice::DoubleSeq(), ik_->getNodeNames());
60  }
61 
62  void
63  PointingIK::appendTrajData(const Eigen::VectorXd& jointValues)
64  {
65  for (size_t i = 0; i < trajData.size(); i++)
66  {
67  trajData[i].push_back(jointValues[i]);
68  }
69  }
70 
71 } // namespace armarx::control::pointing::core
armarx::control::pointing::core
Definition: Pointing.cpp:13
PointingIK.h
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
IceInternal::Handle< Trajectory >
armarx::control::pointing::core::Side
Side
Describes the side of an arm.
Definition: Side.h:10
armarx::control::pointing::core::PointingIK::getTrajectory
armarx::TrajectoryPtr getTrajectory()
Constructs a trajectory containing the sequence of joint configurations from the calls to optimize().
Definition: PointingIK.cpp:57
armarx::control::pointing::core::PointingIK::isTargetReached
bool isTargetReached()
Definition: PointingIK.cpp:42
armarx::control::pointing::core::PointingIK::optimize
double optimize()
Optimizes the joint configuration of the internal robot model regarding pointing towards the target.
Definition: PointingIK.cpp:48
armarx::VariantType::Trajectory
const VariantTypeId Trajectory
Definition: Trajectory.h:44
armarx::control::pointing::core::PointingIK::PointingIK
PointingIK(VirtualRobot::RobotPtr robot, Side side, Eigen::Vector3f &target)
Initialize a new PointingIK.
Definition: PointingIK.cpp:9
armarx::control::pointing::core::LEFT
@ LEFT
Definition: Side.h:12
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18