ocra-recipes
Doxygen documentation for the ocra-recipes repository
LinearInterpolationTrajectory.cpp
Go to the documentation of this file.
1 
3 
4 
5 namespace ocra
6 {
8 {
9  if (startTrigger)
10  {
11  startTrigger = false;
12  t0 = _time;
13  }
14 
15  Eigen::MatrixXd desiredValue = Eigen::MatrixXd::Zero(nDoF,TRAJ_DIM);
16 
17  double tau;
18  if (usingDurationVector) {
20  } else {
21  tau = (_time - t0) / pointToPointDuration;
22  }
23 
24 
25  if ((tau <= TAU_MAX) && (currentWaypointIndex<(nWaypoints-1)))
26  {
27  // Interpolate
28  if (nonRotationDof != 0)
29  {
31  }
33  {
34  Eigen::Rotation3d qStart, qEnd;
37 
38  Eigen::Rotation3d interpolatedQuat = quaternionSlerp(tau, qStart, qEnd);
39 
40  Eigen::VectorXd interpolatedQuatVector = quaternionToEigenVector(interpolatedQuat);
41  desiredValue.block((nDoF-QUATERNION_DIM),POS_INDEX,QUATERNION_DIM,1) = interpolatedQuatVector;
42  }
43  }
44  else if ((tau > TAU_MAX) && (currentWaypointIndex<(nWaypoints-1)))
45  {
46  // Set to the next waypoint when pointToPointDuration achieved
47  startTrigger = true;
49  desiredValue.col(POS_INDEX) = waypoints.col(currentWaypointIndex);
50  }
51  else{
52  // Set to final waypoint if no more waypoints and duration achieved
53  desiredValue.col(POS_INDEX) = waypoints.col(nWaypoints-1);
54  trajectoryFinished = true;
55  }
56 
57 
58 
59  return desiredValue;
60 }
61 
62 } //namespace ocra
bool trajectoryFinished
Definition: Trajectory.h:130
int currentWaypointIndex
Definition: Trajectory.h:122
#define TRAJ_DIM
Definition: Trajectory.h:24
bool usingDurationVector
Definition: Trajectory.h:129
Eigen::MatrixXd waypoints
Definition: Trajectory.h:117
#define QUATERNION_DIM
Definition: Trajectory.h:19
Eigen::VectorXd pointToPointDurationVector
Definition: Trajectory.h:126
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Eigen::Rotation3d quaternionSlerp(double tau, Eigen::Rotation3d &qStart, Eigen::Rotation3d &qEnd)
Definition: Trajectory.cpp:241
#define TAU_MAX
Definition: Trajectory.h:26
double pointToPointDuration
Definition: Trajectory.h:127
#define POS_INDEX
Definition: Trajectory.h:20
bool endsWithQuaternion
Definition: Trajectory.h:120
Eigen::VectorXd quaternionToEigenVector(Eigen::Rotation3d &quat)
Definition: Trajectory.cpp:355
bool eigenVectorToQuaternion(const Eigen::VectorXd &quatVec, Eigen::Rotation3d &quat)
Definition: Trajectory.cpp:435