GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/algorithm/center-of-mass.hpp Lines: 0 2 0.0 %
Date: 2024-01-23 21:41:47 Branches: 0 0 - %

Line Branch Exec Source
1
//
2
// Copyright (c) 2015-2020 CNRS INRIA
3
//
4
5
#ifndef __pinocchio_algorithm_center_of_mass_hpp__
6
#define __pinocchio_algorithm_center_of_mass_hpp__
7
8
#include "pinocchio/multibody/model.hpp"
9
#include "pinocchio/multibody/data.hpp"
10
11
namespace pinocchio
12
{
13
14
  ///
15
  /// \brief Compute the total mass of the model and return it.
16
  ///
17
  /// \param[in] model The model structure of the rigid body system.
18
  ///
19
  /// \return Total mass of the model.
20
  ///
21
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
22
  inline Scalar computeTotalMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model);
23
24
  ///
25
  /// \brief Compute the total mass of the model, put it in data.mass[0] and return it.
26
  ///
27
  /// \param[in] model The model structure of the rigid body system.
28
  /// \param[in] data The data structure of the rigid body system.
29
  ///
30
  /// \warning This method does not fill the whole data.mass vector. Only data.mass[0] is updated.
31
  /// If you need the whole data.mass vector to be computed, use computeSubtreeMasses
32
  ///
33
  /// \return Total mass of the model.
34
  ///
35
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
36
  inline Scalar computeTotalMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
37
                                 DataTpl<Scalar,Options,JointCollectionTpl> & data);
38
39
  ///
40
  /// \brief Compute the mass of each kinematic subtree and store it in data.mass. The element mass[0] corresponds to the total mass of the model.
41
  ///
42
  /// \param[in] model The model structure of the rigid body system.
43
  /// \param[in] data The data structure of the rigid body system.
44
  ///
45
  /// \note If you are only interested in knowing the total mass of the model, computeTotalMass will probably be slightly faster.
46
  ///
47
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
48
  inline void computeSubtreeMasses(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
49
                                   DataTpl<Scalar,Options,JointCollectionTpl> & data);
50
51
  ///
52
  /// \brief Computes the center of mass position of a given model according to a particular joint configuration.
53
  ///        The result is accessible through data.com[0] for the full body com and data.com[i] for the subtree supported by joint i (expressed in the joint i frame).
54
  ///
55
  /// \tparam JointCollection Collection of Joint types.
56
  /// \tparam ConfigVectorType Type of the joint configuration vector.
57
  ///
58
  /// \param[in] model The model structure of the rigid body system.
59
  /// \param[in] data The data structure of the rigid body system.
60
  /// \param[in] q The joint configuration vector (dim model.nq).
61
  /// \param[in] computeSubtreeComs If true, the algorithm computes also the center of mass of the subtrees.
62
  ///
63
  /// \return The center of mass position of the full rigid body system expressed in the world frame.
64
  ///
65
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType>
66
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::Vector3 &
67
  centerOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
68
               DataTpl<Scalar,Options,JointCollectionTpl> & data,
69
               const Eigen::MatrixBase<ConfigVectorType> & q,
70
               const bool computeSubtreeComs = true);
71
72
  ///
73
  /// \brief Computes the center of mass position and velocity of a given model according to a particular joint configuration and velocity.
74
  ///        The result is accessible through data.com[0], data.vcom[0] for the full body com position and velocity.
75
  ///        And data.com[i] and data.vcom[i] for the subtree supported by joint i (expressed in the joint i frame).
76
  ///
77
  /// \tparam JointCollection Collection of Joint types.
78
  /// \tparam ConfigVectorType Type of the joint configuration vector.
79
  /// \tparam TangentVectorType Type of the joint velocity vector.
80
  ///
81
  /// \param[in] model The model structure of the rigid body system.
82
  /// \param[in] data The data structure of the rigid body system.
83
  /// \param[in] q The joint configuration vector (dim model.nq).
84
  /// \param[in] v The joint velocity vector (dim model.nv).
85
  /// \param[in] computeSubtreeComs If true, the algorithm computes also the center of mass of the subtrees.
86
  ///
87
  /// \return The center of mass position of the full rigid body system expressed in the world frame.
88
  ///
89
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType, typename TangentVectorType>
90
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::Vector3 &
91
  centerOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
92
               DataTpl<Scalar,Options,JointCollectionTpl> & data,
93
               const Eigen::MatrixBase<ConfigVectorType> & q,
94
               const Eigen::MatrixBase<TangentVectorType> & v,
95
               const bool computeSubtreeComs = true);
96
97
  ///
98
  /// \brief Computes the center of mass position, velocity and acceleration of a given model according to a particular joint configuration, velocity and acceleration.
99
  ///        The result is accessible through data.com[0], data.vcom[0], data.acom[0] for the full body com position, velocity and acceleation.
100
  ///        And data.com[i], data.vcom[i] and data.acom[i] for the subtree supported by joint i (expressed in the joint i frame).
101
  ///
102
  /// \tparam JointCollection Collection of Joint types.
103
  /// \tparam ConfigVectorType Type of the joint configuration vector.
104
  /// \tparam TangentVectorType1 Type of the joint velocity vector.
105
  /// \tparam TangentVectorType2 Type of the joint acceleration vector.
106
  ///
107
  /// \param[in] model The model structure of the rigid body system.
108
  /// \param[in] data The data structure of the rigid body system.
109
  /// \param[in] q The joint configuration vector (dim model.nq).
110
  /// \param[in] v The joint velocity vector (dim model.nv).
111
  /// \param[in] a The joint acceleration vector (dim model.nv).
112
  /// \param[in] computeSubtreeComs If true, the algorithm computes also the center of mass of the subtrees.
113
  ///
114
  /// \return The center of mass position of the full rigid body system expressed in the world frame.
115
  ///
116
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType, typename TangentVectorType1, typename TangentVectorType2>
117
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::Vector3 &
118
  centerOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
119
               DataTpl<Scalar,Options,JointCollectionTpl> & data,
120
               const Eigen::MatrixBase<ConfigVectorType> & q,
121
               const Eigen::MatrixBase<TangentVectorType1> & v,
122
               const Eigen::MatrixBase<TangentVectorType2> & a,
123
               const bool computeSubtreeComs = true);
124
125
  ///
126
  /// \brief Computes the center of mass position, velocity and acceleration of a given model according to the current kinematic values contained in data and the requested kinematic_level.
127
  ///        The result is accessible through data.com[0], data.vcom[0] and data.acom[0] for the full body com position and velocity.
128
  ///        And data.com[i] and data.vcom[i] for the subtree supported by joint i (expressed in the joint i frame).
129
  ///
130
  /// \tparam JointCollection Collection of Joint types.
131
  ///
132
  /// \param[in] model The model structure of the rigid body system.
133
  /// \param[in] data The data structure of the rigid body system.
134
  /// \param[in] kinematic_level if = POSITION, computes the CoM position, if = VELOCITY, also computes the CoM velocity and if = ACCELERATION, it also computes the CoM acceleration.
135
  /// \param[in] computeSubtreeComs If true, the algorithm computes also the center of mass of the subtrees.
136
  ///
137
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
138
  const typename DataTpl<Scalar,Options,JointCollectionTpl>::Vector3 &
139
  centerOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
140
               DataTpl<Scalar,Options,JointCollectionTpl> & data,
141
               KinematicLevel kinematic_level,
142
               const bool computeSubtreeComs = true);
143
144
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
145
  PINOCCHIO_DEPRECATED
146
  inline void centerOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
147
                           DataTpl<Scalar,Options,JointCollectionTpl> & data,
148
                           int kinematic_level,
149
                           const bool computeSubtreeComs = true)
150
  {
151
    centerOfMass(model,data,static_cast<KinematicLevel>(kinematic_level),computeSubtreeComs);
152
  }
153
154
  ///
155
  /// \brief Computes the center of mass position, velocity and acceleration of a given model according to the current kinematic values contained in data.
156
  ///        The result is accessible through data.com[0], data.vcom[0] and data.acom[0] for the full body com position and velocity.
157
  ///        And data.com[i] and data.vcom[i] for the subtree supported by joint i (expressed in the joint i frame).
158
  ///
159
  /// \tparam JointCollection Collection of Joint types.
160
  ///
161
  /// \param[in] model The model structure of the rigid body system.
162
  /// \param[in] data The data structure of the rigid body system.
163
  /// \param[in] computeSubtreeComs If true, the algorithm computes also the center of mass of the subtrees, expressed in the local coordinate frame of each joint.
164
  ///
165
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
166
  const typename DataTpl<Scalar,Options,JointCollectionTpl>::Vector3 &
167
  centerOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
168
               DataTpl<Scalar,Options,JointCollectionTpl> & data,
169
               const bool computeSubtreeComs = true)
170
  { return centerOfMass(model,data,ACCELERATION,computeSubtreeComs); }
171
172
  ///
173
  /// \brief Computes both the jacobian and the the center of mass position of a given model according to a particular joint configuration.
174
  ///        The results are accessible through data.Jcom and data.com[0] and are both expressed in the world frame. In addition, the algorithm also computes the Jacobian of all the joints (\sa pinocchio::computeJointJacobians).
175
  ///        And data.com[i] gives the center of mass of the subtree supported by joint i (expressed in the world frame).
176
  ///
177
  /// \tparam JointCollection Collection of Joint types.
178
  /// \tparam ConfigVectorType Type of the joint configuration vector.
179
  ///
180
  /// \param[in] model The model structure of the rigid body system.
181
  /// \param[in] data The data structure of the rigid body system.
182
  /// \param[in] q The joint configuration vector (dim model.nq).
183
  /// \param[in] computeSubtreeComs If true, the algorithm also computes the centers of mass of the subtrees, expressed in the world coordinate frame.
184
  ///
185
  /// \return The jacobian of center of mass position of the rigid body system expressed in the world frame (matrix 3 x model.nv).
186
  ///
187
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType>
188
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::Matrix3x &
189
  jacobianCenterOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
190
                       DataTpl<Scalar,Options,JointCollectionTpl> & data,
191
                       const Eigen::MatrixBase<ConfigVectorType> & q,
192
                       const bool computeSubtreeComs = true);
193
194
  ///
195
  /// \brief Computes both the jacobian and the the center of mass position of a given model according to the current value stored in data.
196
  ///        It assumes that forwardKinematics has been called first.
197
  ///        The results are accessible through data.Jcom and data.com[0] and are both expressed in the world frame. In addition, the algorithm also computes the Jacobian of all the joints (\sa pinocchio::computeJointJacobians).
198
  ///        And data.com[i] gives the center of mass of the subtree supported by joint i (expressed in the world frame).
199
  ///
200
  /// \tparam JointCollection Collection of Joint types.
201
  /// \tparam ConfigVectorType Type of the joint configuration vector.
202
  ///
203
  /// \param[in] model The model structure of the rigid body system.
204
  /// \param[in] data The data structure of the rigid body system.
205
  /// \param[in] computeSubtreeComs If true, the algorithm also computes the center of mass of the subtrees, expressed in the world coordinate frame.
206
  ///
207
  /// \return The jacobian of center of mass position of the rigid body system expressed in the world frame (matrix 3 x model.nv).
208
  ///
209
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
210
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::Matrix3x &
211
  jacobianCenterOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
212
                       DataTpl<Scalar,Options,JointCollectionTpl> & data,
213
                       const bool computeSubtreeComs = true);
214
215
  ///
216
  /// \brief Computes the Jacobian of the center of mass of the given subtree according to a particular joint configuration.
217
  ///        In addition, the algorithm also computes the Jacobian of all the joints (\sa pinocchio::computeJointJacobians).
218
  ///
219
  /// \tparam JointCollection Collection of Joint types.
220
  /// \tparam ConfigVectorType Type of the joint configuration vector.
221
  /// \tparam Matrix3xLike Type of the output Jacobian matrix.
222
  ///
223
  /// \param[in] model The model structure of the rigid body system.
224
  /// \param[in] data The data structure of the rigid body system.
225
  /// \param[in] q The joint configuration vector (dim model.nq).
226
  /// \param[in] rootSubtreeId Index of the parent joint supporting the subtree.
227
  /// \param[out] res The Jacobian matrix where the results will be stored in (dim 3 x model.nv). You must first fill J with zero elements, e.g. J.setZero().
228
  ///
229
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType, typename Matrix3xLike>
230
  inline void
231
  jacobianSubtreeCenterOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
232
                              DataTpl<Scalar,Options,JointCollectionTpl> & data,
233
                              const Eigen::MatrixBase<ConfigVectorType> & q,
234
                              const JointIndex & rootSubtreeId,
235
                              const Eigen::MatrixBase<Matrix3xLike> & res);
236
237
  ///
238
  /// \brief Computes the Jacobian of the center of mass of the given subtree according to the current value stored in data.
239
  ///        It assumes that forwardKinematics has been called first.
240
  ///
241
  /// \tparam JointCollection Collection of Joint types.
242
  /// \tparam Matrix3xLike Type of the output Jacobian matrix.
243
  ///
244
  /// \param[in] model The model structure of the rigid body system.
245
  /// \param[in] data The data structure of the rigid body system.
246
  /// \param[in] rootSubtreeId Index of the parent joint supporting the subtree.
247
  /// \param[out] res The Jacobian matrix where the results will be stored in (dim 3 x model.nv). You must first fill J with zero elements, e.g. J.setZero().
248
  ///
249
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename Matrix3xLike>
250
  inline void
251
  jacobianSubtreeCenterOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
252
                              DataTpl<Scalar,Options,JointCollectionTpl> & data,
253
                              const JointIndex & rootSubtreeId,
254
                              const Eigen::MatrixBase<Matrix3xLike> & res);
255
256
  ///
257
  /// \brief Retrieves the Jacobian of the center of mass of the given subtree according to the current value stored in data.
258
  ///        It assumes that pinocchio::jacobianCenterOfMass has been called first with computeSubtreeComs equals to true.
259
  ///
260
  /// \tparam JointCollection Collection of Joint types.
261
  /// \tparam Matrix3xLike Type of the output Jacobian matrix.
262
  ///
263
  /// \param[in] model The model structure of the rigid body system.
264
  /// \param[in] data The data structure of the rigid body system.
265
  /// \param[in] rootSubtreeId Index of the parent joint supporting the subtree.
266
  /// \param[out] res The Jacobian matrix where the results will be stored in (dim 3 x model.nv). You must first fill J with zero elements, e.g. J.setZero().
267
  ///
268
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename Matrix3xLike>
269
  inline void
270
  getJacobianSubtreeCenterOfMass(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
271
                                 const DataTpl<Scalar,Options,JointCollectionTpl> & data,
272
                                 const JointIndex & rootSubtreeId,
273
                                 const Eigen::MatrixBase<Matrix3xLike> & res);
274
275
276
  /* If the CRBA has been run, then both COM and Jcom are easily available from
277
   * the joint space mass matrix (data.M).
278
   * Use the following function to infer them directly. In that case,
279
   * the COM subtrees (also easily available from CRBA data) are not
280
   * explicitely set. Use data.Ycrb[i].lever() to get them. */
281
  ///
282
  /// \brief Extracts the center of mass position from the joint space inertia matrix (also called the mass matrix).
283
  ///
284
  /// \tparam JointCollection Collection of Joint types.
285
  /// \tparam Matrix3xLike Type of the output Jacobian matrix.
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 The center of mass position of the rigid body system expressed in the world frame (vector 3).
291
  ///
292
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
293
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::Vector3 &
294
  getComFromCrba(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
295
                 DataTpl<Scalar,Options,JointCollectionTpl> & data);
296
297
  ///
298
  /// \brief Extracts both the jacobian of the center of mass (CoM), the total mass of the system and the CoM position from the joint space inertia matrix (also called the mass matrix).
299
  ///        The results are accessible through data.Jcom, data.mass[0] and data.com[0] and are both expressed in the world frame.
300
  ///
301
  /// \tparam JointCollection Collection of Joint types.
302
  ///
303
  /// \param[in] model The model structure of the rigid body system.
304
  /// \param[in] data The data structure of the rigid body system.
305
  ///
306
  /// \return The jacobian of the CoM expressed in the world frame (matrix 3 x model.nv).
307
  ///
308
  /// \remark This extraction of inertial quantities is only valid for free-floating base systems.
309
  ///
310
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
311
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::Matrix3x &
312
  getJacobianComFromCrba(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
313
                         DataTpl<Scalar,Options,JointCollectionTpl> & data);
314
315
} // namespace pinocchio
316
317
/* --- Details -------------------------------------------------------------------- */
318
/* --- Details -------------------------------------------------------------------- */
319
/* --- Details -------------------------------------------------------------------- */
320
#include "pinocchio/algorithm/center-of-mass.hxx"
321
322
#endif // ifndef __pinocchio_algorithm_center_of_mass_hpp__