ocra-recipes
Doxygen documentation for the ocra-recipes repository
MinimumJerkTrajectory.cpp
Go to the documentation of this file.
2 #include <math.h>
3 
4 namespace ocra
5 {
6 
7 Eigen::MatrixXd MinimumJerkTrajectory::getDesiredValues(double _time)
8 {
14  if (startTrigger)
15  {
16  startTrigger = false;
17  t0 = _time;
18  }
19 
20  Eigen::MatrixXd desiredValue = Eigen::MatrixXd::Zero(nDoF, TRAJ_DIM);
21 
22  double tau = (_time - t0) / pointToPointDuration;
23 
24 
25  if ((tau <= TAU_MAX) && (currentWaypointIndex<(nWaypoints-1)))
26  {
27 
28  if (nonRotationDof != 0)
29  {
30  Eigen::VectorXd alpha = waypoints.col(currentWaypointIndex+1) - waypoints.col(currentWaypointIndex);
31  desiredValue.block(0,POS_INDEX,nonRotationDof,1) = waypoints.col(currentWaypointIndex) + alpha * ( 10*pow(tau,3.0) - 15*pow(tau,4.0) + 6*pow(tau,5.0) );
32  desiredValue.block(0,VEL_INDEX,nonRotationDof,1) = Eigen::VectorXd::Zero(nDoF) + alpha * ( 30*pow(tau,2.0) - 60*pow(tau,3.0) + 30*pow(tau,4.0) );
33  desiredValue.block(0,ACC_INDEX,nonRotationDof,1) = Eigen::VectorXd::Zero(nDoF) + alpha * ( 60*pow(tau,1.0) - 180*pow(tau,2.0) + 120*pow(tau,3.0) );
34  }
36  {
37  Eigen::Rotation3d qStart, qEnd;
40 
41  Eigen::Rotation3d interpolatedQuat = quaternionSlerp(tau, qStart, qEnd);
42 
43  Eigen::VectorXd interpolatedQuatVector = quaternionToEigenVector(interpolatedQuat);
44  desiredValue.block((nDoF-QUATERNION_DIM),POS_INDEX,QUATERNION_DIM,1) = interpolatedQuatVector;
45  }
46  }
47  else if ((tau > TAU_MAX) && (currentWaypointIndex<(nWaypoints-1)))
48  {
49  startTrigger = true;
51  desiredValue.col(POS_INDEX) = waypoints.col(currentWaypointIndex);
54  }
55  }
56  else{
57  desiredValue.col(POS_INDEX) = waypoints.col(nWaypoints-1);
58  trajectoryFinished = true;
59  }
60 
61  return desiredValue;
62 }
63 
64 } //namespace ocra
bool trajectoryFinished
Definition: Trajectory.h:130
int currentWaypointIndex
Definition: Trajectory.h:122
#define VEL_INDEX
Definition: Trajectory.h:21
#define TRAJ_DIM
Definition: Trajectory.h:24
Eigen::MatrixXd waypoints
Definition: Trajectory.h:117
Eigen::MatrixXd getDesiredValues(double time)
#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 ACC_INDEX
Definition: Trajectory.h:22
#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