32 : tcpTarget(tcpTarget), handJointsTarget(handJointsTarget),
dt(0),
33 feedForwardPosVelocity(0, 0, 0), feedForwardOriVelocity(0, 0, 0),
34 feedForwardHandJointsVelocity(
Eigen::VectorXf::Zero(handJointsTarget.rows()))
38 float dt,
const Eigen::Vector3f& feedForwardPosVelocity,
const Eigen::Vector3f& feedForwardOriVelocity,
39 const Eigen::VectorXf& feedForwardHandJointsVelocity)
40 : tcpTarget(tcpTarget), handJointsTarget(handJointsTarget),
dt(
dt),
41 feedForwardPosVelocity(feedForwardPosVelocity), feedForwardOriVelocity(feedForwardOriVelocity),
42 feedForwardHandJointsVelocity(feedForwardHandJointsVelocity)
47 return ::math::Helpers::GetPosition(tcpTarget);
52 return ::math::Helpers::GetOrientation(tcpTarget);
62 Eigen::Vector3f pos0 = ::math::Helpers::GetPosition(prev->tcpTarget);
63 Eigen::Matrix3f ori0 = ::math::Helpers::GetOrientation(prev->tcpTarget);
64 Eigen::VectorXf hnd0 = prev->handJointsTarget;
66 Eigen::Vector3f pos1 = ::math::Helpers::GetPosition(tcpTarget);
68 Eigen::VectorXf hnd1 = handJointsTarget;
70 Eigen::Vector3f dpos = pos1 - pos0;
71 Eigen::Vector3f dori = ::math::Helpers::GetRotationVector(ori0, ori1);
72 Eigen::VectorXf dhnd = hnd1 - hnd0;
75 feedForwardPosVelocity = dpos /
dt;
76 feedForwardOriVelocity = dori /
dt;
77 feedForwardHandJointsVelocity = dhnd /
dt;
83 keypointMap[0] = keypoints.size();
84 keypoints.push_back(keypoint);
92 keypoint->updateVelocities(prev,
dt);
94 keypointMap[t] = keypoints.size();
95 keypoints.push_back(keypoint);
100 return keypoints.size();
106 if (index <= 0 || index > keypoints.size())
112 keypoint->updateVelocities(prev,
dt);
113 if (
index < keypoints.size())
116 next->updateVelocities(keypoint, next->dt);
118 keypoints.insert(keypoints.begin() +
index, keypoint);
124 if (index <= 0 || index >= keypoints.size())
128 keypoints.erase(keypoints.begin() +
index);
129 if (
index < keypoints.size())
133 next->updateVelocities(prev, next->dt);
141 if (index <= 0 || index >= keypoints.size())
147 keypoint->updateVelocities(prev,
dt);
148 keypoints.at(
index) = keypoint;
154 if (index <= 0 || index >= keypoints.size())
160 keypoint->updateVelocities(prev,
dt);
166 return keypoints.at(keypoints.size() - 1);
171 return keypoints.at(i);
188 std::map<float, size_t>::const_iterator it, prev;
189 it = keypointMap.upper_bound(t);
190 if (it == keypointMap.end())
192 i1 = keypoints.size() - 1;
193 i2 = keypoints.size() - 1;
197 prev = std::prev(it);
200 f = ::math::Helpers::ILerp(prev->first, it->first, t);
208 return ::math::Helpers::Lerp(
getKeypoint(i1)->getTargetPosition(),
getKeypoint(i2)->getTargetPosition(), f);
217 if (oriVel.squaredNorm() == 0)
221 Eigen::AngleAxisf aa(oriVel.norm(), oriVel.normalized());
223 return aa.toRotationMatrix() *
getKeypoint(i1)->getTargetOrientation();
233 std::vector<Eigen::Matrix4f> res;
236 res.emplace_back(keypoint->getTargetPose());
243 std::vector<Eigen::Vector3f> res;
246 res.emplace_back(keypoint->getTargetPosition());
253 std::vector<Eigen::Matrix3f> res;
256 res.emplace_back(keypoint->getTargetOrientation());
299 return getKeypoint(i2)->feedForwardHandJointsVelocity;
304 return keypointMap.rbegin()->first;
310 for (
size_t i = 1; i < keypoints.size(); i++)
315 Eigen::Vector3f pos0 = ::math::Helpers::GetPosition(k0->tcpTarget);
318 Eigen::Vector3f pos1 = ::math::Helpers::GetPosition(k1->tcpTarget);
322 l.
ori += fabs(::math::Helpers::GetAngleAxisFromTo(ori0, ori1).
angle());
329 return keypoints.at(0)->handJointsTarget.rows();
335 for (
size_t i = 1; i < keypoints.size(); i++)
338 traj->addKeypoint(::math::Helpers::TranslateAndRotatePose(kp->getTargetPose(), translation, rotation), kp->handJointsTarget, kp->dt);
346 for (
size_t i = 1; i < keypoints.size(); i++)
349 traj->addKeypoint(
transform * kp->getTargetPose(), kp->handJointsTarget, kp->dt);
362 Eigen::Vector3f targetHandForward = ::math::Helpers::TransformDirection(
target, handForward);
363 Eigen::Vector3f trajHandForward = ::math::Helpers::TransformDirection(startPose, handForward);
364 Eigen::Vector3f up(0, 0, 1);
366 float angle = ::math::Helpers::Angle(targetHandForward, trajHandForward, up);
367 Eigen::AngleAxisf aa(
angle, up);
369 Eigen::Matrix4f transform = ::math::Helpers::CreateTranslationRotationTranslationPose(-::math::Helpers::GetPosition(startPose), aa.toRotationMatrix(), ::math::Helpers::GetPosition(
target));
385 e.
Add(
"dt", keypoint->dt);
386 e.
AddAsArr(
"Pose", keypoint->tcpTarget);
387 e.
AddAsArr(
"HandValues", keypoint->handJointsTarget);
395 std::string packageName =
"armar6_skills";
397 std::string dataDir = finder.
getDataDir() +
"/" + packageName;
413 std::vector<JPathNavigator> rows = nav.
select(
"Pose/*");
414 for (
int i = 0; i < 4; i++)
416 std::vector<JPathNavigator> cells = rows.at(i).select(
"*");
417 for (
int j = 0; j < 4; j++)
419 pose(i, j) = cells.at(j).asFloat();
423 Eigen::Vector3f handValues;
424 std::vector<JPathNavigator> cells = nav.
select(
"HandValues/*");
425 for (
int j = 0; j < 3; j++)
427 handValues(j) = cells.at(j).asFloat();
436 traj->addKeypoint(pose, handValues,
dt);
452 void GraspTrajectory::updateKeypointMap()
456 for (
size_t i = 0; i < keypoints.size(); i++)