47 Pimpl(std::shared_ptr<Model> m, std::shared_ptr<OneLevelSolver> s,
bool useReducedProblem)
53 , reducedProblem(useReducedProblem)
56 , minDdqFunction( new
ocra::
QuadraticFunction(m->getAccelerationVariable(),
Eigen::MatrixXd::Identity(m->nbDofs(), m->nbDofs()),
Eigen::VectorXd::Zero(m->nbDofs()), 0) )
58 , minTauFunction( new
ocra::
QuadraticFunction(m->getJointTorqueVariable(),
Eigen::MatrixXd::Identity(m->getJointTorqueVariable().getSize(), m->getJointTorqueVariable().getSize()),
Eigen::VectorXd::Zero(m->getJointTorqueVariable().getSize()), 0) )
60 , minFcFunction( new
FcQuadraticFunction(m->getModelContacts().getContactForcesVariable()) )
63 minDdqObjective.
set(minDdqFunction);
64 minTauObjective.
set(minTauFunction);
65 minFcObjective.
set(minFcFunction);
84 , pimpl( new
Pimpl(innerModel, innerSolver, useReducedProblem) )
88 if (!pimpl->reducedProblem)
92 pimpl->innerSolver->addConstraint(pimpl->dynamicEquation.getConstraint());
93 pimpl->innerSolver->addObjective(pimpl->minDdqObjective);
94 pimpl->innerSolver->addObjective(pimpl->minTauObjective);
95 pimpl->innerSolver->addObjective(pimpl->minFcObjective);
108 pimpl->innerSolver->addObjective(pimpl->minTauObjective);
109 pimpl->innerSolver->addObjective(pimpl->minFcObjective);
119 const std::map<std::string, std::shared_ptr<Task>>& taskMap =
getTasks();
120 for (std::map<std::string, std::shared_ptr<Task>>::const_iterator it = taskMap.begin(); it != taskMap.end(); ++it)
123 it->second->disconnectFromController();
127 if (!pimpl->reducedProblem)
131 pimpl->innerSolver->removeConstraint(pimpl->dynamicEquation.getConstraint());
132 pimpl->innerSolver->removeObjective(pimpl->minDdqObjective);
133 pimpl->innerSolver->removeObjective(pimpl->minTauObjective);
134 pimpl->innerSolver->removeObjective(pimpl->minFcObjective);
139 pimpl->innerSolver->removeObjective(pimpl->minTauObjective);
140 pimpl->innerSolver->removeObjective(pimpl->minFcObjective);
149 return pimpl->innerModel;
157 return pimpl->innerSolver;
165 return pimpl->reducedProblem;
171 pimpl->minDdqObjective.getObjective().setWeight(w_ddq);
172 pimpl->minTauObjective.getObjective().setWeight(w_tau);
173 pimpl->minFcObjective.getObjective().setWeight(w_fc);
178 pimpl->dynamicEquation.getFunction().takeIntoAccountGravity(useGrav);
183 pimpl->innerSolver->addConstraint(constraint);
188 pimpl->innerSolver->removeConstraint(constraint);
194 pimpl->innerSolver->addConstraint(constraint.
getConstraint());
199 pimpl->innerSolver->removeConstraint(constraint.
getConstraint());
206 task->connectToController(pimpl->innerSolver, pimpl->dynamicEquation, pimpl->reducedProblem);
208 catch(
const std::exception & e) {
209 std::cerr << e.what() ;
210 throw std::runtime_error(
"[WocraController::doAddTask] cannot add task to controller (wrong type)");
218 throw std::runtime_error(
"[WocraController::doAddTask] not implemented");
258 return std::make_shared<ocra::Task>(name, pimpl->innerModel, feature, featureDes);
263 return std::make_shared<ocra::Task>(name, pimpl->innerModel, feature);
268 return std::make_shared<ocra::Task>(name, pimpl->innerModel, feature);
282 pimpl->updateTasksRecorder.initializeTime();
284 const std::vector<std::shared_ptr<Task>>& tasks =
getActiveTasks();
286 for(
auto task : tasks)
291 pimpl->updateTasksRecorder.saveRelativeTime();
294 pimpl->solveProblemRecorder.initializeTime();
295 if(!pimpl->innerSolver->solve().info)
297 tau = pimpl->innerModel->getJointTorqueVariable().getValue();
305 pimpl->solveProblemRecorder.saveRelativeTime();
313 pimpl->updateTasksRecorder.writeInStream(
"controller_update_tasks", outstream,
true);
315 pimpl->solveProblemRecorder.writeInStream(
"controller_solve_problem", outstream,
true);
317 pimpl->innerSolver->writePerformanceInStream(outstream, addCommaAtEnd);
323 std::ostringstream osstream;
328 return osstream.str();
void setErrorFlag(int eflag)
PerformanceRecorder solveProblemRecorder
ObjectivePtr< ocra::QuadraticFunction > minFcObjective
std::shared_ptr< Model > innerModel
std::shared_ptr< Model > getModel()
virtual ~WocraController()
Destructor of Wocra controller.
ocra::QuadraticFunction * minTauFunction
Define the LQP-based controller developped during my PhD thesis with ocra framework.
ObjectivePtr< ocra::QuadraticFunction > minDdqObjective
std::shared_ptr< OneLevelSolver > getSolver()
PerformanceRecorder updateTasksRecorder
virtual void doAddContactSet(const ContactSet &contacts)
Contains all the abstract & concrete classes for robotic control with optimization, based on the ocra framework.
void removeConstraint(ocra::LinearConstraint &constraint) const
virtual void connectToController(const FullDynamicEquationFunction &dynamicEquation, bool useReducedProblem)=0
Pimpl(std::shared_ptr< Model > m, std::shared_ptr< OneLevelSolver > s, bool useReducedProblem)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual void doComputeOutput(Eigen::VectorXd &tau)
Interface for controllers.
WocraController(const std::string &ctrlName, std::shared_ptr< Model > innerModel, std::shared_ptr< OneLevelSolver > innerSolver, bool useReducedProblem)
std::string getPerformances() const
ocra::EqualZeroConstraintPtr< ocra::FullDynamicEquationFunction > dynamicEquation
void takeIntoAccountGravity(bool useGrav)
LinearConstraint & getConstraint()
bool isUsingReducedProblem()
Create a linear function that represents the dynamic equation of motion.
void writePerformanceInStream(std::ostream &myOstream, bool addCommaAtEnd) const
ObjectivePtr< ocra::QuadraticFunction > minTauObjective
ocra::FcQuadraticFunction * minFcFunction
virtual std::shared_ptr< Task > doCreateTask(const std::string &name, Feature::Ptr feature, Feature::Ptr featureDes) const
ocra::QuadraticFunction * minDdqFunction
void setErrorMessage(const std::string &msg)
void setVariableMinimizationWeights(double w_ddq, double w_tau, double w_fc)
virtual void doAddTask(std::shared_ptr< Task > task)
const std::map< std::string, std::shared_ptr< Task > > & getTasks() const
void addConstraint(ocra::LinearConstraint &constraint) const
std::shared_ptr< OneLevelSolver > innerSolver
void set(T *f, double weight=1.)
const std::vector< std::shared_ptr< Task > > & getActiveTasks() const
virtual void disconnectFromController()=0
Declaration file of the QuadraticFunction class.
virtual std::shared_ptr< Task > doCreateContactTask(const std::string &name, PointContactFeature::Ptr feature, double mu, double margin) const