GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/algorithm/frames.hpp Lines: 4 4 100.0 %
Date: 2024-04-26 13:14:21 Branches: 0 0 - %

Line Branch Exec Source
1
//
2
// Copyright (c) 2015-2020 CNRS INRIA
3
//
4
5
#ifndef __pinocchio_algorithm_frames_hpp__
6
#define __pinocchio_algorithm_frames_hpp__
7
8
#include "pinocchio/multibody/model.hpp"
9
#include "pinocchio/multibody/data.hpp"
10
11
namespace pinocchio
12
{
13
14
  /**
15
   * @brief      Updates the position of each frame contained in the model.
16
   *
17
   * @tparam JointCollection Collection of Joint types.
18
   *
19
   * @param[in]  model  The kinematic model.
20
   * @param      data   Data associated to model.
21
   *
22
   * @warning    One of the algorithms forwardKinematics should have been called first.
23
   */
24
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
25
  inline void updateFramePlacements(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
26
                                    DataTpl<Scalar,Options,JointCollectionTpl> & data);
27
28
  /**
29
   * @brief      Updates the placement of the given frame.
30
   *
31
   * @param[in]  model        The kinematic model.
32
   * @param      data         Data associated to model.
33
   * @param[in]  frame_id     Id of the operational Frame.
34
   *
35
   * @return     A reference to the frame placement stored in data.oMf[frame_id]
36
   *
37
   * @warning    One of the algorithms forwardKinematics should have been called first
38
   */
39
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
40
  inline const typename DataTpl<Scalar,Options,JointCollectionTpl>::SE3 &
41
  updateFramePlacement(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
42
                       DataTpl<Scalar,Options,JointCollectionTpl> & data,
43
                       const FrameIndex frame_id);
44
45
46
  /**
47
   * @brief      First calls the forwardKinematics on the model, then computes the placement of each frame.
48
   *             /sa pinocchio::forwardKinematics.
49
   *
50
   * @tparam JointCollection Collection of Joint types.
51
   * @tparam ConfigVectorType Type of the joint configuration vector.
52
   *
53
   * @param[in]  model                    The kinematic model.
54
   * @param      data                     Data associated to model.
55
   * @param[in]  q                        Configuration vector.
56
   */
57
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType>
58
  inline void framesForwardKinematics(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
59
                                      DataTpl<Scalar,Options,JointCollectionTpl> & data,
60
                                      const Eigen::MatrixBase<ConfigVectorType> & q);
61
62
63
  /**
64
   * @brief      Updates the position of each frame contained in the model.
65
   *             This function is now deprecated and has been renamed updateFramePlacements.
66
   *
67
   * @tparam JointCollection Collection of Joint types.
68
   *
69
   * @param[in]  model  The kinematic model.
70
   * @param      data   Data associated to model.
71
   *
72
   * @warning    One of the algorithms forwardKinematics should have been called first.
73
  */
74
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
75
  PINOCCHIO_DEPRECATED
76
  inline void framesForwardKinematics(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
77
                                      DataTpl<Scalar,Options,JointCollectionTpl> & data)
78
  {
79
    updateFramePlacements(model,data);
80
  }
81
82
83
  /**
84
   * @brief      Returns the spatial velocity of the Frame expressed in the desired reference frame.
85
   *             You must first call pinocchio::forwardKinematics to update placement and velocity values in data structure.
86
   *
87
   * @param[in]  model       The kinematic model
88
   * @param[in]  data        Data associated to model
89
   * @param[in]  frame_id    Id of the operational Frame
90
   * @param[in]  rf          Reference frame in which the velocity is expressed.
91
   *
92
   * @return     The spatial velocity of the Frame expressed in the desired reference frame.
93
   *
94
   * @warning    Fist or second order forwardKinematics should have been called first
95
   */
96
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
97
  inline MotionTpl<Scalar, Options>
98
  getFrameVelocity(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
99
                   const DataTpl<Scalar,Options,JointCollectionTpl> & data,
100
                   const FrameIndex frame_id,
101
                   const ReferenceFrame rf = LOCAL);
102
103
  /**
104
   * @brief      Returns the spatial acceleration of the Frame expressed in the desired reference frame.
105
   *             You must first call pinocchio::forwardKinematics to update placement, velocity and acceleration values in the data structure.
106
   *
107
   * @param[in]  model       The kinematic model
108
   * @param[in]  data        Data associated to model
109
   * @param[in]  frame_id    Id of the operational Frame
110
   * @param[in]  rf          Reference frame in which the acceleration is expressed.
111
   *
112
   * @return The spatial acceleration of the Frame expressed in the desired reference frame.
113
   *
114
   * @warning    Second order @ref forwardKinematics should have been called first
115
   *
116
   * @remark     In the context of a frame placement constraint \f$J(q) a + \dot{J}(q, v) v = 0\f$,
117
   *             one way to compute the second term \f$\dot{J}(q, v) v\f$ is to call second-order @ref forwardKinematics with a zero acceleration,
118
   *             then read the remaining \f$\dot{J}(q, v) v\f$ by calling this function.
119
   *             This is significantly more efficient than applying the matrix \f$\dot{J}(q, v)\f$ (from @ref getFrameJacobianTimeVariation)
120
   *             to the velocity vector \f$v\f$.
121
   */
122
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
123
  inline MotionTpl<Scalar, Options>
124
  getFrameAcceleration(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
125
                       const DataTpl<Scalar,Options,JointCollectionTpl> & data,
126
                       const FrameIndex frame_id,
127
                       const ReferenceFrame rf = LOCAL);
128
129
  /**
130
   * @brief      Returns the "classical" acceleration of the Frame expressed in the desired reference frame.
131
   *             This is different from the "spatial" acceleration in that centrifugal effects are accounted for.
132
   *             You must first call pinocchio::forwardKinematics to update placement, velocity and acceleration values in data structure.
133
   *
134
   * @param[in]  model       The kinematic model
135
   * @param[in]  data        Data associated to model
136
   * @param[in]  frame_id    Id of the operational Frame
137
   * @param[in]  rf          Reference frame in which the acceleration is expressed.
138
   *
139
   * @return The classical acceleration of the Frame expressed in the desired reference frame.
140
   *
141
   * @warning    Second order @ref forwardKinematics should have been called first
142
   *
143
   * @remark     In the context of a frame placement constraint \f$J(q) a + \dot{J}(q, v) v = 0\f$,
144
   *             one way to compute the second term \f$\dot{J}(q, v) v\f$ is to call second-order @ref forwardKinematics with a zero acceleration,
145
   *             then read the remaining \f$\dot{J}(q, v) v\f$ by calling this function.
146
   *             This is significantly more efficient than applying the matrix \f$\dot{J}(q, v)\f$ (from @ref getFrameJacobianTimeVariation)
147
   *             to the velocity vector \f$v\f$.
148
   *
149
   */
150
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
151
  inline MotionTpl<Scalar, Options>
152
  getFrameClassicalAcceleration(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
153
                                const DataTpl<Scalar,Options,JointCollectionTpl> & data,
154
                                const FrameIndex frame_id,
155
                                const ReferenceFrame rf = LOCAL);
156
157
  /**
158
   * @brief      Returns the jacobian of the frame expressed either expressed in the LOCAL frame coordinate system or in the WORLD coordinate system,
159
   *             depending on the value of rf.
160
   *             You must first call pinocchio::computeJointJacobians followed by pinocchio::framesForwardKinematics to update placement values in data structure.
161
   *
162
   * @remark     Similarly to pinocchio::getJointJacobian with LOCAL or WORLD parameters, if rf == LOCAL, this function returns the Jacobian of the frame expressed
163
   *             in the local coordinates of the frame, or if rl == WORLD, it returns the Jacobian expressed of the point coincident with the origin
164
   *             and expressed in a coordinate system aligned with the WORLD.
165
   *
166
   * @tparam JointCollection Collection of Joint types.
167
   * @tparam Matrix6xLike Type of the matrix containing the joint Jacobian.
168
   *
169
   * @param[in]  model       The kinematic model
170
   * @param[in]  data        Data associated to model
171
   * @param[in]  frame_id    Id of the operational Frame
172
   * @param[in]  rf          Reference frame in which the Jacobian is expressed.
173
   * @param[out] J           The Jacobian of the Frame expressed in the coordinates Frame.
174
   *
175
   * @warning    The function pinocchio::computeJointJacobians should have been called first.
176
   */
177
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename Matrix6xLike>
178
  inline void getFrameJacobian(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
179
                               DataTpl<Scalar,Options,JointCollectionTpl> & data,
180
                               const FrameIndex frame_id,
181
                               const ReferenceFrame rf,
182
                               const Eigen::MatrixBase<Matrix6xLike> & J);
183
184
  ///
185
  /// \brief Computes the Jacobian of a specific Frame expressed in the desired reference_frame given as argument.
186
  ///
187
  /// \tparam JointCollection Collection of Joint types.
188
  /// \tparam ConfigVectorType Type of the joint configuration vector.
189
  /// \tparam Matrix6xLike Type of the matrix containing the joint Jacobian.
190
  ///
191
  /// \param[in] model                                The model structure of the rigid body system.
192
  /// \param[in] data                                  The data structure of the rigid body system.
193
  /// \param[in] q                                         The joint configuration vector (dim model.nq).
194
  /// \param[in] frameId                            The id of the Frame refering to model.frames[frameId].
195
  /// \param[in] reference_frame          Reference frame in which the Jacobian is expressed.
196
  /// \param[out] J                                       A reference on the Jacobian matrix where the results will be stored in (dim 6 x model.nv). You must fill J with zero elements, e.g. J.setZero().
197
  ///
198
  /// \return The Jacobian of the specific Frame expressed in the desired reference frame (matrix 6 x model.nv).
199
  ///
200
  /// \remarks The result of this function is equivalent to call first computeJointJacobians(model,data,q), then updateFramePlacements(model,data) and then call getJointJacobian(model,data,jointId,rf,J),
201
  ///         but forwardKinematics and updateFramePlacements are not fully computed.
202
  ///
203
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType, typename Matrix6xLike>
204
  inline void computeFrameJacobian(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
205
                                   DataTpl<Scalar,Options,JointCollectionTpl> & data,
206
                                   const Eigen::MatrixBase<ConfigVectorType> & q,
207
                                   const FrameIndex frameId,
208
                                   const ReferenceFrame reference_frame,
209
                                   const Eigen::MatrixBase<Matrix6xLike> & J);
210
211
  ///
212
  /// \brief Computes the Jacobian of a specific Frame expressed in the LOCAL frame coordinate system.
213
  ///
214
  /// \tparam JointCollection Collection of Joint types.
215
  /// \tparam ConfigVectorType Type of the joint configuration vector.
216
  /// \tparam Matrix6xLike Type of the matrix containing the joint Jacobian.
217
  ///
218
  /// \param[in] model The model structure of the rigid body system.
219
  /// \param[in] data The data structure of the rigid body system.
220
  /// \param[in] q The joint configuration vector (dim model.nq).
221
  /// \param[in] frameId The id of the Frame refering to model.frames[frameId].
222
  ///
223
  /// \param[out] J A reference on the Jacobian matrix where the results will be stored in (dim 6 x model.nv). You must fill J with zero elements, e.g. J.setZero().
224
  ///
225
  /// \return The Jacobian of the specific Frame expressed in the LOCAL frame coordinate system (matrix 6 x model.nv).
226
  ///
227
  /// \remarks The result of this function is equivalent to call first computeJointJacobians(model,data,q), then updateFramePlacements(model,data) and then call getJointJacobian(model,data,jointId,LOCAL,J),
228
  ///         but forwardKinematics and updateFramePlacements are not fully computed.
229
  ///
230
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType, typename Matrix6xLike>
231
1
  inline void computeFrameJacobian(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
232
                                   DataTpl<Scalar,Options,JointCollectionTpl> & data,
233
                                   const Eigen::MatrixBase<ConfigVectorType> & q,
234
                                   const FrameIndex frameId,
235
                                   const Eigen::MatrixBase<Matrix6xLike> & J)
236
  {
237
1
    computeFrameJacobian(model,data,q.derived(),frameId,LOCAL,
238
1
                         PINOCCHIO_EIGEN_CONST_CAST(Matrix6xLike,J));
239
1
  }
240
241
  ///
242
  /// \brief This function is now deprecated and has been renamed computeFrameJacobian. This signature will be removed in future release of Pinocchio.
243
  ///
244
  /// \copydoc pinocchio::computeFrameJacobian
245
  ///
246
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ConfigVectorType, typename Matrix6xLike>
247
  PINOCCHIO_DEPRECATED
248
  inline void frameJacobian(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
249
                            DataTpl<Scalar,Options,JointCollectionTpl> & data,
250
                            const Eigen::MatrixBase<ConfigVectorType> & q,
251
                            const FrameIndex frameId,
252
                            const Eigen::MatrixBase<Matrix6xLike> & J)
253
  {
254
    computeFrameJacobian(model,data,q,frameId,PINOCCHIO_EIGEN_CONST_CAST(Matrix6xLike,J));
255
  }
256
257
  ///
258
  /// \brief Computes the Jacobian time variation of a specific frame (given by frame_id) expressed either in the LOCAL frame.
259
  ///
260
  /// \note This jacobian is extracted from data.dJ. You have to run pinocchio::computeJointJacobiansTimeVariation before calling it.
261
  ///
262
  /// \tparam JointCollection Collection of Joint types.
263
  /// \tparam Matrix6xLike Type of the matrix containing the joint Jacobian.
264
  ///
265
  /// \param[in] model The model structure of the rigid body system.
266
  /// \param[in] data The data structure of the rigid body system.
267
  /// \param[in] frameId The index of the frame.
268
  ///
269
  /// \param[out] dJ A reference on the Jacobian matrix where the results will be stored in (dim 6 x model.nv). You must fill dJ with zero elements, e.g. dJ.fill(0.).
270
  ///
271
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename Matrix6xLike>
272
  void getFrameJacobianTimeVariation(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
273
                                     DataTpl<Scalar,Options,JointCollectionTpl> & data,
274
                                     const FrameIndex frame_id,
275
                                     const ReferenceFrame rf,
276
                                     const Eigen::MatrixBase<Matrix6xLike> & dJ);
277
278
/**
279
  * @brief Compute the inertia supported by a specific frame (given by frame_id) expressed in the LOCAL frame.
280
  *        The total supported inertia corresponds to the sum of all the inertia after the given frame, i.e :
281
  *         * The frame inertia
282
  *         * The child frames inertia ('Child frames' refers to frames that share the same parent joint and are placed after the given frame)
283
  *         * The child joints inertia (if with_subtree == true)
284
  *        You must first call pinocchio::forwardKinematics to update placement values in data structure.
285
  *
286
  * @note Physically speaking, if the robot were to be cut in two parts at that given frame, this supported inertia would represents the inertia of the part that was after the frame.
287
  *       with_subtree determines if the childs joints must be taken into consideration (if true) or only the current joint (if false).
288
  *
289
  * @note The equivalent function for a joint would be :
290
  *       * to read `data.Ycrb[joint_id]`, after having called pinocchio::crba (if with_subtree == true).
291
  *       * to read `model.inertia[joint_id]` (if with_subtree == false).
292
  *
293
  * @tparam JointCollection Collection of Joint types.
294
  *
295
  * @param[in] model The model structure of the rigid body system.
296
  * @param[in] data The data structure of the rigid body system.
297
  * @param[in] frameId The index of the frame.
298
  * @param[in] with_subtree If false, compute the inertia only inside the frame parent joint if false. If true, include child joints inertia.
299
  *
300
  * @return The computed inertia.
301
  *
302
  * @warning forwardKinematics should have been called first
303
  */
304
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
305
  InertiaTpl<Scalar, Options>
306
  computeSupportedInertiaByFrame(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
307
                                 const DataTpl<Scalar,Options,JointCollectionTpl> & data,
308
                                 const FrameIndex frame_id,
309
                                 bool with_subtree);
310
311
/**
312
  * @brief Computes the force supported by a specific frame (given by frame_id) expressed in the LOCAL frame.
313
  *        The supported force corresponds to the sum of all the forces experienced after the given frame, i.e :
314
  *         * The inertial forces and gravity (applied on the supported inertia in body)
315
  *         * The forces applied by child joints
316
  *         * (The external forces)
317
  *        You must first call pinocchio::rnea to update placements, velocities and efforts values in data structure.
318
  *
319
  * @note If an external force is applied to the frame parent joint (during rnea), it won't be taken in consideration in this function
320
  *       (it will be considered to be applied before the frame in the joint and not after. However external forces applied to child joints will be taken into account).
321
  *
322
  * @note Physically speaking, if the robot were to be separated in two parts glued together at that given frame, the supported force represents the internal forces applide from the part after the cut/frame to the part before.
323
  *       This compute what a force-torque sensor would measures if it would be placed at that frame.
324
  *
325
  * @note The equivalent function for a joint would be to read `data.f[joint_id]`, after having call pinocchio::rnea.
326
  *
327
  * @tparam JointCollection Collection of Joint types.
328
  *
329
  * @param[in] model The model structure of the rigid body system.
330
  * @param[in] data The data structure of the rigid body system.
331
  * @param[in] frameId The index of the frame.
332
  *
333
  * @return The computed force.
334
  *
335
  * @warning pinocchio::rnea should have been called first
336
  */
337
  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
338
  ForceTpl<Scalar, Options>
339
  computeSupportedForceByFrame(const ModelTpl<Scalar,Options,JointCollectionTpl> & model,
340
                               const DataTpl<Scalar,Options,JointCollectionTpl> & data,
341
                               const FrameIndex frame_id);
342
343
} // namespace pinocchio
344
345
/* --- Details -------------------------------------------------------------------- */
346
#include "pinocchio/algorithm/frames.hxx"
347
348
#endif // ifndef __pinocchio_algorithm_frames_hpp__