ocra-recipes
Doxygen documentation for the ocra-recipes repository
HocraController.cpp
Go to the documentation of this file.
2 
3 
4 namespace hocra {
5 using namespace ocra;
6 
7 
8 
9 HocraController::HocraController(const std::string& _ctrlName,
10  Model::Ptr _innerModel,
11  OneLevelSolver::Ptr _levelSolver,
12  bool _useReducedProblem):
13  Controller(_ctrlName, *_innerModel),
14  innerModel(_innerModel),
15  cascadeQPSolver(new CascadeQPSolver(_ctrlName,_innerModel,_levelSolver,_useReducedProblem))
16 {
17  std::cout <<"Constructing Hocra Controller"<<std::endl;
18 }
19 
21 {
22  std::cout << "HocraController::doAddContactSet" << std::endl;
23 }
24 void HocraController::doAddTask(Task::Ptr task)
25 {
26  std::cout << "Adding task "<<task->getName()<<" at level "<<task->getHierarchyLevel() << std::endl;
27  cascadeQPSolver->addTask(task);
28 }
29 
31 {
32  auto tasks = getActiveTasks();
33 
34  for(auto task : tasks)
35  {
36  task->update();
37  }
38  try {
39  if(!cascadeQPSolver->solve().info)
40  {
41  tau = innerModel->getJointTorqueVariable().getValue();
42  }
43  }catch(const std::exception & e) {
44  std::cerr << e.what() ;
45  throw std::runtime_error("[HocraController::doComputeOutput] Error while computing output");
46  }
47 }
48 Task::Ptr HocraController::doCreateContactTask(const std::string& name, PointContactFeature::Ptr feature, double mu, double margin) const
49 {
50  std::cout << "HocraController::doCreateContactTask" << std::endl;
51  return std::make_shared<ocra::Task>(name, innerModel, feature);
52 
53 }
54 Task::Ptr HocraController::doCreateTask(const std::string& name, Feature::Ptr feature, Feature::Ptr featureDes) const
55 {
56  std::cout << "HocraController::doCreateTask des" << std::endl;
57  return std::make_shared<ocra::Task>(name, innerModel, feature, featureDes);
58 
59 }
60 Task::Ptr HocraController::doCreateTask(const std::string& name, Feature::Ptr feature) const
61 {
62  std::cout << "HocraController::doCreateTask" << std::endl;
63  return std::make_shared<ocra::Task>(name, innerModel, feature);
64 }
65 
66 }
Task::Ptr doCreateContactTask(const std::string &name, ocra::PointContactFeature::Ptr feature, double mu, double margin) const
Task::Ptr doCreateTask(const std::string &name, ocra::Feature::Ptr feature) const
Contact task factory.
Definition: ContactSet.h:59
virtual void doAddContactSet(const ContactSet &contacts)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Interface for controllers.
Definition: Controller.h:53
virtual void doAddTask(Task::Ptr task)
virtual void doComputeOutput(VectorXd &tau)
HocraController(const std::string &ctrlName, Model::Ptr innerModel, OneLevelSolver::Ptr innerSolver, bool useReducedProblem)
const std::vector< std::shared_ptr< Task > > & getActiveTasks() const
Definition: Controller.cpp:394
CascadeQPSolver class.