56 , isFreeFloating(m.nbDofs() - m.nbInternalDofs()>0)
62 , totalActiveTaskDim(0)
63 , augmentedJacobian(MatrixXd::Zero(1,m.nbDofs()))
87 , pimpl( new
Pimpl(ctrlName, innerModel, innerSolver, useGrav) )
89 if (pimpl->isFreeFloating)
90 pimpl->innerSolver.addConstraint(pimpl->seConstraint.getConstraint());
98 for (
size_t i=0; i<pimpl->createdTask.size(); ++i)
100 pimpl->createdTask[i]->disconnectFromController();
101 delete pimpl->createdTask[i];
104 if (pimpl->isFreeFloating)
105 pimpl->innerSolver.removeConstraint(pimpl->seConstraint.getConstraint());
115 return pimpl->innerModel;
123 return pimpl->innerSolver;
136 pimpl->innerSolver.addConstraint(constraint);
142 pimpl->innerSolver.removeConstraint(constraint);
169 catch(
const std::exception & e) {
170 std::cerr << e.what() ;
171 throw std::runtime_error(
"[GHCJTController::doAddTask] cannot add task to controller (wrong type)");
182 throw std::runtime_error(
"[GHCJTController::doAddTask] not implemented");
190 auto taskPtr =
createTask(name, feature, featureDes).get();
191 return dynamic_cast<GHCJTTask&
>(*taskPtr);
196 auto taskPtr =
createTask(name, feature).get();
197 return dynamic_cast<GHCJTTask&
>(*taskPtr);
203 return dynamic_cast<GHCJTTask&
>(*taskPtr);
223 pimpl->createdTask.push_back(nTask);
239 pimpl->createdTask.push_back(nTask);
257 pimpl->createdTask.push_back(nTask);
274 pimpl->updateTasksRecorder.initializeTime();
280 tau.resize(pimpl->innerModel.nbInternalDofs());
284 if (pimpl->useGrav && pimpl->isFreeFloating)
287 VectorXd b = pimpl->innerModel.getGravityTerms().head(pimpl->innerModel.nbDofs() - pimpl->innerModel.nbInternalDofs());
289 pimpl->seConstraint.getFunction().changeb(b);
292 for(
size_t i=0; i< tasks.size(); ++i)
300 pimpl->updateTasksRecorder.saveRelativeTime();
301 pimpl->solveProblemRecorder.initializeTime();
302 if(!pimpl->innerSolver.solve().info)
305 tau = pimpl->innerModel.getGravityTerms().tail(pimpl->innerModel.nbInternalDofs());
307 for(
int i = 0; i < tasks.size(); ++i)
328 pimpl->solveProblemRecorder.saveRelativeTime();
343 pimpl->updateTasksRecorder.writeInStream(
"controller_update_tasks", outstream,
true);
344 pimpl->solveProblemRecorder.writeInStream(
"controller_solve_problem", outstream,
true);
345 pimpl->innerSolver.writePerformanceInStream(outstream, addCommaAtEnd);
373 std::ostringstream osstream;
378 return osstream.str();
383 pimpl->activeTask.clear();
384 int totalTaskDim = 0;
385 for (
int i=0; i<pimpl->createdTask.size(); ++i)
387 if (pimpl->createdTask[i]->isActiveAsObjective())
389 if(!pimpl->createdTask[i]->isPointContactTask())
391 pimpl->activeTask.push_back(pimpl->createdTask[i]);
392 totalTaskDim += pimpl->createdTask[i]->getTaskDimension();
393 pimpl->createdTask[i]->setWeight(1);
397 pimpl->nbActiveTask = pimpl->activeTask.size();
398 pimpl->totalActiveTaskDim = totalTaskDim;
407 int nDof = pimpl->innerModel.nbDofs();
408 MatrixXd jacobian=MatrixXd::Zero(pimpl->totalActiveTaskDim, nDof);
413 for (
int i=0; i<pimpl->nbActiveTask; ++i)
415 taskdim = pimpl->activeTask[i]->getDimension();
416 jacobian.block(rowindex,0, taskdim, nDof)=pimpl->activeTask[i]->getJacobian();
419 pimpl->augmentedJacobian = jacobian;
425 const int nDof = pimpl->innerModel.nbDofs();
426 MatrixXd proj(nDof,nDof);
427 MatrixXd taskiProj(nDof,nDof);
428 for (
int i=0; i<pimpl->nbActiveTask; ++i)
431 computeProjector(pimpl->activeTask[i]->getPriority(), pimpl->augmentedJacobian, proj);
432 pimpl->activeTask[i]->setProjector(proj);
434 pimpl->activeTask[i]->setTaskiProjector(taskiProj);
439 return pimpl->activeTask;
444 return pimpl->nbActiveTask;
449 return pimpl->totalActiveTaskDim;
456 for (
int i=0; i<pimpl->activeTask.size(); ++i)
458 dim = pimpl->activeTask[i]->getTaskDimension();
459 pimpl->activeTask[i]->setIndexBegin(dim_alpha);
460 pimpl->activeTask[i]->setIndexEnd(dim_alpha + dim);
469 int totalTaskDim = J.rows();
471 MatrixXd Cii_J = MatrixXd::Zero(totalTaskDim, 1+nDof);
473 Cii_J.col(0) = C.diagonal();
474 Cii_J.block(0,1,totalTaskDim,nDof) = J;
476 int rdim = Cii_J.rows();
477 VectorXd tmp= VectorXd::Zero(1+nDof);
478 for (
int rmin=0; rmin<rdim-1;++rmin)
480 for(
int i=rdim-1; i>rmin; --i)
482 if (Cii_J(i,0)>Cii_J(i-1,0))
484 tmp = Cii_J.row(i-1);
485 Cii_J.row(i-1) = Cii_J.row(i);
491 return std::pair<VectorXd, MatrixXd>(Cii_J.col(0),Cii_J.block(0,1,totalTaskDim,nDof));
496 int totalTaskDim = J.rows();
497 const int nDof = pimpl->innerModel.nbDofs();
499 MatrixXd Js(totalTaskDim, nDof);
501 std::pair<VectorXd, MatrixXd> sortedMatrix =
sortRows(C,J);
502 Cs = sortedMatrix.first;
503 Js = sortedMatrix.second;
506 MatrixXd onb_Js = onfamily.
getOnf();
513 for (
int j=0; j<k; ++j)
515 Chat(j)=Cs(origin(j));
519 MatrixXd alpha = MatrixXd(Chat.asDiagonal());
529 projector = MatrixXd::Identity(nDof,nDof) - onb_Js.transpose()*alpha*onb_Js;
537 MatrixXd onb_Js = onfamily.
getOnf();
538 const int nDof = pimpl->innerModel.nbDofs();
540 projector = MatrixXd::Identity(nDof,nDof) - onb_Js.transpose()*onb_Js;
550 MatrixXd m_priority(pimpl->totalActiveTaskDim,pimpl->totalActiveTaskDim);
551 m_priority.setZero();
553 int nt = pimpl->nbActiveTask;
554 for (
int i=0; i<nt; ++i)
556 for (
int j=0; j<nt; ++j)
558 dim_j = pimpl->activeTask[j]->getTaskDimension();
559 vec_ij = VectorXd::Zero(dim_j);
560 vec_ij = vec_ij.setConstant(param(i,j));
561 m_priority.block(pimpl->activeTask[j]->getIndexBegin(), pimpl->activeTask[j]->getIndexBegin(),dim_j,dim_j) = MatrixXd(vec_ij.asDiagonal());
564 pimpl->activeTask[i]->setPriority(m_priority);
568 const int nDof = pimpl->innerModel.nbDofs();
569 MatrixXd proj(nDof,nDof);
570 MatrixXd taskiProj(nDof,nDof);
572 for (
int i=0; i<pimpl->nbActiveTask; ++i)
574 computeProjector(pimpl->activeTask[i]->getPriority(), pimpl->augmentedJacobian, proj);
575 pimpl->activeTask[i]->setProjector(proj);
577 pimpl->activeTask[i]->setTaskiProjector(taskiProj);
void setErrorFlag(int eflag)
GHCJTController(const std::string &ctrlName, Model &innerModel, ocra::OneLevelSolver &innerSolver, bool useGrav)
int getNbActiveTask() const
ocra::OneLevelSolver & innerSolver
Define task class for GHCJT controller. It inherits from the task class defined in the ocra framework...
const Eigen::MatrixXd & getJacobian() const
std::pair< Eigen::VectorXd, Eigen::MatrixXd > sortRows(const Eigen::MatrixXd &C, const Eigen::MatrixXd &J)
const Eigen::VectorXi & getOrigin() const
ocra::OneLevelSolver & getSolver()
const VectorXd & getValue() const
int getTotalActiveTaskDimensions() const
PerformanceRecorder solveProblemRecorder
EqualZeroConstraintPtr< SumOfLinearFunctions > seConstraint
void connectToController(ocra::OneLevelSolver &_solver, SumOfLinearFunctions &seConstraint)
void addConstraint(ocra::LinearConstraint &constraint) const
virtual ~GHCJTController()
void removeConstraint(ocra::LinearConstraint &constraint) const
Define the internal solver class that can be used in the wOcra controller.
Declaration file of the Model class.
std::vector< GHCJTTask * > & getActiveTask()
const Variable & getVariable() const
void initPriorityMatrix()
A class hierarchy to compute task errors based on control frames.
void takeIntoAccountGravity(bool useGrav)
std::vector< GHCJTTask * > activeTask
void setActiveTaskVector()
MatrixXd augmentedJacobian
virtual void doAddContactSet(const ContactSet &contacts)
bool isBodyContactConstraint() const
std::string getPerformances() const
void computeProjector(const Eigen::MatrixXd &C, const Eigen::MatrixXd &J, Eigen::MatrixXd &projector)
Interface for controllers.
Define the Generalized Hierarchical Controller based on Jacobian transpose (GHCJT) in quasi-static ca...
virtual Task * doCreateContactTask(const std::string &name, PointContactFeature::Ptr feature, double mu, double margin) const
const Eigen::MatrixXd & getOnf() const
A generic abstract task for the GHCJT controller.
virtual void doAddTask(Task &task)
GHCJTTask & createGHCJTContactTask(const std::string &name, PointContactFeature::Ptr feature, double mu, double margin) const
std::shared_ptr< Task > createContactTask(const std::string &name, PointContactFeature::Ptr feature, double mu, double margin) const
Creates a contact task.
const Eigen::MatrixXd & getProjector() const
void computeTaskiProjector(const Eigen::MatrixXd &J, Eigen::MatrixXd &projector)
void computeOrthonormalFamily()
virtual Task * doCreateTask(const std::string &name, Feature::Ptr feature, Feature::Ptr featureDes) const
void doUpdateAugmentedJacobian()
void setTaskProjectors(Eigen::MatrixXd ¶m)
A generic abstract class the solvers that can be used in the wOcra Controller.
void setErrorMessage(const std::string &msg)
virtual void doComputeOutput(Eigen::VectorXd &tau)
PerformanceRecorder updateTasksRecorder
bool isPointContactTask() const
std::shared_ptr< Task > createTask(const std::string &name, Feature::Ptr feature, Feature::Ptr featureDes) const
Generic task creation.
void writePerformanceInStream(std::ostream &myOstream, bool addCommaAtEnd) const
Pimpl(const std::string &name, Model &m, ocra::OneLevelSolver &s, bool useGrav)
GHCJTTask & createGHCJTTask(const std::string &name, Feature::Ptr feature, Feature::Ptr featureDes) const
const std::vector< std::shared_ptr< Task > > & getActiveTasks() const
std::vector< GHCJTTask * > createdTask
Declaration file of the QuadraticFunction class.