31 Eigen::MatrixXd::Identity(m->getJointTorqueVariable().getSize(),
32 m->getJointTorqueVariable().getSize()),
33 Eigen::VectorXd::Zero(m->getJointTorqueVariable().getSize())) ))
35 , minFcFunction( new
FcQuadraticFunction(m->getModelContacts().getContactForcesVariable()) )
38 minDdqObjective.
set(minDdqFunction);
39 minTauObjective.
set(minTauFunction);
40 minFcObjective.
set(minFcFunction);
52 Model::Ptr _innerModel,
53 OneLevelSolver::Ptr _levelSolver,
54 bool _useReducedProblem):
75 for(
auto m : solvermap)
77 if(level == m.first)
return;
79 auto solver = m.second;
80 Eigen::VectorXd full_solution = solver->getLastResult().solution;
83 for(
auto obj : solver->getObjectives())
88 if(has_element(_exclusion_constraints[m.first],&obj->getFunction()))
98 const std::vector<int>& mapping = solver->findMapping(obj->getVariable());
102 Eigen::VectorXd minus_solution(var.getSize());
103 for(
int i=0;i<mapping.size();i++)
104 minus_solution[i] = - full_solution[mapping[i]];
109 if(levelConstraints[level][m.first].find(&f_obj) == levelConstraints[level][m.first].end())
114 getSolver(level)->addConstraint(levelConstraints[level][m.first][&f_obj].getConstraint());
120 auto& f = levelConstraints[level][m.first][&f_obj].getFunction();
121 f.changeb( f_obj.getA() * minus_solution );
122 f.changeA( f_obj.getA() );
131 for(
auto m : solvermap)
132 if(m.first == current_level)
143 for(
auto m : solvermap)
150 tmp_res = m.second->solve();
179 return this->solvermap;
185 if(solvermap.find(level) == solvermap.end())
187 bool solverexists =
false;
188 for(
auto sm : solvermap)
189 if(sm.second.get() == solver.get())
194 this->solvermap[level] = solver->clone();
197 this->solvermap[level] = solver;
216 return solvermap.at(level);
221 if(_exclusion_constraints.find(at_level) == _exclusion_constraints.end() ||
222 has_element(_exclusion_constraints[at_level],&obj.
getFunction()) ==
false)
225 _exclusion_constraints[at_level].push_back(&obj.
getFunction());
234 const int level = task->getHierarchyLevel();
235 if(task->isActiveAsObjective())
236 this->taskmap[level].push_back(task);
237 else if(task->isActiveAsConstraint())
238 for(
auto& tm : taskmap)
239 this->taskmap[level].push_back(task);
248 new_solver->addConstraint(
std_obj[level]->dynamicEquation.getConstraint());
249 new_solver->addObjective(
std_obj[level]->minDdqObjective);
250 new_solver->addObjective(
std_obj[level]->minTauObjective);
260 task->connectToController(this->
getSolver(level),
261 std_obj[level]->dynamicEquation,
264 catch(
const std::exception & e) {
265 std::cerr << e.what() ;
266 throw std::runtime_error(
"[HocraController::doAddTask] cannot add task to controller (wrong type)");
virtual void doConclude()
const Variable & getVariable() const
ocra::EqualZeroConstraintPtr< ocra::FullDynamicEquationFunction > dynamicEquation
OneLevelSolver::Ptr levelSolver
ObjectivePtr< ocra::QuadraticFunction > minFcObjective
void internalAddConstraint(const GenericConstraint &constraint)
virtual void doPrepare(void)
virtual void printValuesAtSolution()
int getNumberOfLevelsAbove(int current_level)
void excludeObjective(int at_level, const ocra::GenericObjective &obj)
void internalAddObjective(const GenericObjective &objective)
OptimizationResult _result
std::shared_ptr< StandardObjectivesAndConstraints > own_obj
CascadeQPSolver(const std::string &_ctrlName, Model::Ptr _innerModel, OneLevelSolver::Ptr _levelSolver, bool _useReducedProblem)
ObjectivePtr< ocra::QuadraticFunction > minTauObjective
Objective< T > & getObjective()
ObjectivePtr< ocra::QuadraticFunction > minDdqObjective
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
void takeIntoAccountGravity(bool useGrav)
StandardObjectivesAndConstraints(Model::Ptr m)
virtual T & getFunction(void)
OneLevelSolver::Ptr getSolver(int level)
Create a linear function that represents the dynamic equation of motion.
SquaredLinearFunction class.
virtual void doSolve(void)
ocra::QuadraticFunction * minDdqFunction
std::map< int, std::shared_ptr< StandardObjectivesAndConstraints > > std_obj
ocra::FcQuadraticFunction * minFcFunction
virtual Function & getFunction()
void updateHierarchicalContraints(int level)
void addTask(Task::Ptr task)
Declaration file of the CascadeQPSolver class.
ocra::QuadraticFunction * minTauFunction
void set(T *f, double weight=1.)
std::vector< int > solverInitialized
void addSolver(OneLevelSolver::Ptr solver, int level)
virtual std::string toString()
const std::map< int, OneLevelSolver::Ptr > & getSolvers()