30 #define VAR_THRESH 0.99 42 if(this->isRunning()) {
49 const std::string& taskName,
56 task = std::make_shared<TaskConnection>(taskName);
57 task->openControlPorts();
62 const std::string& taskName,
63 const Eigen::MatrixXd& waypoints,
71 task = std::make_shared<TaskConnection>(taskName);
72 task->openControlPorts();
77 const std::string& taskName,
78 const std::list<Eigen::VectorXd>& waypoints,
86 task = std::make_shared<TaskConnection>(taskName);
87 task->openControlPorts();
119 trajectory = std::make_shared<ocra::MinimumJerkTrajectory>();
122 trajectory = std::make_shared<ocra::LinearInterpolationTrajectory>();
126 trajectory = std::make_shared<ocra::GaussianProcessTrajectory>();
128 std::cout <<
"You need the SMLT libs to use GAUSSIAN_PROCESS type trajectories. I'm gonna make you a MIN_JERK instead." << std::endl;
130 trajectory = std::make_shared<ocra::MinimumJerkTrajectory>();
135 trajectory = std::make_shared<ocra::TimeOptimalTrajectory>();
137 std::cout <<
"You need the GTTraj libs to use TIME_OPTIMAL type trajectories. I'm gonna make you a MIN_JERK instead." << std::endl;
139 trajectory = std::make_shared<ocra::MinimumJerkTrajectory>();
167 task->closeControlPorts();
168 std::cout<<
"\nTrajectoryThread: Trajectory thread finished.\n";
190 std::cout <<
"Trajectory thread for task: " <<
task->getTaskName() <<
" has attained its goal state. Awaiting new commands." << std::endl;
220 if(
task->deactivate()){
224 std::cout <<
"[WARNING] Trajectory thread for task: " <<
task->getTaskName() <<
" has attained its goal state, but cannot be deactivated." << std::endl;
225 yarp::os::Time::delay(1.0);
228 std::cout <<
"[WARNING] Deactivation timeout." << std::endl;
256 if(
task->deactivate()){
260 std::cout <<
"[WARNING] Trajectory thread for task: " <<
task->getTaskName() <<
" has attained its goal state, but cannot be deactivated." << std::endl;
261 yarp::os::Time::delay(1.0);
264 std::cout <<
"[WARNING] Deactivation timeout." << std::endl;
271 std::cout <<
"Trajectory thread for task: " <<
task->getTaskName() <<
" has attained its goal state. Awaiting new commands." << std::endl;
277 if(
task->deactivate()){
280 std::cout <<
"Trajectory thread for task: " <<
task->getTaskName() <<
" has attained its goal state. Deactivating task and awaiting new commands." << std::endl;
284 std::cout <<
"Trajectory thread for task: " <<
task->getTaskName() <<
" has attained its goal state and is awaiting new commands. [WARNING] Could not deactivate the task." << std::endl;
285 yarp::os::Time::delay(1.0);
289 std::cout <<
"[WARNING] Deactivation timeout." << std::endl;
305 Eigen::MatrixXd desiredState_tmp;
335 desiredState_tmp =
trajectory->getDesiredValues(relativeTime);
341 task->setDesiredTaskStateDirect(matrixToTaskState(desiredState_tmp));
367 Eigen::VectorXd desiredWeights = (Eigen::VectorXd::Ones(desiredVariance.rows()) - desiredVariance) / beta;
368 return desiredWeights;
390 for (
auto rit = wptListCopy.rbegin(); rit!= wptListCopy.rend(); ++rit){
398 int c_tmp = nCols - 1;
399 for(
int c=0; c<nCols; c++)
420 tmp.rightCols(nCols-1) =
allWaypoints.leftCols(nCols-1);
431 if(containsStartingWaypoint)
439 for(
int i=0; i<_userWaypoints.cols(); i++)
463 std::cout <<
"[ERROR](TrajectoryThread::setTrajectoryWaypoints): The dimension (# DOF) of the waypoints you provided, " << _userWaypoints.rows() <<
", does not match the dimension of the task, " <<
weightDimension <<
". Thread not starting." << std::endl;
474 if(!containsStartingWaypoint)
491 std::cout <<
"[ERROR](TrajectoryThread::setTrajectoryWaypoints): The dimension (# DOF) of the waypoints you provided, " << waypointList.begin()->rows() <<
", does not match the dimension of the task, " <<
weightDimension <<
". Thread not starting." << std::endl;
507 Eigen::MatrixXd tmpWaypoints = Eigen::MatrixXd::Zero(
weightDimension, 2);
518 ocra::TaskState TrajectoryThread::matrixToTaskState(
const Eigen::MatrixXd& desMat)
522 case ocra::Task::META_TASK_TYPE::UNKNOWN:
526 case ocra::Task::META_TASK_TYPE::POSITION:
532 case ocra::Task::META_TASK_TYPE::ORIENTATION:
538 case ocra::Task::META_TASK_TYPE::POSE:
544 case ocra::Task::META_TASK_TYPE::FORCE:
548 case ocra::Task::META_TASK_TYPE::COM:
554 case ocra::Task::META_TASK_TYPE::COM_MOMENTUM:
560 case ocra::Task::META_TASK_TYPE::PARTIAL_POSTURE:
562 desState.
setQ(desMat.col(POS_COL));
563 desState.
setQd(desMat.col(VEL_COL));
564 desState.
setQdd(desMat.col(ACC_COL));
566 case ocra::Task::META_TASK_TYPE::FULL_POSTURE:
568 desState.
setQ(desMat.col(POS_COL));
569 desState.
setQd(desMat.col(VEL_COL));
570 desState.
setQdd(desMat.col(ACC_COL));
572 case ocra::Task::META_TASK_TYPE::PARTIAL_TORQUE:
576 case ocra::Task::META_TASK_TYPE::FULL_TORQUE:
600 Eigen::VectorXd TrajectoryThread::getCurrentTaskStateAsVector()
606 case ocra::Task::META_TASK_TYPE::UNKNOWN:
610 case ocra::Task::META_TASK_TYPE::POSITION:
612 startVector = state.
getPosition().getTranslation();
614 case ocra::Task::META_TASK_TYPE::ORIENTATION:
616 Eigen::Rotation3d quat = state.
getPosition().getRotation();
617 startVector = Eigen::VectorXd(4);
618 startVector << quat.w(), quat.x(), quat.y(), quat.z();
620 case ocra::Task::META_TASK_TYPE::POSE:
623 startVector = Eigen::VectorXd(7);
624 startVector << disp.x(), disp.y(), disp.z(), disp.qw(), disp.qx(), disp.qy(), disp.qz();
626 case ocra::Task::META_TASK_TYPE::FORCE:
630 case ocra::Task::META_TASK_TYPE::COM:
632 startVector = state.
getPosition().getTranslation();
635 case ocra::Task::META_TASK_TYPE::COM_MOMENTUM:
637 startVector = state.
getPosition().getTranslation();
640 case ocra::Task::META_TASK_TYPE::PARTIAL_POSTURE:
642 startVector = state.
getQ();
645 case ocra::Task::META_TASK_TYPE::FULL_POSTURE:
647 startVector = state.
getQ();
650 case ocra::Task::META_TASK_TYPE::PARTIAL_TORQUE:
655 case ocra::Task::META_TASK_TYPE::FULL_TORQUE:
717 void TrajectoryThread::setMeanWaypoints(std::vector<bool>& isMeanWaypoint)
722 void TrajectoryThread::setVarianceWaypoints(std::vector<bool>& isVarWaypoint)
727 void TrajectoryThread::setOptimizationWaypoints(std::vector<bool>& isOptWaypoint)
732 void TrajectoryThread::setDofToOptimize(std::vector<Eigen::VectorXi>& dofToOptimize)
737 Eigen::VectorXd TrajectoryThread::getBayesianOptimizationVariables()
ocra::Task::META_TASK_TYPE taskType
void setPosition(const Eigen::Displacementd &newPosition)
void setTorque(const Eigen::VectorXd &newTorque)
void setAcceleration(const Eigen::Twistd &newAcceleration)
virtual bool threadInit()
std::list< Eigen::VectorXd > userWaypointList
bool isTaskCurrentlyActive
Eigen::Twistd eigenVectorToTwistd(const Eigen::VectorXd &eigenVector, bool linearOnly=true, bool angularOnly=false)
void setVelocity(const Eigen::Twistd &newVelocity)
Eigen::ArrayXd varianceThresh
TrajectoryThread(int period, const std::string &taskPortName, const TRAJECTORY_TYPE=MIN_JERK, const TERMINATION_STRATEGY _terminationStrategy=STOP_THREAD)
virtual void threadRelease()
std::shared_ptr< TaskConnection > task
void setMaxVelocity(double maxVel)
bool isUsingTerminationStrategy
Eigen::VectorXd getQ() const
bool setDisplacement(double dispDouble)
bool waypointsHaveBeenSet
Eigen::VectorXd startStateVector
void setQd(const Eigen::VectorXd &newQd)
void setMaxVelocityAndAcceleration(double maxVel, double maxAcc)
yarp::os::Bottle desStateBottle
Eigen::Displacementd eigenVectorToDisplacementd(const Eigen::VectorXd &eigenVector)
bool setTrajectoryWaypoints(const Eigen::MatrixXd &userWaypoints, bool containsStartingWaypoint=false)
Eigen::VectorXd getTorque() const
std::shared_ptr< ocra::Trajectory > trajectory
Eigen::Wrenchd eigenVectorToWrenchd(const Eigen::VectorXd &eigenVector, bool linearOnly=true, bool angularOnly=false)
std::list< Eigen::VectorXd > allWaypointList
A thread for launching trajectory generators.
void setMaxAcceleration(double maxAcc)
bool printWaitingNoticeOnce
void setQdd(const Eigen::VectorXd &newQdd)
Eigen::Wrenchd getWrench() const
std::list< Eigen::VectorXd > getWaypointList()
Eigen::MatrixXd userWaypoints
double deactivationTimeout
double timeElapsedDuringPause
Eigen::VectorXd varianceToWeights(Eigen::VectorXd &desiredVariance, const double beta=1.0)
Eigen::VectorXd desiredVariance
void setWrench(const Eigen::Wrenchd &newWrench)
void setQ(const Eigen::VectorXd &newQ)
Eigen::Displacementd getPosition() const
TERMINATION_STRATEGY terminationStrategy
Eigen::MatrixXd allWaypoints
bool useVarianceModulation
Eigen::VectorXd goalStateVector