Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2015-2019 CNRS INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#ifndef __pinocchio_cholesky_hpp__ |
6 |
|
|
#define __pinocchio_cholesky_hpp__ |
7 |
|
|
|
8 |
|
|
#include "pinocchio/multibody/model.hpp" |
9 |
|
|
#include "pinocchio/multibody/data.hpp" |
10 |
|
|
|
11 |
|
|
namespace pinocchio |
12 |
|
|
{ |
13 |
|
|
namespace cholesky |
14 |
|
|
{ |
15 |
|
|
|
16 |
|
|
/// |
17 |
|
|
/// \brief Compute the Cholesky decomposition of the joint space inertia matrix M contained in |
18 |
|
|
/// data. |
19 |
|
|
/// |
20 |
|
|
/// \note The Cholesky decomposition corresponds to |
21 |
|
|
/// \f$ M = U D U^{\top}\f$ with \f$U\f$ an upper triangular matrix with ones on its main |
22 |
|
|
/// diagonal and \f$D\f$ a diagonal matrix. |
23 |
|
|
/// |
24 |
|
|
/// The result stored in data.U and data.D matrices. One can retrieve the matrice M by |
25 |
|
|
/// performing the computation data.U * data.D * data.U.transpose() |
26 |
|
|
/// |
27 |
|
|
/// See https://en.wikipedia.org/wiki/Cholesky_decomposition for futher details. |
28 |
|
|
/// |
29 |
|
|
/// \tparam JointCollection Collection of Joint types. |
30 |
|
|
/// |
31 |
|
|
/// \param[in] model The model structure of the rigid body system. |
32 |
|
|
/// \param[in] data The data structure of the rigid body system. |
33 |
|
|
/// |
34 |
|
|
/// \return A reference to the upper triangular matrix \f$U\f$. |
35 |
|
|
/// |
36 |
|
|
template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> |
37 |
|
|
inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::MatrixXs & decompose( |
38 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
39 |
|
|
DataTpl<Scalar, Options, JointCollectionTpl> & data); |
40 |
|
|
|
41 |
|
|
/// |
42 |
|
|
/// \brief Return the solution \f$x\f$ of \f$ M x = y \f$ using the Cholesky decomposition |
43 |
|
|
/// stored in data given the entry \f$ y \f$. Act like solveInPlace of Eigen::LLT. |
44 |
|
|
/// |
45 |
|
|
/// \note This algorithm is useful to compute the forward dynamics, retriving the joint |
46 |
|
|
/// acceleration \f$ \ddot{q} \f$ from the current joint torque \f$ \tau \f$ |
47 |
|
|
/// \f$ |
48 |
|
|
/// M(q) \ddot{q} + b(q, \dot{q}) = \tau \iff \ddot{q} = M(q)^{-1} (\tau - b(q, |
49 |
|
|
/// \dot{q})) |
50 |
|
|
/// \f$ |
51 |
|
|
/// |
52 |
|
|
/// \tparam JointCollection Collection of Joint types. |
53 |
|
|
/// |
54 |
|
|
/// \param[in] model The model structure of the rigid body system. |
55 |
|
|
/// \param[in] data The data structure of the rigid body system. |
56 |
|
|
/// \param[inout] y The input matrix to inverse which also contains the result \f$x\f$ of the |
57 |
|
|
/// inversion. |
58 |
|
|
/// |
59 |
|
|
template< |
60 |
|
|
typename Scalar, |
61 |
|
|
int Options, |
62 |
|
|
template<typename, int> class JointCollectionTpl, |
63 |
|
|
typename Mat> |
64 |
|
|
Mat & solve( |
65 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
66 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
67 |
|
|
const Eigen::MatrixBase<Mat> & y); |
68 |
|
|
|
69 |
|
|
/// |
70 |
|
|
/// \brief Performs the multiplication \f$ M v \f$ by using the sparsity pattern of the M |
71 |
|
|
/// matrix. |
72 |
|
|
/// |
73 |
|
|
/// \tparam JointCollection Collection of Joint types. |
74 |
|
|
/// |
75 |
|
|
/// \param[in] model The model structure of the rigid body system. |
76 |
|
|
/// \param[in] data The data structure of the rigid body system. |
77 |
|
|
/// \param[in] min The input matrix to multiply with data.M. |
78 |
|
|
/// |
79 |
|
|
/// \return A the result of \f$ Mv \f$. |
80 |
|
|
/// |
81 |
|
|
template< |
82 |
|
|
typename Scalar, |
83 |
|
|
int Options, |
84 |
|
|
template<typename, int> class JointCollectionTpl, |
85 |
|
|
typename Mat> |
86 |
|
|
typename PINOCCHIO_EIGEN_PLAIN_TYPE(Mat) Mv( |
87 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
88 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
89 |
|
|
const Eigen::MatrixBase<Mat> & min); |
90 |
|
|
|
91 |
|
|
/// |
92 |
|
|
/// \brief Performs the multiplication \f$ M v \f$ by using the sparsity pattern of the M |
93 |
|
|
/// matrix. |
94 |
|
|
/// |
95 |
|
|
/// \tparam JointCollection Collection of Joint types. |
96 |
|
|
/// |
97 |
|
|
/// \param[in] model The model structure of the rigid body system. |
98 |
|
|
/// \param[in] data The data structure of the rigid body system. |
99 |
|
|
/// \param[in] min The input matrix to multiply with data.M. |
100 |
|
|
/// \param[out] mout The output matrix where the result of \f$ Mv \f$ is stored. |
101 |
|
|
/// |
102 |
|
|
/// \return A reference of the result of \f$ Mv \f$. |
103 |
|
|
/// |
104 |
|
|
template< |
105 |
|
|
typename Scalar, |
106 |
|
|
int Options, |
107 |
|
|
template<typename, int> class JointCollectionTpl, |
108 |
|
|
typename Mat, |
109 |
|
|
typename MatRes> |
110 |
|
|
MatRes & Mv( |
111 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
112 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
113 |
|
|
const Eigen::MatrixBase<Mat> & min, |
114 |
|
|
const Eigen::MatrixBase<MatRes> & mout); |
115 |
|
|
|
116 |
|
|
/// |
117 |
|
|
/// \brief Performs the multiplication \f$ M v \f$ by using the Cholesky decomposition of M |
118 |
|
|
/// stored in data. |
119 |
|
|
/// |
120 |
|
|
/// \tparam JointCollection Collection of Joint types. |
121 |
|
|
/// |
122 |
|
|
/// \param[in] model The model structure of the rigid body system. |
123 |
|
|
/// \param[in] data The data structure of the rigid body system. |
124 |
|
|
/// \param[inout] m The input matrix where the result of \f$ Mv \f$ is stored. |
125 |
|
|
/// |
126 |
|
|
/// \return A reference of the result of \f$ Mv \f$. |
127 |
|
|
/// |
128 |
|
|
template< |
129 |
|
|
typename Scalar, |
130 |
|
|
int Options, |
131 |
|
|
template<typename, int> class JointCollectionTpl, |
132 |
|
|
typename Mat> |
133 |
|
|
Mat & UDUtv( |
134 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
135 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
136 |
|
|
const Eigen::MatrixBase<Mat> & m); |
137 |
|
|
|
138 |
|
|
/// |
139 |
|
|
/// \brief Perform the sparse multiplication \f$ Uv \f$ using the Cholesky decomposition stored |
140 |
|
|
/// in data and acting in place. |
141 |
|
|
/// |
142 |
|
|
/// \tparam JointCollection Collection of Joint types. |
143 |
|
|
/// |
144 |
|
|
/// \param[in] model The model structure of the rigid body system. |
145 |
|
|
/// \param[in] data The data structure of the rigid body system. |
146 |
|
|
/// \param[inout] v The input matrix to multiply with data.U and also storing the result. |
147 |
|
|
/// |
148 |
|
|
/// \return A reference to the result of \f$ Uv \f$ stored in v. |
149 |
|
|
/// |
150 |
|
|
template< |
151 |
|
|
typename Scalar, |
152 |
|
|
int Options, |
153 |
|
|
template<typename, int> class JointCollectionTpl, |
154 |
|
|
typename Mat> |
155 |
|
|
Mat & Uv( |
156 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
157 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
158 |
|
|
const Eigen::MatrixBase<Mat> & v); |
159 |
|
|
|
160 |
|
|
/// |
161 |
|
|
/// \brief Perform the sparse multiplication \f$ U^{\top}v \f$ using the Cholesky decomposition |
162 |
|
|
/// stored in data and acting in place. |
163 |
|
|
/// |
164 |
|
|
/// \tparam JointCollection Collection of Joint types. |
165 |
|
|
/// |
166 |
|
|
/// \param[in] model The model structure of the rigid body system. |
167 |
|
|
/// \param[in] data The data structure of the rigid body system. |
168 |
|
|
/// \param[inout] v The input matrix to multiply with data.U.tranpose() and also storing the |
169 |
|
|
/// result. |
170 |
|
|
/// |
171 |
|
|
/// \return A reference to the result of \f$ U^{\top}v \f$ stored in v. |
172 |
|
|
/// |
173 |
|
|
template< |
174 |
|
|
typename Scalar, |
175 |
|
|
int Options, |
176 |
|
|
template<typename, int> class JointCollectionTpl, |
177 |
|
|
typename Mat> |
178 |
|
|
Mat & Utv( |
179 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
180 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
181 |
|
|
const Eigen::MatrixBase<Mat> & v); |
182 |
|
|
|
183 |
|
|
/// |
184 |
|
|
/// \brief Perform the pivot inversion \f$ U^{-1}v \f$ using the Cholesky decomposition stored |
185 |
|
|
/// in data and acting in place. |
186 |
|
|
/// |
187 |
|
|
/// \tparam JointCollection Collection of Joint types. |
188 |
|
|
/// |
189 |
|
|
/// \param[in] model The model structure of the rigid body system. |
190 |
|
|
/// \param[in] data The data structure of the rigid body system. |
191 |
|
|
/// \param[inout] v The input matrix to multiply with data.U^{-1} and also storing the result. |
192 |
|
|
/// |
193 |
|
|
/// \return A reference to the result of \f$ U^{-1}v \f$ stored in v. |
194 |
|
|
/// |
195 |
|
|
/// \remarks The result is similar to the code data.U.triangularView<Eigen::Upper> |
196 |
|
|
/// ().solveInPlace(v). |
197 |
|
|
/// |
198 |
|
|
template< |
199 |
|
|
typename Scalar, |
200 |
|
|
int Options, |
201 |
|
|
template<typename, int> class JointCollectionTpl, |
202 |
|
|
typename Mat> |
203 |
|
|
Mat & Uiv( |
204 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
205 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
206 |
|
|
const Eigen::MatrixBase<Mat> & v); |
207 |
|
|
|
208 |
|
|
/// |
209 |
|
|
/// \brief Perform the pivot inversion \f$ U^{-\top}v \f$ using the Cholesky decomposition |
210 |
|
|
/// stored in data and acting in place. |
211 |
|
|
/// |
212 |
|
|
/// \tparam JointCollection Collection of Joint types. |
213 |
|
|
/// |
214 |
|
|
/// \param[in] model The model structure of the rigid body system. |
215 |
|
|
/// \param[in] data The data structure of the rigid body system. |
216 |
|
|
/// \param[inout] v The input matrix to multiply with data.U^{-\top} and also storing the |
217 |
|
|
/// result. |
218 |
|
|
/// |
219 |
|
|
/// \return A reference to the result of \f$ U^{-\top}v \f$ stored in v. |
220 |
|
|
/// |
221 |
|
|
/// \remarks The result is similar to the code data.U.triangularView<Eigen::Upper> |
222 |
|
|
/// ().transpose().solveInPlace(v). |
223 |
|
|
/// |
224 |
|
|
template< |
225 |
|
|
typename Scalar, |
226 |
|
|
int Options, |
227 |
|
|
template<typename, int> class JointCollectionTpl, |
228 |
|
|
typename Mat> |
229 |
|
|
Mat & Utiv( |
230 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
231 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
232 |
|
|
const Eigen::MatrixBase<Mat> & v); |
233 |
|
|
|
234 |
|
|
/// |
235 |
|
|
/// \brief Perform the sparse inversion \f$ M^{-1}v \f$ using the Cholesky decomposition stored |
236 |
|
|
/// in data and acting in place. |
237 |
|
|
/// |
238 |
|
|
/// \tparam JointCollection Collection of Joint types. |
239 |
|
|
/// |
240 |
|
|
/// \param[in] model The model structure of the rigid body system. |
241 |
|
|
/// \param[in] data The data structure of the rigid body system. |
242 |
|
|
/// \param[inout] v The input matrix to multiply with data.M^{-1} and also storing the result. |
243 |
|
|
/// |
244 |
|
|
/// \return A reference to the result of \f$ M^{-1}v \f$ stored in v. |
245 |
|
|
/// |
246 |
|
|
|
247 |
|
|
// TODO Clearify, it seems it is exactly the same as solve in l. 54 |
248 |
|
|
template< |
249 |
|
|
typename Scalar, |
250 |
|
|
int Options, |
251 |
|
|
template<typename, int> class JointCollectionTpl, |
252 |
|
|
typename Mat> |
253 |
|
|
Mat & solve( |
254 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
255 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
256 |
|
|
const Eigen::MatrixBase<Mat> & v); |
257 |
|
|
|
258 |
|
|
/// |
259 |
|
|
/// \brief Computes the inverse of the joint space inertia matrix M from its Cholesky |
260 |
|
|
/// factorization. |
261 |
|
|
/// |
262 |
|
|
/// \tparam JointCollection Collection of Joint types. |
263 |
|
|
/// |
264 |
|
|
/// \param[in] model The model structure of the rigid body system. |
265 |
|
|
/// \param[in] data The data structure of the rigid body system. |
266 |
|
|
/// \param[out] Minv The output matrix where the result is stored. |
267 |
|
|
/// |
268 |
|
|
/// \return A reference to the result. |
269 |
|
|
/// |
270 |
|
|
template< |
271 |
|
|
typename Scalar, |
272 |
|
|
int Options, |
273 |
|
|
template<typename, int> class JointCollectionTpl, |
274 |
|
|
typename Mat> |
275 |
|
|
Mat & computeMinv( |
276 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
277 |
|
|
const DataTpl<Scalar, Options, JointCollectionTpl> & data, |
278 |
|
|
const Eigen::MatrixBase<Mat> & Minv); |
279 |
|
|
|
280 |
|
|
/// |
281 |
|
|
/// \brief Computes the inverse of the joint space inertia matrix M from its Cholesky |
282 |
|
|
/// factorization. |
283 |
|
|
/// The results is then directly stored in data.Minv. |
284 |
|
|
/// |
285 |
|
|
/// \tparam JointCollection Collection of Joint types. |
286 |
|
|
/// |
287 |
|
|
/// \param[in] model The model structure of the rigid body system. |
288 |
|
|
/// \param[in] data The data structure of the rigid body system. |
289 |
|
|
/// |
290 |
|
|
/// \return A reference to the result data.Minv. |
291 |
|
|
/// |
292 |
|
|
template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> |
293 |
|
1 |
const typename DataTpl<Scalar, Options, JointCollectionTpl>::RowMatrixXs & computeMinv( |
294 |
|
|
const ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
295 |
|
|
DataTpl<Scalar, Options, JointCollectionTpl> & data) |
296 |
|
|
{ |
297 |
|
1 |
return computeMinv(model, data, data.Minv); |
298 |
|
|
} |
299 |
|
|
|
300 |
|
|
} // namespace cholesky |
301 |
|
|
} // namespace pinocchio |
302 |
|
|
|
303 |
|
|
/* --- Details -------------------------------------------------------------------- */ |
304 |
|
|
/* --- Details -------------------------------------------------------------------- */ |
305 |
|
|
/* --- Details -------------------------------------------------------------------- */ |
306 |
|
|
#include "pinocchio/algorithm/cholesky.hxx" |
307 |
|
|
|
308 |
|
|
#if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION |
309 |
|
|
#include "pinocchio/algorithm/cholesky.txx" |
310 |
|
|
#endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION |
311 |
|
|
|
312 |
|
|
#endif // ifndef __pinocchio_cholesky_hpp__ |
313 |
|
|
|