Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2015-2020 CNRS INRIA |
3 |
|
|
// Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France. |
4 |
|
|
// |
5 |
|
|
|
6 |
|
|
#ifndef __pinocchio_multibody_constraint_base_hpp__ |
7 |
|
|
#define __pinocchio_multibody_constraint_base_hpp__ |
8 |
|
|
|
9 |
|
|
#include "pinocchio/macros.hpp" |
10 |
|
|
#include "pinocchio/spatial/fwd.hpp" |
11 |
|
|
#include "pinocchio/spatial/motion.hpp" |
12 |
|
|
#include "pinocchio/spatial/act-on-set.hpp" |
13 |
|
|
|
14 |
|
|
#include <boost/static_assert.hpp> |
15 |
|
|
|
16 |
|
|
// S : v \in M^6 -> v_J \in lie(Q) ~= R^nv |
17 |
|
|
// S^T : f_J \in lie(Q)^* ~= R^nv -> f \in F^6 |
18 |
|
|
|
19 |
|
|
#define PINOCCHIO_CONSTRAINT_TYPEDEF_GENERIC(DERIVED, TYPENAME) \ |
20 |
|
|
typedef TYPENAME traits<DERIVED>::Scalar Scalar; \ |
21 |
|
|
typedef TYPENAME traits<DERIVED>::JointMotion JointMotion; \ |
22 |
|
|
typedef TYPENAME traits<DERIVED>::JointForce JointForce; \ |
23 |
|
|
typedef TYPENAME traits<DERIVED>::DenseBase DenseBase; \ |
24 |
|
|
typedef TYPENAME traits<DERIVED>::MatrixReturnType MatrixReturnType; \ |
25 |
|
|
typedef TYPENAME traits<DERIVED>::ConstMatrixReturnType ConstMatrixReturnType; \ |
26 |
|
|
enum \ |
27 |
|
|
{ \ |
28 |
|
|
LINEAR = traits<DERIVED>::LINEAR, \ |
29 |
|
|
ANGULAR = traits<DERIVED>::ANGULAR \ |
30 |
|
|
}; \ |
31 |
|
|
enum \ |
32 |
|
|
{ \ |
33 |
|
|
Options = traits<DERIVED>::Options \ |
34 |
|
|
}; |
35 |
|
|
|
36 |
|
|
#define PINOCCHIO_CONSTRAINT_TYPEDEF_TPL(DERIVED) \ |
37 |
|
|
PINOCCHIO_CONSTRAINT_TYPEDEF_GENERIC(DERIVED, typename) |
38 |
|
|
#define PINOCCHIO_CONSTRAINT_TYPEDEF(DERIVED) \ |
39 |
|
|
PINOCCHIO_CONSTRAINT_TYPEDEF_GENERIC(DERIVED, PINOCCHIO_EMPTY_ARG) |
40 |
|
|
|
41 |
|
|
namespace pinocchio |
42 |
|
|
{ |
43 |
|
|
|
44 |
|
|
/// \brief Return type of the Constraint::Transpose * Force operation |
45 |
|
|
template<class ConstraintDerived, typename Force> |
46 |
|
|
struct ConstraintForceOp |
47 |
|
|
{ |
48 |
|
|
typedef ReturnTypeNotDefined ReturnType; |
49 |
|
|
}; |
50 |
|
|
|
51 |
|
|
/// \brief Return type of the Constraint::Transpose * ForceSet operation |
52 |
|
|
template<class ConstraintDerived, typename ForceSet> |
53 |
|
|
struct ConstraintForceSetOp |
54 |
|
|
{ |
55 |
|
|
typedef ReturnTypeNotDefined ReturnType; |
56 |
|
|
}; |
57 |
|
|
|
58 |
|
|
template<class Derived> |
59 |
|
|
class JointMotionSubspaceBase : public NumericalBase<Derived> |
60 |
|
|
{ |
61 |
|
|
protected: |
62 |
|
|
PINOCCHIO_CONSTRAINT_TYPEDEF_TPL(Derived) |
63 |
|
|
|
64 |
|
|
public: |
65 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
66 |
|
|
|
67 |
|
1382 |
Derived & derived() |
68 |
|
|
{ |
69 |
|
1382 |
return *static_cast<Derived *>(this); |
70 |
|
|
} |
71 |
|
52219 |
const Derived & derived() const |
72 |
|
|
{ |
73 |
|
103422 |
return *static_cast<const Derived *>(this); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
template<typename VectorLike> |
77 |
|
94260 |
JointMotion operator*(const Eigen::MatrixBase<VectorLike> & vj) const |
78 |
|
|
{ |
79 |
|
94260 |
return derived().__mult__(vj); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
1382 |
MatrixReturnType matrix() |
83 |
|
|
{ |
84 |
|
1382 |
return derived().matrix_impl(); |
85 |
|
|
} |
86 |
|
940 |
ConstMatrixReturnType matrix() const |
87 |
|
|
{ |
88 |
|
1540 |
return derived().matrix_impl(); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
1403 |
int nv() const |
92 |
|
|
{ |
93 |
|
1403 |
return derived().nv_impl(); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
52 |
static int rows() |
97 |
|
|
{ |
98 |
|
52 |
return 6; |
99 |
|
|
} |
100 |
|
26 |
int cols() const |
101 |
|
|
{ |
102 |
|
52 |
return nv(); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
template<class OtherDerived> |
106 |
|
|
bool isApprox( |
107 |
|
|
const JointMotionSubspaceBase<OtherDerived> & other, |
108 |
|
|
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) const |
109 |
|
|
{ |
110 |
|
|
return matrix().isApprox(other.matrix(), prec); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
void disp(std::ostream & os) const |
114 |
|
|
{ |
115 |
|
|
derived().disp_impl(os); |
116 |
|
|
} |
117 |
|
|
friend std::ostream & operator<<(std::ostream & os, const JointMotionSubspaceBase<Derived> & X) |
118 |
|
|
{ |
119 |
|
|
X.disp(os); |
120 |
|
|
return os; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
typename SE3GroupAction<Derived>::ReturnType se3Action(const SE3Tpl<Scalar, Options> & m) const |
124 |
|
|
{ |
125 |
|
|
return derived().se3Action(m); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
typename SE3GroupAction<Derived>::ReturnType |
129 |
|
|
se3ActionInverse(const SE3Tpl<Scalar, Options> & m) const |
130 |
|
|
{ |
131 |
|
|
return derived().se3ActionInverse(m); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
template<typename MotionDerived> |
135 |
|
|
typename MotionAlgebraAction<Derived, MotionDerived>::ReturnType |
136 |
|
|
motionAction(const MotionDense<MotionDerived> & v) const |
137 |
|
|
{ |
138 |
|
|
return derived().motionAction(v); |
139 |
|
|
} |
140 |
|
|
|
141 |
|
1252 |
bool operator==(const JointMotionSubspaceBase<Derived> & other) const |
142 |
|
|
{ |
143 |
|
1252 |
return derived().isEqual(other.derived()); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
}; // class JointMotionSubspaceBase |
147 |
|
|
|
148 |
|
|
/// \brief Operation Y * S used in the CRBA algorithm for instance |
149 |
|
|
template<typename Scalar, int Options, typename ConstraintDerived> |
150 |
|
703 |
typename MultiplicationOp<InertiaTpl<Scalar, Options>, ConstraintDerived>::ReturnType operator*( |
151 |
|
|
const InertiaTpl<Scalar, Options> & Y, |
152 |
|
|
const JointMotionSubspaceBase<ConstraintDerived> & constraint) |
153 |
|
|
{ |
154 |
|
|
return impl::LhsMultiplicationOp<InertiaTpl<Scalar, Options>, ConstraintDerived>::run( |
155 |
|
703 |
Y, constraint.derived()); |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
/// \brief Operation Y_matrix * S used in the ABA algorithm for instance |
159 |
|
|
template<typename MatrixDerived, typename ConstraintDerived> |
160 |
|
|
typename MultiplicationOp<Eigen::MatrixBase<MatrixDerived>, ConstraintDerived>::ReturnType |
161 |
|
69 |
operator*( |
162 |
|
|
const Eigen::MatrixBase<MatrixDerived> & Y, |
163 |
|
|
const JointMotionSubspaceBase<ConstraintDerived> & constraint) |
164 |
|
|
{ |
165 |
|
48 |
return impl::LhsMultiplicationOp<Eigen::MatrixBase<MatrixDerived>, ConstraintDerived>::run( |
166 |
|
117 |
Y.derived(), constraint.derived()); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
namespace details |
170 |
|
|
{ |
171 |
|
|
template<typename Constraint> |
172 |
|
|
struct StDiagonalMatrixSOperation |
173 |
|
|
{ |
174 |
|
|
typedef typename traits<Constraint>::StDiagonalMatrixSOperationReturnType ReturnType; |
175 |
|
|
typedef typename traits<Constraint>::ReducedSquaredMatrix ReducedSquaredMatrix; |
176 |
|
|
|
177 |
|
38 |
static ReturnType run(const JointMotionSubspaceBase<Constraint> & /*constraint*/) |
178 |
|
|
{ |
179 |
|
38 |
return ReducedSquaredMatrix::Identity(Constraint::NV, Constraint::NV); |
180 |
|
|
} |
181 |
|
|
}; |
182 |
|
|
} // namespace details |
183 |
|
|
|
184 |
|
|
template<class ConstraintDerived> |
185 |
|
|
struct JointMotionSubspaceTransposeBase |
186 |
|
|
{ |
187 |
|
|
typedef typename traits<ConstraintDerived>::StDiagonalMatrixSOperationReturnType |
188 |
|
|
StDiagonalMatrixSOperationReturnType; |
189 |
|
|
}; |
190 |
|
|
|
191 |
|
|
template<class ConstraintDerived> |
192 |
|
|
typename JointMotionSubspaceTransposeBase<ConstraintDerived>::StDiagonalMatrixSOperationReturnType |
193 |
|
25 |
operator*( |
194 |
|
|
const JointMotionSubspaceTransposeBase<ConstraintDerived> & /*S_transpose*/, |
195 |
|
|
const JointMotionSubspaceBase<ConstraintDerived> & S) |
196 |
|
|
{ |
197 |
|
25 |
return details::StDiagonalMatrixSOperation<ConstraintDerived>::run(S.derived()); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
} // namespace pinocchio |
201 |
|
|
|
202 |
|
|
#endif // ifndef __pinocchio_multibody_constraint_base_hpp__ |
203 |
|
|
|