mc_rtc  2.12.0
Update.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 
9 
10 namespace mc_solver
11 {
12 
13 namespace utils
14 {
15 
17 
18 template<typename UpdateNrVars>
19 struct Update : public UpdateNrVars, UpdateTag
20 {
21  static_assert(std::is_same<UpdateNrVars, UpdateNrVarsRobot>::value
22  || std::is_same<UpdateNrVars, UpdateNrVarsLambda>::value,
23  "This should not be instanciated with unexpected UpdateNrVars classes");
24 
25 protected:
26  // XXX The following is a hack to work-around the absence of constructor inheritance in GCC 4.7
27  // We enable different constructor based on the UpdateNrVars class
28 
29  template<typename U = UpdateNrVars,
30  typename = typename std::enable_if<std::is_same<U, UpdateNrVarsRobot>::value>::type>
31  explicit Update(unsigned int rIndex) : UpdateNrVars(rIndex)
32  {
33  }
34 
35  template<typename U = UpdateNrVars,
36  typename = typename std::enable_if<std::is_same<U, UpdateNrVarsLambda>::value>::type>
37  explicit Update(const tasks::qp::ContactId & cid) : UpdateNrVars(cid)
38  {
39  }
40 
41  virtual ~Update() {}
42 
44  virtual void compute() = 0;
45 
47  virtual const Eigen::MatrixXd & A() const = 0;
48 
49  void updateImpl(const std::vector<rbd::MultiBody> &,
50  const std::vector<rbd::MultiBodyConfig> &,
51  const tasks::qp::SolverData &)
52  {
53  compute();
54  const auto & A_ = A();
55  auto nInEq = A_.rows();
56  AFull_.setZero(nInEq, UpdateNrVars::nrVars_);
57  AFull_.block(0, UpdateNrVars::ABegin_, nInEq, A_.cols()) = A_;
58  }
59 
61  Eigen::MatrixXd AFull_;
62 };
63 
64 template<typename T>
65 struct IsUpdate : public std::is_base_of<UpdateTag, T>
66 {
67 };
68 
71 
72 struct MC_SOLVER_DLLAPI UpdateForce : public Update<UpdateNrVarsLambda>
73 {
74 protected:
75  UpdateForce(const mc_solver::QPSolver & solver, const tasks::qp::ContactId & cid);
76 
77  void updateImpl(const std::vector<rbd::MultiBody> &,
78  const std::vector<rbd::MultiBodyConfig> &,
79  const tasks::qp::SolverData &);
80 
81 private:
84 
85  Eigen::MatrixXd ALambda_;
86 };
87 
88 } // namespace utils
89 
90 } // namespace mc_solver
ContactWrenchMatrixToLambdaMatrix.h
mc_solver::utils::Update::Update
Update(unsigned int rIndex)
Definition: Update.h:31
mc_solver::utils::Update::~Update
virtual ~Update()
Definition: Update.h:41
mc_solver::utils::Update::Update
Update(const tasks::qp::ContactId &cid)
Definition: Update.h:37
mc_solver::QPSolver
Definition: QPSolver.h:85
mc_solver::utils::IsUpdate
Definition: Update.h:65
mc_solver::utils::Update::compute
virtual void compute()=0
mc_solver::utils::UpdateForce
Definition: Update.h:72
mc_solver::utils::Update
Definition: Update.h:19
mc_solver::utils::Update::A
virtual const Eigen::MatrixXd & A() const =0
mc_solver::utils::Update::AFull_
Eigen::MatrixXd AFull_
Definition: Update.h:61
mc_solver::utils::Update::updateImpl
void updateImpl(const std::vector< rbd::MultiBody > &, const std::vector< rbd::MultiBodyConfig > &, const tasks::qp::SolverData &)
Definition: Update.h:49
mc_solver
Definition: Contact.h:17
mc_solver::utils::UpdateTag
Definition: Update.h:16
MC_SOLVER_DLLAPI
#define MC_SOLVER_DLLAPI
Definition: api.h:50
mc_solver::utils::ContactWrenchMatrixToLambdaMatrix
Definition: ContactWrenchMatrixToLambdaMatrix.h:108
UpdateNrVars.h