21 , usingDurationVector(false)
30 void Trajectory::setWaypoints(
const std::vector<double>& startingDoubleVec,
const std::vector<double>& endingDoubleVec,
const int waypointSelector,
bool _endsWithQuaternion)
33 if (startingDoubleVec.size() != endingDoubleVec.size())
34 throw std::runtime_error(std::string(
"[Trajectory::setWaypoints()]: Starting vector and ending vector are not the same size."));
38 if (waypointSelector>0) {
39 _nRows = waypointSelector;
42 _nRows = startingDoubleVec.size();
46 Eigen::MatrixXd _waypoints(_nRows, _nCols);
48 for(
int i=0; i<_nRows; i++){
49 _waypoints(i,0)=startingDoubleVec[i];
50 _waypoints(i,1)=endingDoubleVec[i];
58 void Trajectory::setWaypoints(
const Eigen::VectorXd& _startingVector,
const Eigen::VectorXd& _endingVector,
bool _endsWithQuaternion)
61 if (_startingVector.rows() != _endingVector.rows())
62 throw std::runtime_error(std::string(
"[Trajectory::setWaypoints()]: Starting vector and ending vector are not the same size."));
65 int _nRows = _startingVector.rows();
68 Eigen::MatrixXd _waypoints(_nRows, _nCols);
70 _waypoints << _startingVector, _endingVector;
76 void Trajectory::setWaypoints(Eigen::Displacementd& startingDisplacement, Eigen::Displacementd& endingDisplacement,
bool _endsWithQuaternion)
82 int _nRows = _startingVector.rows();
85 Eigen::MatrixXd _waypoints(_nRows, _nCols);
86 _waypoints << _startingVector, _endingVector;
93 void Trajectory::setWaypoints(Eigen::Rotation3d& startingOrientation, Eigen::Rotation3d& endingOrientation,
bool _endsWithQuaternion)
99 int _nRows = _startingVector.rows();
102 Eigen::MatrixXd _waypoints(_nRows, _nCols);
103 _waypoints << _startingVector, _endingVector;
160 if (newMaxVel.size()==
nDoF) {
163 OCRA_ERROR(
"The size of the newMaxVel vector ("<<newMaxVel.size()<<
") doesn't match the nDoF (" <<
nDoF <<
") of the trajectory. Ignoring.")
187 if (newMaxAcc.size()==
nDoF) {
190 OCRA_ERROR(
"The size of the newMaxAcc vector ("<<newMaxAcc.size()<<
") doesn't match the nDoF (" <<
nDoF <<
") of the trajectory. Ignoring.")
227 void Trajectory::getDesiredValues(
double _time, Eigen::Displacementd& _desiredDisplacement, Eigen::Twistd& _desiredVelocity, Eigen::Twistd& _desiredAcceleration)
230 std::cout<<
"\n\ndesVals: \n" << desVals <<
"\n\n";
235 Eigen::Displacementd::AdjointMatrix H_adj = Eigen::Displacementd(Eigen::Vector3d::Zero(), _desiredDisplacement.getRotation().inverse()).adjoint();
236 _desiredVelocity = H_adj * _desiredVelocity;
237 _desiredAcceleration = H_adj * _desiredAcceleration;
248 Eigen::VectorXd startVec;
250 Eigen::VectorXd endVec;
252 if ((startVec - endVec).norm() == 0.0){
257 Eigen::Rotation3d quaternionVector = _qEnd * _qStart.inverse();
258 double theta = 2.0 * acos(quaternionVector.w() );
259 Eigen::Vector3d new_XYZ;
260 new_XYZ << quaternionVector.x(), quaternionVector.y(), quaternionVector.z();
261 new_XYZ /= sin(theta/2.0);
262 new_XYZ *= sin((_tau*theta)/2.0);
263 double new_W = cos((_tau*theta)/2.0);
265 Eigen::Rotation3d interpolatedQuaternion = Eigen::Rotation3d(new_W, new_XYZ);
266 interpolatedQuaternion *= _qStart;
268 return interpolatedQuaternion;
302 if (_pointToPointDurationVector.size() == (
nWaypoints-1)) {
309 OCRA_WARNING(
"The point to point duration vector you passed is not the right size.")
340 Eigen::VectorXd outputVector(7);
341 double x, y, z, qx, qy, qz, qw;
342 x = _disp.getTranslation().x();
343 y = _disp.getTranslation().y();
344 z = _disp.getTranslation().z();
345 qx = _disp.getRotation().x();
346 qy = _disp.getRotation().y();
347 qz = _disp.getRotation().z();
348 qw = _disp.getRotation().w();
349 outputVector << x, y, z, qw, qx, qy, qz;
361 Eigen::VectorXd outputVector(4);
362 double qx, qy, qz, qw;
367 outputVector << qw, qx, qy, qz;
374 if (_doubleVec.size() == _dispVec.rows()){
375 for(
int i=0; i<_dispVec.rows(); i++){
376 _doubleVec[i] = _dispVec[i];
386 int nValues = _dispMat.size();
387 if (nValues == _doubleVec.size()) {
388 const double *eigPtr = _dispMat.data();
389 for(
int i=0; i<nValues; i++){
390 _doubleVec[i] = *eigPtr;
404 Eigen::Vector3d translation;
405 Eigen::Rotation3d rotation;
408 if (_dispVec.rows()==3)
410 translation = _dispVec;
411 rotation = Eigen::Rotation3d(1.0, 0.0, 0.0, 0.0);
416 translation << 0.0, 0.0, 0.0;
420 else if(_dispVec.rows()==7)
427 _disp = Eigen::Displacementd(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
431 _disp = Eigen::Displacementd(translation, rotation);
439 _quat = Eigen::Rotation3d(_quatVec(0), _quatVec(1), _quatVec(2), _quatVec(3));
444 _quat = Eigen::Rotation3d(1.0, 0.0, 0.0, 0.0);
453 Eigen::Vector3d linearComponent, angularComponent;
456 if (_twistVec.rows()==3)
458 linearComponent = _twistVec;
459 angularComponent << 0.0, 0.0, 0.0;
464 linearComponent << 0.0, 0.0, 0.0;
468 else if(_twistVec.rows()==7)
475 _twist = Eigen::Twistd::Zero();
479 _twist = Eigen::Twistd(angularComponent, linearComponent);
491 Eigen::MatrixXd posVelAcc(nRows, nCols);
499 return posVelAcc.topRows(rowCounter-1);
bool eigenVectorToStdVector(const Eigen::VectorXd &dispVec, std::vector< double > &doubleVec)
void setMaxAcceleration(double newMaxAcc)
Eigen::MatrixXd waypoints
Eigen::VectorXd getMaxAccelerationVector()
Eigen::VectorXd displacementToEigenVector(Eigen::Displacementd &disp)
double maximumAcceleration
void setMaxVelocity(double newMaxVel)
Eigen::VectorXd pointToPointDurationVector
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
bool eigenVectorToTwist(const Eigen::VectorXd &twistVec, Eigen::Twistd &twist)
std::list< Eigen::VectorXd > waypointList
Eigen::Rotation3d quaternionSlerp(double tau, Eigen::Rotation3d &qStart, Eigen::Rotation3d &qEnd)
double pointToPointDuration
virtual void initializeTrajectory()
void setWaypoints(const std::vector< double > &startingDoubleVec, const std::vector< double > &endingDoubleVec, const int waypointSelector=0, bool endsWithQuaternion=false)
double totalTrajectoryDuration
Eigen::VectorXd maximumAccelerationVector
bool eigenMatrixToStdVector(const Eigen::MatrixXd &dispMat, std::vector< double > &doubleVec)
double getMaxAcceleration()
Eigen::MatrixXd getFullTrajectory(double dt=0.01)
Eigen::VectorXd quaternionToEigenVector(Eigen::Rotation3d &quat)
bool eigenVectorToDisplacement(const Eigen::VectorXd &dispVec, Eigen::Displacementd &disp)
Eigen::VectorXd maximumVelocityVector
virtual Eigen::MatrixXd getDesiredValues(double time)
Eigen::VectorXd getMaxVelocityVector()
bool eigenVectorToQuaternion(const Eigen::VectorXd &quatVec, Eigen::Rotation3d &quat)