Qontrol
GenericConstraint.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 <memory>
27 
28 #include <Qontrol/Model/GenericModel.hpp>
29 #include <Qontrol/Utils/Size.hpp>
30 #include "Eigen/Dense"
31 namespace Qontrol {
33 namespace Constraint {
48 public:
58  GenericConstraint(std::string name, int constraint_size,int optimization_vector_size)
59  : name_{name}, constraint_size_{constraint_size}, optimization_vector_size_{optimization_vector_size} {
60  resize(constraint_size_,optimization_vector_size_);
61  }
62 
73  GenericConstraint(std::string name,
74  int constraint_size,
75  std::shared_ptr<Model::GenericModel> model_ptr)
76  : name_{name}, model_ptr_{model_ptr},
77  constraint_size_{constraint_size},
78  optimization_vector_size_{model_ptr->getNrOfDegreesOfFreedom()} {
79  resize(constraint_size_,optimization_vector_size_);
80  }
81 
87  virtual void update(double dt){};
88 
94  int getSize();
95 
101  std::string getName();
102 
108  void setConstraintMatrix(Eigen::MatrixXd constraint_matrix);
109 
115  void setUpperBounds(Eigen::VectorXd upper_bound);
116 
122  void setLowerBounds(Eigen::VectorXd lower_bound);
123 
131  void resize(int task_size, int constraint_size);
132 
138  Eigen::MatrixXd getConstraintMatrix();
139 
145  Eigen::VectorXd getUpperBounds();
146 
152  Eigen::VectorXd getLowerBounds();
153 
154  Eigen::VectorXd lower_limit;
155  Eigen::VectorXd upper_limit;
156 
157 protected:
158  std::shared_ptr<Model::GenericModel> model_ptr_;
159  int constraint_size_;
160  int optimization_vector_size_;
161 
162 private:
163  std::string name_;
164  Eigen::MatrixXd constraint_matrix_;
165  Eigen::VectorXd upper_bound_;
166  Eigen::VectorXd lower_bound_;
167 };
168 } // namespace Constraint
169 } // namespace Qontrol
Qontrol::Constraint::GenericConstraint::GenericConstraint
GenericConstraint(std::string name, int constraint_size, std::shared_ptr< Model::GenericModel > model_ptr)
Construct a new Base onstraint object.
Definition: GenericConstraint.hpp:73
Qontrol::Constraint::GenericConstraint::GenericConstraint
GenericConstraint(std::string name, int constraint_size, int optimization_vector_size)
Construct a new GenericConstraint object.
Definition: GenericConstraint.hpp:58
Qontrol::Constraint::GenericConstraint
Represents a generic constraint.
Definition: GenericConstraint.hpp:47
Qontrol::Constraint::GenericConstraint::resize
void resize(int task_size, int constraint_size)
Resize the constraint matrices and vectors according to the task size and new constraint size.
Definition: GenericConstraint.cpp:6
Qontrol::Constraint::GenericConstraint::getName
std::string getName()
Get the constraint name.
Definition: GenericConstraint.cpp:40
Qontrol::Constraint::GenericConstraint::setUpperBounds
void setUpperBounds(Eigen::VectorXd upper_bound)
Set the constraint upper bounds .
Definition: GenericConstraint.cpp:30
Qontrol::Constraint::GenericConstraint::getSize
int getSize()
Get the constraint size.
Definition: GenericConstraint.cpp:42
Qontrol::Constraint::GenericConstraint::getConstraintMatrix
Eigen::MatrixXd getConstraintMatrix()
Get the constraint matrix .
Definition: GenericConstraint.cpp:13
Qontrol::Constraint::GenericConstraint::update
virtual void update(double dt)
Update , and overrided by the considered implementation of the constraint.
Definition: GenericConstraint.hpp:87
Qontrol::Constraint::GenericConstraint::setLowerBounds
void setLowerBounds(Eigen::VectorXd lower_bound)
Set the constraint lower bounds .
Definition: GenericConstraint.cpp:25
Qontrol::Constraint::GenericConstraint::getLowerBounds
Eigen::VectorXd getLowerBounds()
Get the constraint lower bounds .
Definition: GenericConstraint.cpp:21
Qontrol::Constraint::GenericConstraint::getUpperBounds
Eigen::VectorXd getUpperBounds()
Get the constraint upper bounds .
Definition: GenericConstraint.cpp:17
Qontrol::Constraint::GenericConstraint::setConstraintMatrix
void setConstraintMatrix(Eigen::MatrixXd constraint_matrix)
Set the constraint matrix .
Definition: GenericConstraint.cpp:35