GCC Code Coverage Report


Directory: ./
File: src/tasks/task-cop-equality.cpp
Date: 2024-11-10 01:12:44
Exec Total Coverage
Lines: 0 39 0.0%
Branches: 0 66 0.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 University of Trento
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-cop-equality.hpp"
19
20 using namespace tsid::math;
21 using namespace std;
22
23 namespace tsid {
24 namespace tasks {
25
26 TaskCopEquality::TaskCopEquality(const std::string& name, RobotWrapper& robot)
27 : TaskContactForce(name, robot),
28 m_contact_name(""),
29 m_constraint(name, 3, 3) {
30 m_normal << 0, 0, 1;
31 m_ref.setZero();
32 }
33
34 void TaskCopEquality::setContactList(
35 const std::vector<std::shared_ptr<ContactLevel> >* contacts) {
36 m_contacts = contacts;
37 }
38
39 int TaskCopEquality::dim() const { return 3; }
40
41 const std::string& TaskCopEquality::getAssociatedContactName() {
42 return m_contact_name;
43 }
44
45 const ConstraintBase& TaskCopEquality::compute(
46 const double t, ConstRefVector q, ConstRefVector v, Data& data,
47 const std::vector<std::shared_ptr<ContactLevel> >* contacts) {
48 setContactList(contacts);
49 return compute(t, q, v, data);
50 }
51 const ConstraintBase& TaskCopEquality::compute(const double, ConstRefVector,
52 ConstRefVector, Data& data) {
53 // count size of force vector
54 int n = 0;
55 for (auto& cl : *m_contacts) {
56 n += cl->contact.n_force();
57 }
58
59 // fill constraint matrix
60 SE3 oMi;
61 Vector3 p_local, p_world;
62 auto& M = m_constraint.matrix();
63 M.resize(3, n);
64 for (auto& cl : *m_contacts) {
65 unsigned int i = cl->index;
66 // get contact points in local frame and transform them to world frame
67 const Matrix3x& P = cl->contact.getContactPoints();
68 m_robot.framePosition(
69 data,
70 static_cast<const TaskSE3Equality&>(cl->contact.getMotionTask())
71 .frame_id(),
72 oMi);
73 // cout<<"Contact "<<cl->contact.name()<<endl;
74 // cout<<"oMi\n"<<oMi<<endl;
75 for (int j = 0; j < P.cols(); ++j) {
76 p_local = P.col(j);
77 p_world = oMi.act(p_local);
78 // cout<<j<<" p_local "<<p_local.transpose()<<endl;
79 // cout<<j<<" p_world "<<p_world.transpose()<<endl;
80 M.middleCols(i + 3 * j, 3) = (p_world - m_ref) * (m_normal.transpose());
81 }
82 }
83 return m_constraint;
84 }
85
86 const ConstraintBase& TaskCopEquality::getConstraint() const {
87 return m_constraint;
88 }
89
90 void TaskCopEquality::setReference(const Vector3& ref) {
91 PINOCCHIO_CHECK_INPUT_ARGUMENT(ref.size() == 3,
92 "The size of the reference needs to equal 3");
93 m_ref = ref;
94 }
95
96 const Vector3& TaskCopEquality::getReference() const { return m_ref; }
97
98 void TaskCopEquality::setContactNormal(const Vector3& n) { m_normal = n; }
99
100 const Vector3& TaskCopEquality::getContactNormal() const { return m_normal; }
101
102 } // namespace tasks
103 } // namespace tsid
104