Qontrol
GenericTask.hpp
1 // This file is part of Qontrol, a quadratic optimization library to
2 // control robot.
3 //
4 // Copyright (C) 2023 Lucas Joseph <lucas.joseph@inria.fr>
5 //
6 // Qontrol is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 3 of
14 // the License, or (at your option) any later version.
15 //
16 // Qontrol is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Qontrol. If not, see <http://www.gnu.org/licenses/>.
24 
25 #pragma once
26 #include <iostream>
27 #include <memory>
28 
29 #include "Eigen/Dense"
30 #include <Qontrol/Model/GenericModel.hpp>
31 #include <Qontrol/Utils/Size.hpp>
32 #include <Qontrol/Problem/ResolutionStrategy.hpp>
33 #include <Qontrol/Problem/ReferenceFrame.hpp>
34 namespace Qontrol {
36 namespace Task {
49 class GenericTask {
50 public:
62  GenericTask(std::string name, int task_dimension, int optim_vector_dimension)
63  : name_{name}, task_dimension_{task_dimension},
64  optim_vector_dimension_{optim_vector_dimension},
65  resolution_strategy_{ResolutionStrategy::Weighted},
66  controled_frame_name_{""},
67  subStateMatrix_{Eigen::MatrixXd::Zero(optim_vector_dimension_,optim_vector_dimension_)},
68  reference_frame_{ReferenceFrame::LOCAL} {
69  resize(task_dimension_, optim_vector_dimension);
70 
71  setSelectionMatrix(Eigen::MatrixXd::Identity(task_dimension_,
72  task_dimension_));
73  setWeightingMatrix(Eigen::MatrixXd::Identity(task_dimension_,
74  task_dimension_));
75  }
76 
87  GenericTask(std::string name, int task_dimension,
88  std::shared_ptr<Model::GenericModel> model_ptr)
89  : name_{name}, task_dimension_{task_dimension},
90  optim_vector_dimension_{model_ptr->getNrOfDegreesOfFreedom()},
91  model_ptr_{model_ptr},
92  resolution_strategy_{ResolutionStrategy::Weighted} ,
93  controled_frame_name_{model_ptr->getTipFrameName()},
94  subStateMatrix_{Eigen::MatrixXd::Zero(optim_vector_dimension_,optim_vector_dimension_)},
95  reference_frame_{ReferenceFrame::LOCAL} {
96  resize(task_dimension_, optim_vector_dimension_);
97  setSelectionMatrix(Eigen::MatrixXd::Identity(task_dimension_,
98  task_dimension_));
99  setWeightingMatrix(Eigen::MatrixXd::Identity(task_dimension_,
100  task_dimension_));
101  }
107  std::string getName();
108 
116  void resize(int input_size, int output_size);
117 
124  void setE(Eigen::MatrixXd E);
125 
132  void setf(Eigen::VectorXd f);
133 
139  virtual void update(double dt){};
140 
151  Eigen::MatrixXd getHessian();
152 
163  Eigen::VectorXd getGradient();
164 
170  void setSelectionMatrix(Eigen::MatrixXd selection_matrix);
171 
177  void setWeightingMatrix(Eigen::MatrixXd weighting_matrix);
178 
184  Eigen::MatrixXd getSelectionMatrix();
185 
191  Eigen::MatrixXd getWeightingMatrix();
192 
193  Eigen::MatrixXd getJacobianGHC();
194 
195  int getTaskDimension();
196 
197  void setResolutionStrategy(ResolutionStrategy resolution_strategy);
198 
199  void setControledFrameName(std::string frame_name);
200 
201  void setReferenceFrame(ReferenceFrame reference_frame);
202 
203  void setSubStateMatrix(Eigen::MatrixXd &subStateMatrix);
204 
205 
206 protected:
207  std::shared_ptr<Model::GenericModel> model_ptr_;
208  std::string name_;
209  Eigen::MatrixXd E_;
210  Eigen::VectorXd f_;
211  Eigen::MatrixXd selection_matrix_;
212  Eigen::MatrixXd weighting_matrix_;
213  int task_dimension_;
214  int optim_vector_dimension_;
215  ResolutionStrategy resolution_strategy_;
216  Eigen::MatrixXd subStateMatrix_;
217  std::string controled_frame_name_;
218  ReferenceFrame reference_frame_;
219 };
220 } // namespace Task
221 } // namespace Qontrol
Qontrol::Task::GenericTask::setE
void setE(Eigen::MatrixXd E)
Set the matrix in .
Definition: GenericTask.cpp:29
Qontrol::Task::GenericTask::getGradient
Eigen::VectorXd getGradient()
Get the gradient vector.
Definition: GenericTask.cpp:25
Qontrol::Task::GenericTask::setWeightingMatrix
void setWeightingMatrix(Eigen::MatrixXd weighting_matrix)
Set the task weighting matrix.
Definition: GenericTask.cpp:59
Qontrol::Task::GenericTask::getName
std::string getName()
Get the task name.
Definition: GenericTask.cpp:9
Qontrol::Task::GenericTask::setSelectionMatrix
void setSelectionMatrix(Eigen::MatrixXd selection_matrix)
Set the task selection matrix.
Definition: GenericTask.cpp:50
Qontrol::Task::GenericTask::setf
void setf(Eigen::VectorXd f)
Set the vector in .
Definition: GenericTask.cpp:40
Qontrol::Task::GenericTask::getSelectionMatrix
Eigen::MatrixXd getSelectionMatrix()
Get the selection matrix.
Definition: GenericTask.cpp:68
Qontrol::Task::GenericTask::getHessian
Eigen::MatrixXd getHessian()
Get the hessian matrix related to the task.
Definition: GenericTask.cpp:21
Qontrol::Task::GenericTask
Represents a generic task.
Definition: GenericTask.hpp:49
Qontrol::Task::GenericTask::getWeightingMatrix
Eigen::MatrixXd getWeightingMatrix()
Get the weighting matrix.
Definition: GenericTask.cpp:71
Qontrol::Task::GenericTask::GenericTask
GenericTask(std::string name, int task_dimension, std::shared_ptr< Model::GenericModel > model_ptr)
Construct a new Base Task object.
Definition: GenericTask.hpp:87
Qontrol::Task::GenericTask::update
virtual void update(double dt)
Update and . overrided by the considered implementation of the task.
Definition: GenericTask.hpp:139
Qontrol::Task::GenericTask::GenericTask
GenericTask(std::string name, int task_dimension, int optim_vector_dimension)
Construct a new GenericTask object.
Definition: GenericTask.hpp:62
Qontrol::Task::GenericTask::resize
void resize(int input_size, int output_size)
Resize the matrix and vector according to the task.
Definition: GenericTask.cpp:11