CompoundJointConstraint.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2022 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 
10 #include <mc_rbdyn/Robots.h>
11 
12 #include <mc_rtc/void_ptr.h>
13 
14 #include <Tasks/QPSolver.h>
15 
16 namespace mc_solver
17 {
18 
21 
22 namespace details
23 {
24 
30 struct CompoundJointConstraint : public tasks::qp::ConstraintFunction<tasks::qp::Inequality>
31 {
32  MC_SOLVER_DLLAPI CompoundJointConstraint(const mc_rbdyn::Robots & robots, unsigned int rIndex, double dt);
33 
35  unsigned int rIndex,
36  double dt,
38 
40 
42  unsigned int rIndex,
44 
45  MC_SOLVER_DLLAPI void updateNrVars(const std::vector<rbd::MultiBody> & mbs,
46  const tasks::qp::SolverData & data) override;
47 
48  MC_SOLVER_DLLAPI void update(const std::vector<rbd::MultiBody> & mbs,
49  const std::vector<rbd::MultiBodyConfig> & mbcs,
50  const tasks::qp::SolverData & data) override;
51 
52  inline const Eigen::MatrixXd & AInEq() const override { return A_; }
53 
54  inline int maxInEq() const override { return static_cast<int>(descs_.size()); }
55 
56  inline std::string nameInEq() const override { return name_; }
57 
58  inline const Eigen::VectorXd & bInEq() const override { return b_; }
59 
60  std::string descInEq(const std::vector<rbd::MultiBody> & mbs, int i) override;
61 
62 private:
63  size_t rIndex_;
64  std::string name_;
65  Eigen::MatrixXd A_;
66  Eigen::VectorXd b_;
67  // Constant part of b_
68  Eigen::VectorXd b_cst_;
69  // Timestep
70  double dt_;
71  // Simplified form of the description
72  struct Desc
73  {
74  // Index of j1 in mbc
75  size_t q1Idx;
76  // Index of j1 in matrix
77  int q1MatIdx;
78  // Index of j2 in mbc
79  size_t q2Idx;
80  // Index of j2 in matrix
81  int q2MatIdx;
82  // x index of p1
83  double p1_x;
84  // y index of p1
85  double p1_y;
86  // P_x = p2_x - p1_x
87  double P_x;
88  // P_y = p2_y - p1_y
89  double P_y;
90  };
91  std::vector<Desc> descs_;
92 };
93 
94 } // namespace details
95 
98 {
99  CompoundJointConstraint(const mc_rbdyn::Robots & robots, unsigned int robotIndex, double dt);
100 
102  unsigned int robotIndex,
103  double dt,
105 
106  void addToSolverImpl(QPSolver & solver) override;
107 
108  void removeFromSolverImpl(QPSolver & solver) override;
109 
110 private:
119  mc_rtc::void_ptr constraint_;
120 };
121 
122 } // namespace mc_solver
mc_solver::details::CompoundJointConstraint
Definition: CompoundJointConstraint.h:30
mc_rbdyn::Robots
Definition: Robots.h:15
void_ptr.h
mc_rbdyn::CompoundJointConstraintDescription
Definition: CompoundJointConstraintDescription.h:23
ConstraintSet.h
mc_solver::details::CompoundJointConstraint::addConstraint
MC_SOLVER_DLLAPI void addConstraint(const mc_rbdyn::Robots &robots, unsigned int rIndex, const CompoundJointConstraintDescription &desc)
mc_rbdyn::CompoundJointConstraintDescriptionVector
std::vector< CompoundJointConstraintDescription, Eigen::aligned_allocator< CompoundJointConstraintDescription > > CompoundJointConstraintDescriptionVector
Definition: CompoundJointConstraintDescription.h:33
mc_solver::QPSolver
Definition: QPSolver.h:85
mc_solver::details::CompoundJointConstraint::maxInEq
int maxInEq() const override
Definition: CompoundJointConstraint.h:54
mc_solver::details::CompoundJointConstraint::bInEq
const Eigen::VectorXd & bInEq() const override
Definition: CompoundJointConstraint.h:58
mc_solver::ConstraintSet
This class is a basis to wrap Constraint functions from Tasks. The aim of such wrappers should be two...
Definition: ConstraintSet.h:20
mc_solver::details::CompoundJointConstraint::update
MC_SOLVER_DLLAPI void update(const std::vector< rbd::MultiBody > &mbs, const std::vector< rbd::MultiBodyConfig > &mbcs, const tasks::qp::SolverData &data) override
mc_solver::CompoundJointConstraint
Definition: CompoundJointConstraint.h:97
mc_rtc::void_ptr
std::unique_ptr< void, void(*)(void *)> void_ptr
Definition: void_ptr.h:14
CompoundJointConstraintDescription.h
Robots.h
mc_solver::details::CompoundJointConstraint::nameInEq
std::string nameInEq() const override
Definition: CompoundJointConstraint.h:56
mc_solver::CompoundJointConstraintDescriptionVector
mc_rbdyn::CompoundJointConstraintDescriptionVector CompoundJointConstraintDescriptionVector
Definition: CompoundJointConstraint.h:20
mc_solver::details::CompoundJointConstraint::AInEq
const Eigen::MatrixXd & AInEq() const override
Definition: CompoundJointConstraint.h:52
mc_solver::CompoundJointConstraintDescription
mc_rbdyn::CompoundJointConstraintDescription CompoundJointConstraintDescription
Definition: CompoundJointConstraint.h:19
mc_solver
Definition: Contact.h:17
mc_solver::details::CompoundJointConstraint::updateNrVars
MC_SOLVER_DLLAPI void updateNrVars(const std::vector< rbd::MultiBody > &mbs, const tasks::qp::SolverData &data) override
mc_solver::details::CompoundJointConstraint::descInEq
std::string descInEq(const std::vector< rbd::MultiBody > &mbs, int i) override
mc_solver::details::CompoundJointConstraint::CompoundJointConstraint
MC_SOLVER_DLLAPI CompoundJointConstraint(const mc_rbdyn::Robots &robots, unsigned int rIndex, double dt)
MC_SOLVER_DLLAPI
#define MC_SOLVER_DLLAPI
Definition: api.h:50
mc_solver::details::CompoundJointConstraint::~CompoundJointConstraint
MC_SOLVER_DLLAPI ~CompoundJointConstraint() override