src/tasks/task-contact-force-equality.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017 CNRS
3 //
4 // This file is part of tsid
5 // tsid is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 // tsid is distributed in the hope that it will be
10 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Lesser Public License for more details. You should have
13 // received a copy of the GNU Lesser General Public License along with
14 // tsid If not, see
15 // <http://www.gnu.org/licenses/>.
16 //
17 
18 #include <Eigen/Dense>
19 #include <pinocchio/multibody/model.hpp>
21 
22 namespace tsid {
23 namespace tasks {
24 
25 using namespace tsid::math;
26 using namespace std;
27 
29  const std::string& name, RobotWrapper& robot, const double dt,
31  : TaskContactForce(name, robot),
32  m_contact(&contact),
33  m_constraint(name, 6, 12),
34  m_ref(6, 6),
35  m_fext(6, 6) {
36  m_forceIntegralError = Vector::Zero(6);
37  m_dt = dt;
38  m_leak_rate = 0.05;
40 }
41 
42 int TaskContactForceEquality::dim() const { return 6; }
43 
44 const Vector& TaskContactForceEquality::Kp() const { return m_Kp; }
45 const Vector& TaskContactForceEquality::Kd() const { return m_Kd; }
46 const Vector& TaskContactForceEquality::Ki() const { return m_Ki; }
48  return m_leak_rate;
49 }
50 
52  PINOCCHIO_CHECK_INPUT_ARGUMENT(Kp.size() == 6,
53  "The size of the Kp vector needs to equal 6");
54  m_Kp = Kp;
55 }
56 
58  PINOCCHIO_CHECK_INPUT_ARGUMENT(Kd.size() == 6,
59  "The size of the Kd vector needs to equal 6");
60  m_Kd = Kd;
61 }
62 
64  PINOCCHIO_CHECK_INPUT_ARGUMENT(Ki.size() == 6,
65  "The size of the Ki vector needs to equal 6");
66  m_Ki = Ki;
67 }
68 
70 
72  return m_contact_name;
73 }
74 
76  return *m_contact;
77 }
78 
81  m_contact = &contact;
83 }
84 
86  m_ref = ref;
87 }
88 
91  return m_ref;
92 }
93 
95  m_fext = f_ext;
96 }
97 
100  return m_fext;
101 }
102 
104  const double t, ConstRefVector q, ConstRefVector v, Data& data,
105  const std::vector<std::shared_ptr<ContactLevel> >* contacts) {
106  bool contactFound = false;
107  if (m_contact_name != "") {
108  // look if the associated contact is in the list of contact
109  for (auto cl : *contacts) {
110  if (m_contact_name == cl->contact.name()) {
111  contactFound = true;
112  break;
113  }
114  }
115  } else {
116  std::cout << "[TaskContactForceEquality] ERROR: Contact name empty"
117  << std::endl;
118  return m_constraint;
119  }
120  if (!contactFound) {
121  std::cout << "[TaskContactForceEquality] ERROR: Contact name not in the "
122  "list of contact in the formulation pb"
123  << std::endl;
124  return m_constraint;
125  }
126  return compute(t, q, v, data);
127 }
128 
132  Data& /*data*/) {
133  auto& M = m_constraint.matrix();
134  M = m_contact->getForceGeneratorMatrix(); // 6x12 for a 6d contact
135 
136  Vector forceError = m_ref.getValue() - m_fext.getValue();
137  Vector f_ref =
138  m_ref.getValue() + m_Kp.cwiseProduct(forceError) +
139  m_Kd.cwiseProduct(m_ref.getDerivative() - m_fext.getDerivative()) +
140  m_Ki.cwiseProduct(m_forceIntegralError);
141  m_constraint.vector() = f_ref;
142 
144  (forceError - m_leak_rate * m_forceIntegralError) * m_dt;
145 
146  return m_constraint;
147 }
148 
150  return m_constraint;
151 }
152 
153 } // namespace tasks
154 } // namespace tsid
data
Definition: setup.in.py:48
Base template of a Contact.
virtual const contacts::ContactBase & getAssociatedContact()
TSID_DISABLE_WARNING_PUSH TSID_DISABLE_WARNING_DEPRECATED const math::Vector & getValue() const
math::ConstRefVector ConstRefVector
Definition: task-base.hpp:39
void setAssociatedContact(contacts::ContactBase &contact)
int dim() const
Return the dimension of the task. should be overloaded in the child class.
const std::string & name() const
Wrapper for a robot based on pinocchio.
TaskContactForceEquality(const std::string &name, RobotWrapper &robot, const double dt, contacts::ContactBase &contact)
cl
Transform3f t
virtual const Matrix & matrix() const
M
const ConstraintBase & compute(const double t, ConstRefVector q, ConstRefVector v, Data &data)
virtual const Matrix & getForceGeneratorMatrix()=0
#define PINOCCHIO_CHECK_INPUT_ARGUMENT(...)


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Sun Jul 2 2023 02:21:51