GCC Code Coverage Report


Directory: ./
File: src/tasks/task-angular-momentum-equality.cpp
Date: 2024-11-10 01:12:44
Exec Total Coverage
Lines: 0 42 0.0%
Branches: 0 70 0.0%

Line Branch Exec Source
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 "tsid/tasks/task-angular-momentum-equality.hpp"
19 #include "tsid/robots/robot-wrapper.hpp"
20 #include <pinocchio/algorithm/joint-configuration.hpp>
21 #include <pinocchio/algorithm/centroidal.hpp>
22
23 namespace tsid {
24 namespace tasks {
25 using namespace math;
26 using namespace trajectories;
27 using namespace pinocchio;
28
29 TaskAMEquality::TaskAMEquality(const std::string& name, RobotWrapper& robot)
30 : TaskMotion(name, robot), m_constraint(name, 3, robot.nv()) {
31 m_Kp.setZero(3);
32 m_Kd.setZero(3);
33 m_L_error.setZero(3);
34 m_dL_error.setZero(3);
35 m_L.setZero(3);
36 m_dL.setZero(3);
37 m_dL_des.setZero(3);
38 m_ref.resize(3);
39 }
40
41 int TaskAMEquality::dim() const {
42 // return self._mask.sum ()
43 return 3;
44 }
45
46 const Vector3& TaskAMEquality::Kp() { return m_Kp; }
47
48 const Vector3& TaskAMEquality::Kd() { return m_Kd; }
49
50 void TaskAMEquality::Kp(ConstRefVector Kp) {
51 PINOCCHIO_CHECK_INPUT_ARGUMENT(Kp.size() == 3,
52 "The size of the Kp vector needs to equal 3");
53 m_Kp = Kp;
54 }
55
56 void TaskAMEquality::Kd(ConstRefVector Kd) {
57 PINOCCHIO_CHECK_INPUT_ARGUMENT(Kd.size() == 3,
58 "The size of the Kd vector needs to equal 3");
59 m_Kd = Kd;
60 }
61
62 void TaskAMEquality::setReference(const TrajectorySample& ref) { m_ref = ref; }
63
64 const TrajectorySample& TaskAMEquality::getReference() const { return m_ref; }
65
66 const Vector3& TaskAMEquality::getDesiredMomentumDerivative() const {
67 return m_dL_des;
68 }
69
70 Vector3 TaskAMEquality::getdMomentum(ConstRefVector dv) const {
71 return m_constraint.matrix() * dv - m_drift;
72 }
73
74 const Vector3& TaskAMEquality::momentum_error() const { return m_L_error; }
75
76 const Vector3& TaskAMEquality::momentum() const { return m_L; }
77 const Vector& TaskAMEquality::momentum_ref() const { return m_ref.getValue(); }
78
79 const Vector& TaskAMEquality::dmomentum_ref() const {
80 return m_ref.getDerivative();
81 }
82
83 const ConstraintBase& TaskAMEquality::getConstraint() const {
84 return m_constraint;
85 }
86
87 const ConstraintBase& TaskAMEquality::compute(const double, ConstRefVector,
88 ConstRefVector v, Data& data) {
89 // Compute errors
90 // Get momentum jacobian
91 const Matrix6x& J_am = m_robot.momentumJacobian(data);
92 m_L = J_am.bottomRows(3) * v;
93 m_L_error = m_L - m_ref.getValue();
94
95 m_dL_des = -m_Kp.cwiseProduct(m_L_error) + m_ref.getDerivative();
96
97 #ifndef NDEBUG
98 // std::cout<<m_name<<" errors: "<<m_L_error.norm()<<" "
99 // <<m_dL_error.norm()<<std::endl;
100 #endif
101
102 m_drift = m_robot.angularMomentumTimeVariation(data);
103 m_constraint.setMatrix(J_am.bottomRows(3));
104 m_constraint.setVector(m_dL_des - m_drift);
105
106 return m_constraint;
107 }
108
109 } // namespace tasks
110 } // namespace tsid
111