src/tasks/task-com-equality.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017-2020 CNRS, Inria
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 
20 
21 namespace tsid {
22 namespace tasks {
23 using namespace math;
24 using namespace trajectories;
25 using namespace pinocchio;
26 
28  : TaskMotion(name, robot), m_constraint(name, 3, robot.nv()) {
29  m_Kp.setZero(3);
30  m_Kd.setZero(3);
31  m_p_error_vec.setZero(3);
32  m_v_error_vec.setZero(3);
33  m_p_com.setZero(3);
34  m_v_com.setZero(3);
35  m_a_des_vec.setZero(3);
36  m_ref.resize(3);
37  m_mask.resize(3);
38  m_mask.fill(1.);
39  setMask(m_mask);
40 }
41 
44  mask.size() == 3, "The size of the mask vector needs to equal 3");
45  TaskMotion::setMask(mask);
46  int n = dim();
48  m_p_error_masked_vec.resize(n);
49  m_v_error_masked_vec.resize(n);
50  m_drift_masked.resize(n);
51  m_a_des_masked.resize(n);
52 }
53 
54 int TaskComEquality::dim() const { return int(m_mask.sum()); }
55 
56 const Vector3& TaskComEquality::Kp() { return m_Kp; }
57 
58 const Vector3& TaskComEquality::Kd() { return m_Kd; }
59 
62  "The size of the Kp vector needs to equal 3");
63  m_Kp = Kp;
64 }
65 
68  "The size of the Kd vector needs to equal 3");
69  m_Kd = Kd;
70 }
71 
73 
75 
77  return m_a_des_masked;
78 }
79 
81  return m_constraint.matrix() * dv - m_drift_masked;
82 }
83 
85  return m_p_error_masked_vec;
86 }
87 
89  return m_v_error_masked_vec;
90 }
91 
92 const Vector& TaskComEquality::position() const { return m_p_com; }
93 
94 const Vector& TaskComEquality::velocity() const { return m_v_com; }
95 
96 const Vector& TaskComEquality::position_ref() const { return m_ref.getValue(); }
97 
99  return m_ref.getDerivative();
100 }
101 
103  return m_constraint;
104 }
105 
109 
110  // Compute errors
113  m_a_des = -m_Kp.cwiseProduct(m_p_error) - m_Kd.cwiseProduct(m_v_error) +
115 
119 #ifndef NDEBUG
120 // std::cout<<m_name<<" errors: "<<m_p_error.norm()<<" "
121 // <<m_v_error.norm()<<std::endl;
122 #endif
123 
124  // Get CoM jacobian
125  const Matrix3x& Jcom = m_robot.Jcom(data);
126 
127  int idx = 0;
128  for (int i = 0; i < 3; i++) {
129  if (m_mask(i) != 1.) continue;
130 
131  m_constraint.matrix().row(idx) = Jcom.row(i);
132  m_constraint.vector().row(idx) = (m_a_des - m_drift).row(i);
133 
134  m_a_des_masked(idx) = m_a_des(i);
135  m_drift_masked(idx) = m_drift(i);
138 
139  idx += 1;
140  }
141 
142  return m_constraint;
143 }
144 
145 } // namespace tasks
146 } // namespace tsid
tsid::tasks::TaskComEquality::Kp
const Vector3 & Kp()
Definition: src/tasks/task-com-equality.cpp:56
tsid::tasks::TaskComEquality::dim
int dim() const override
Return the dimension of the task. \info should be overloaded in the child class.
Definition: src/tasks/task-com-equality.cpp:54
tsid::trajectories::TrajectorySample::resize
void resize(unsigned int size)
Definition: trajectories/trajectory-base.hpp:58
tsid::tasks::TaskComEquality::compute
const ConstraintBase & compute(double t, ConstRefVector q, ConstRefVector v, Data &data) override
Definition: src/tasks/task-com-equality.cpp:106
tsid::tasks::TaskComEquality::velocity
const Vector & velocity() const override
Definition: src/tasks/task-com-equality.cpp:94
tsid::trajectories::TrajectorySample::getDerivative
const math::Vector & getDerivative() const
Definition: trajectories/trajectory-base.hpp:44
tsid::tasks::TaskComEquality::Vector3
math::Vector3 Vector3
Definition: tasks/task-com-equality.hpp:36
tsid::trajectories::TrajectorySample
Definition: trajectories/trajectory-base.hpp:33
pinocchio::DataTpl
PINOCCHIO_CHECK_INPUT_ARGUMENT
#define PINOCCHIO_CHECK_INPUT_ARGUMENT(...)
dv
dv
tsid::math::ConstraintEquality::vector
const Vector & vector() const override
Definition: src/math/constraint-equality.cpp:55
tsid::math::ConstraintBase
Abstract class representing a linear equality/inequality constraint. Equality constraints are represe...
Definition: constraint-base.hpp:35
tsid::tasks::TaskMotion::setMask
virtual void setMask(math::ConstRefVector mask)
Definition: task-motion.cpp:29
i
int i
tsid::tasks::TaskComEquality::velocity_error
const Vector & velocity_error() const override
Definition: src/tasks/task-com-equality.cpp:88
tsid::tasks::TaskComEquality::setMask
virtual void setMask(math::ConstRefVector mask) override
Definition: src/tasks/task-com-equality.cpp:42
tsid::tasks::TaskComEquality::m_p_error_masked_vec
Vector m_p_error_masked_vec
Definition: tasks/task-com-equality.hpp:71
ref
list ref
tsid::tasks::TaskComEquality::m_v_error_vec
Vector m_v_error_vec
Definition: tasks/task-com-equality.hpp:77
setup.data
data
Definition: setup.in.py:48
task-com-equality.hpp
demo_quadruped.robot
robot
Definition: demo_quadruped.py:51
tsid::tasks::TaskComEquality::getDesiredAcceleration
const Vector & getDesiredAcceleration() const override
Definition: src/tasks/task-com-equality.cpp:76
tsid::math::Matrix3x
Eigen::Matrix< Scalar, 3, Eigen::Dynamic > Matrix3x
Definition: math/fwd.hpp:42
test_Contact.Kp
Kp
Definition: test_Contact.py:44
tsid::tasks::TaskComEquality::Kd
const Vector3 & Kd()
Definition: src/tasks/task-com-equality.cpp:58
tsid::tasks::TaskComEquality::m_p_com
Vector m_p_com
Definition: tasks/task-com-equality.hpp:76
tsid::tasks::TaskComEquality::m_drift
Vector3 m_drift
Definition: tasks/task-com-equality.hpp:74
tsid::tasks::TaskComEquality::m_Kd
Vector3 m_Kd
Definition: tasks/task-com-equality.hpp:69
tsid::tasks::TaskComEquality::m_v_error
Vector3 m_v_error
Definition: tasks/task-com-equality.hpp:70
tsid::tasks::TaskMotion::m_mask
Vector m_mask
Definition: task-motion.hpp:53
tsid::math::ConstraintEquality::resize
void resize(unsigned int r, unsigned int c) override
Definition: src/math/constraint-equality.cpp:46
tsid::tasks::TaskComEquality::m_ref
TrajectorySample m_ref
Definition: tasks/task-com-equality.hpp:78
tsid::tasks::TaskComEquality::position_ref
const Vector & position_ref() const override
Definition: src/tasks/task-com-equality.cpp:96
ex_4_conf.nv
int nv
Definition: ex_4_conf.py:23
tsid::tasks::TaskComEquality::m_a_des
Vector3 m_a_des
Definition: tasks/task-com-equality.hpp:72
tsid::tasks::TaskComEquality::setReference
void setReference(const TrajectorySample &ref)
Definition: src/tasks/task-com-equality.cpp:72
tsid::robots::RobotWrapper::nv
virtual int nv() const
Definition: src/robots/robot-wrapper.cpp:97
tsid::tasks::TaskComEquality::Vector
math::Vector Vector
Definition: tasks/task-com-equality.hpp:35
tsid::math::ConstraintBase::matrix
virtual const Matrix & matrix() const
Definition: constraint-base.cpp:35
tsid::tasks::TaskComEquality::m_p_error
Vector3 m_p_error
Definition: tasks/task-com-equality.hpp:70
robot-wrapper.hpp
tsid::robots::RobotWrapper::com
void com(const Data &data, RefVector com_pos, RefVector com_vel, RefVector com_acc) const
Definition: src/robots/robot-wrapper.cpp:145
tsid::tasks::TaskComEquality::getAcceleration
Vector getAcceleration(ConstRefVector dv) const override
Definition: src/tasks/task-com-equality.cpp:80
tsid::trajectories::TrajectorySample::getValue
TSID_DISABLE_WARNING_PUSH const TSID_DISABLE_WARNING_DEPRECATED math::Vector & getValue() const
Definition: trajectories/trajectory-base.hpp:43
tsid::tasks::TaskComEquality::m_a_des_masked
Vector m_a_des_masked
Definition: tasks/task-com-equality.hpp:73
tsid::tasks::TaskComEquality::position
const Vector & position() const override
Definition: src/tasks/task-com-equality.cpp:92
setup.name
name
Definition: setup.in.py:179
tsid::tasks::TaskComEquality::m_p_error_vec
Vector m_p_error_vec
Definition: tasks/task-com-equality.hpp:77
tsid::tasks::TaskMotion
Definition: task-motion.hpp:26
tsid::math::ConstRefVector
const typedef Eigen::Ref< const Vector > ConstRefVector
Definition: math/fwd.hpp:48
tsid::tasks::TaskComEquality::position_error
const Vector & position_error() const override
Definition: src/tasks/task-com-equality.cpp:84
tsid
Definition: bindings/python/constraint/constraint-bound.cpp:21
tsid::robots::RobotWrapper
Wrapper for a robot based on pinocchio.
Definition: robots/robot-wrapper.hpp:37
tsid::trajectories::TrajectorySample::getSecondDerivative
const math::Vector & getSecondDerivative() const
Definition: trajectories/trajectory-base.hpp:45
tsid::tasks::TaskComEquality::velocity_ref
const Vector & velocity_ref() const override
Definition: src/tasks/task-com-equality.cpp:98
tsid::tasks::TaskComEquality::m_drift_masked
Vector m_drift_masked
Definition: tasks/task-com-equality.hpp:75
tsid::tasks::TaskComEquality::m_constraint
ConstraintEquality m_constraint
Definition: tasks/task-com-equality.hpp:79
tsid::robots::RobotWrapper::Jcom
const Matrix3x & Jcom(const Data &data) const
Definition: src/robots/robot-wrapper.cpp:162
tsid::tasks::TaskComEquality::getReference
const TrajectorySample & getReference() const override
Definition: src/tasks/task-com-equality.cpp:74
test_Contact.Kd
int Kd
Definition: test_Contact.py:45
tsid::tasks::TaskBase::m_robot
RobotWrapper & m_robot
Reference on the robot model.
Definition: task-base.hpp:64
tsid::tasks::TaskComEquality::m_Kp
Vector3 m_Kp
Definition: tasks/task-com-equality.hpp:68
tsid::tasks::TaskBase::ConstRefVector
math::ConstRefVector ConstRefVector
Definition: task-base.hpp:39
tsid::tasks::TaskComEquality::m_v_com
Vector m_v_com
Definition: tasks/task-com-equality.hpp:76
n
Vec3f n
tsid::tasks::TaskComEquality::getConstraint
const ConstraintBase & getConstraint() const override
Definition: src/tasks/task-com-equality.cpp:102
tsid::tasks::TaskComEquality::m_a_des_vec
Vector m_a_des_vec
Definition: tasks/task-com-equality.hpp:73
tsid::tasks::TaskComEquality::TaskComEquality
TaskComEquality(const std::string &name, RobotWrapper &robot)
Definition: src/tasks/task-com-equality.cpp:27
tsid::tasks::TaskComEquality::m_v_error_masked_vec
Vector m_v_error_masked_vec
Definition: tasks/task-com-equality.hpp:71
pinocchio


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Thu Apr 3 2025 02:47:16