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 namespace Qontrol {
34 namespace Task {
47 class GenericTask {
48 public:
60  GenericTask(std::string name, int task_dimension, int optim_vector_dimension)
61  : name_{name}, task_dimension_{task_dimension},
62  optim_vector_dimension_{optim_vector_dimension} {
63  resize(task_dimension_, optim_vector_dimension);
64  setSelectionMatrix(Eigen::MatrixXd::Identity(optim_vector_dimension,
65  optim_vector_dimension));
66  setWeightingMatrix(Eigen::MatrixXd::Identity(optim_vector_dimension,
67  optim_vector_dimension));
68  }
69 
80  GenericTask(std::string name, int task_dimension,
81  std::shared_ptr<Model::GenericModel> model_ptr)
82  : name_{name}, task_dimension_{task_dimension},
83  optim_vector_dimension_{model_ptr_->getNrOfDegreesOfFreedom()},
84  model_ptr_{model_ptr} {
85  resize(task_dimension_, optim_vector_dimension_);
86  setSelectionMatrix(Eigen::MatrixXd::Identity(optim_vector_dimension_,
87  optim_vector_dimension_));
88  setWeightingMatrix(Eigen::MatrixXd::Identity(optim_vector_dimension_,
89  optim_vector_dimension_));
90  }
96  std::string getName();
97 
105  void resize(int input_size, int output_size);
106 
113  void setE(Eigen::MatrixXd E);
114 
121  void setf(Eigen::VectorXd f);
122 
128  virtual void update(double dt){};
129 
140  Eigen::MatrixXd getHessian();
141 
152  Eigen::VectorXd getGradient();
153 
159  void setSelectionMatrix(Eigen::MatrixXd selection_matrix);
160 
166  void setWeightingMatrix(Eigen::MatrixXd weighting_matrix);
167 
173  Eigen::MatrixXd getSelectionMatrix();
174 
180  Eigen::MatrixXd getWeightingMatrix();
181 
182 protected:
183  std::shared_ptr<Model::GenericModel> model_ptr_;
184  std::string name_;
185  Eigen::MatrixXd E_;
186  Eigen::VectorXd f_;
187  Eigen::MatrixXd selection_matrix_;
188  Eigen::MatrixXd weighting_matrix_;
189  int task_dimension_;
190  int optim_vector_dimension_;
191 };
192 } // namespace Task
193 } // namespace Qontrol
Qontrol::Task::GenericTask::setE
void setE(Eigen::MatrixXd E)
Set the matrix in .
Definition: GenericTask.cpp:24
Qontrol::Task::GenericTask::getGradient
Eigen::VectorXd getGradient()
Get the gradient vector.
Definition: GenericTask.cpp:20
Qontrol::Task::GenericTask::setWeightingMatrix
void setWeightingMatrix(Eigen::MatrixXd weighting_matrix)
Set the task weighting matrix.
Definition: GenericTask.cpp:53
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:45
Qontrol::Task::GenericTask::setf
void setf(Eigen::VectorXd f)
Set the vector in .
Definition: GenericTask.cpp:35
Qontrol::Task::GenericTask::getSelectionMatrix
Eigen::MatrixXd getSelectionMatrix()
Get the selection matrix.
Definition: GenericTask.cpp:61
Qontrol::Task::GenericTask::getHessian
Eigen::MatrixXd getHessian()
Get the hessian matrix related to the task.
Definition: GenericTask.cpp:16
Qontrol::Task::GenericTask
Represents a generic task.
Definition: GenericTask.hpp:47
Qontrol::Task::GenericTask::getWeightingMatrix
Eigen::MatrixXd getWeightingMatrix()
Get the weighting matrix.
Definition: GenericTask.cpp:64
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:80
Qontrol::Task::GenericTask::update
virtual void update(double dt)
Update and . overrided by the considered implementation of the task.
Definition: GenericTask.hpp:128
Qontrol::Task::GenericTask::GenericTask
GenericTask(std::string name, int task_dimension, int optim_vector_dimension)
Construct a new GenericTask object.
Definition: GenericTask.hpp:60
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