GCC Code Coverage Report


Directory: ./
File: include/hpp/constraints/qp-static-stability.hh
Date: 2025-05-05 12:19:30
Exec Total Coverage
Lines: 0 10 0.0%
Branches: 0 16 0.0%

Line Branch Exec Source
1 // Copyright (c) 2015, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28
29 #ifndef HPP_CONSTRAINTS_QP_STATIC_STABILITY_HH
30 #define HPP_CONSTRAINTS_QP_STATIC_STABILITY_HH
31
32 #include <hpp/constraints/convex-shape-contact.hh>
33 #include <hpp/constraints/differentiable-function.hh>
34 #include <hpp/constraints/fwd.hh>
35 #include <hpp/constraints/static-stability.hh>
36 #include <qpOASES.hpp>
37
38 namespace hpp {
39 namespace constraints {
40
41 /// \addtogroup constraints
42 /// \{
43 ///
44
45 /// Quasi static equilibrium constraint defined as a QP program
46 ///
47 /// This class defines a function whose value is equal to zero
48 /// if and only if there exists a set of non-negative forces applied
49 /// at some given contact points along some given normals that
50 // counter-balance the gravity force and momentum of a kinematics chain.
51 ///
52 /// \sa https://hal.archives-ouvertes.fr/tel-01516897 Chapter 2, Sections
53 /// 3.1 and 3.2.
54 class HPP_CONSTRAINTS_DLLAPI QPStaticStability : public DifferentiableFunction {
55 public:
56 static const Eigen::Matrix<value_type, 6, 1> Gravity;
57
58 typedef StaticStability::Contact_t Contact_t;
59 typedef StaticStability::Contacts_t Contacts_t;
60 typedef ConvexShapeContact::ForceData ForceData;
61
62 /// Constructor
63 /// \param name name of the constraint
64 /// \param robot the robot the constraints is applied to,
65 /// \param contacts set of contact points
66 /// \param com COM of the robot
67 QPStaticStability(const std::string& name, const DevicePtr_t& robot,
68 const Contacts_t& contacts,
69 const CenterOfMassComputationPtr_t& com);
70
71 /// Constructor
72 /// \param robot the robot the constraints is applied to,
73 /// \param com COM of the robot
74 QPStaticStability(const std::string& name, const DevicePtr_t& robot,
75 const std::vector<ForceData>& contacts,
76 const CenterOfMassComputationPtr_t& com);
77
78 static QPStaticStabilityPtr_t create(const std::string& name,
79 const DevicePtr_t& robot,
80 const Contacts_t& contacts,
81 const CenterOfMassComputationPtr_t& com);
82
83 static QPStaticStabilityPtr_t create(const std::string& name,
84 const DevicePtr_t& robot,
85 const std::vector<ForceData>& contacts,
86 const CenterOfMassComputationPtr_t& com);
87
88 static QPStaticStabilityPtr_t create(const DevicePtr_t& robot,
89 const Contacts_t& contacts,
90 const CenterOfMassComputationPtr_t& com);
91
92 MatrixOfExpressions<>& phi() { return phi_; }
93
94 protected:
95 bool isEqual(const DifferentiableFunction& other) const {
96 const QPStaticStability& castother =
97 dynamic_cast<const QPStaticStability&>(other);
98 if (!DifferentiableFunction::isEqual(other)) return false;
99
100 if (name() != castother.name()) return false;
101 if (robot_ != castother.robot_) return false;
102 if (nbContacts_ != castother.nbContacts_) return false;
103 if (com_ != castother.com_) return false;
104 if (Zeros != castother.Zeros) return false;
105 if (nWSR != castother.nWSR) return false;
106
107 return true;
108 }
109
110 private:
111 static const Eigen::Matrix<value_type, 6, 1> MinusGravity;
112
113 qpOASES::real_t* Zeros;
114 const qpOASES::int_t nWSR;
115
116 void impl_compute(LiegroupElementRef result,
117 ConfigurationIn_t argument) const;
118
119 void impl_jacobian(matrixOut_t jacobian, ConfigurationIn_t argument) const;
120
121 qpOASES::returnValue solveQP(vectorOut_t result) const;
122
123 bool checkQPSol() const;
124 bool checkStrictComplementarity() const;
125
126 DevicePtr_t robot_;
127 std::size_t nbContacts_;
128 CenterOfMassComputationPtr_t com_;
129
130 typedef MatrixOfExpressions<eigen::vector3_t, JacobianMatrix> MoE_t;
131 typedef Eigen::Matrix<qpOASES::real_t, Eigen::Dynamic, Eigen::Dynamic,
132 Eigen::RowMajor>
133 RowMajorMatrix_t;
134 typedef Eigen::Map<RowMajorMatrix_t> InvertStorageOrderMap_t;
135 typedef Eigen::Map<Eigen::Matrix<qpOASES::real_t, Eigen::Dynamic, 1> >
136 VectorMap_t;
137 typedef Eigen::Map<const vector_t> ConstVectorMap_t;
138
139 mutable RowMajorMatrix_t H_;
140 mutable vector_t G_;
141 mutable qpOASES::QProblemB qp_;
142 mutable MoE_t phi_;
143 mutable vector_t primal_, dual_;
144 };
145 /// \}
146 } // namespace constraints
147 } // namespace hpp
148
149 #endif // HPP_CONSTRAINTS_STATIC_STABILITY_HH
150