Directory: | ./ |
---|---|
File: | include/pinocchio/algorithm/frames-derivatives.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 43 | 43 | 100.0% |
Branches: | 6 | 18 | 33.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2020 INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_algorithm_frames_derivatives_hpp__ | ||
6 | #define __pinocchio_algorithm_frames_derivatives_hpp__ | ||
7 | |||
8 | #include "pinocchio/multibody/model.hpp" | ||
9 | #include "pinocchio/multibody/data.hpp" | ||
10 | |||
11 | namespace pinocchio | ||
12 | { | ||
13 | |||
14 | /** | ||
15 | * @brief Computes the partial derivatives of the spatial velocity of a frame given by its | ||
16 | * relative placement, with respect to q and v. You must first call | ||
17 | * pinocchio::computeForwardKinematicsDerivatives to compute all the required quantities. | ||
18 | * | ||
19 | * @tparam JointCollection Collection of Joint types. | ||
20 | * @tparam Matrix6xOut1 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
21 | * with respect to the joint configuration vector. | ||
22 | * @tparam Matrix6xOut2 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
23 | * with respect to the joint velocity vector. | ||
24 | * | ||
25 | * @param[in] model The kinematic model | ||
26 | * @param[in] data Data associated to model | ||
27 | * @param[in] joint_id Index of the supporting joint | ||
28 | * @param[in] placement Placement of the Frame w.r.t. the joint frame. | ||
29 | * @param[in] rf Reference frame in which the velocity is expressed. | ||
30 | * @param[out] v_partial_dq Partial derivative of the frame spatial velocity w.r.t. \f$ q \f$. | ||
31 | * @param[out] v_partial_dv Partial derivative of the frame spatial velociy w.r.t. \f$ v \f$. | ||
32 | * | ||
33 | */ | ||
34 | template< | ||
35 | typename Scalar, | ||
36 | int Options, | ||
37 | template<typename, int> class JointCollectionTpl, | ||
38 | typename Matrix6xOut1, | ||
39 | typename Matrix6xOut2> | ||
40 | void getFrameVelocityDerivatives( | ||
41 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
42 | const DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
43 | const JointIndex joint_id, | ||
44 | const SE3Tpl<Scalar, Options> & placement, | ||
45 | const ReferenceFrame rf, | ||
46 | const Eigen::MatrixBase<Matrix6xOut1> & v_partial_dq, | ||
47 | const Eigen::MatrixBase<Matrix6xOut2> & v_partial_dv); | ||
48 | |||
49 | /** | ||
50 | * @brief Computes the partial derivatives of the frame spatial velocity with respect to q | ||
51 | * and v. You must first call pinocchio::computeForwardKinematicsDerivatives to compute all the | ||
52 | * required quantities. | ||
53 | * | ||
54 | * @tparam JointCollection Collection of Joint types. | ||
55 | * @tparam Matrix6xOut1 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
56 | * with respect to the joint configuration vector. | ||
57 | * @tparam Matrix6xOut2 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
58 | * with respect to the joint velocity vector. | ||
59 | * | ||
60 | * @param[in] model The kinematic model | ||
61 | * @param[in] data Data associated to model | ||
62 | * @param[in] frame_id Id of the operational Frame | ||
63 | * @param[in] rf Reference frame in which the velocity is expressed. | ||
64 | * @param[out] v_partial_dq Partial derivative of the frame spatial velocity w.r.t. \f$ q \f$. | ||
65 | * @param[out] v_partial_dv Partial derivative of the frame spatial velociy w.r.t. \f$ v \f$. | ||
66 | * | ||
67 | */ | ||
68 | template< | ||
69 | typename Scalar, | ||
70 | int Options, | ||
71 | template<typename, int> class JointCollectionTpl, | ||
72 | typename Matrix6xOut1, | ||
73 | typename Matrix6xOut2> | ||
74 | 9 | void getFrameVelocityDerivatives( | |
75 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
76 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
77 | const FrameIndex frame_id, | ||
78 | const ReferenceFrame rf, | ||
79 | const Eigen::MatrixBase<Matrix6xOut1> & v_partial_dq, | ||
80 | const Eigen::MatrixBase<Matrix6xOut2> & v_partial_dv) | ||
81 | { | ||
82 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9 | PINOCCHIO_CHECK_INPUT_ARGUMENT((int)frame_id < model.nframes, "The frame_id is not valid."); |
83 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
84 | typedef DataTpl<Scalar, Options, JointCollectionTpl> Data; | ||
85 | typedef typename Model::Frame Frame; | ||
86 | |||
87 | 9 | const Frame & frame = model.frames[frame_id]; | |
88 | 9 | typename Data::SE3 & oMframe = data.oMf[frame_id]; | |
89 |
1/2✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
|
9 | oMframe = data.oMi[frame.parentJoint] * frame.placement; // for backward compatibility |
90 | 9 | getFrameVelocityDerivatives( | |
91 | 9 | model, data, frame.parentJoint, frame.placement, rf, | |
92 | 9 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut1, v_partial_dq), | |
93 | 9 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut1, v_partial_dv)); | |
94 | 9 | } | |
95 | |||
96 | /** | ||
97 | * @brief Computes the partial derivatives of the spatial acceleration of a frame given by | ||
98 | * its relative placement, with respect to q, v and a. You must first call | ||
99 | * pinocchio::computeForwardKinematicsDerivatives to compute all the required quantities. It is | ||
100 | * important to notice that a direct outcome (for free) of this algo is v_partial_dq and | ||
101 | * v_partial_dv which is equal to a_partial_da. | ||
102 | * | ||
103 | * @tparam JointCollection Collection of Joint types. | ||
104 | * @tparam Matrix6xOut1 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
105 | * with respect to the joint configuration vector. | ||
106 | * @tparam Matrix6xOut2 Matrix6x containing the partial derivatives of the frame spatial | ||
107 | * acceleration with respect to the joint configuration vector. | ||
108 | * @tparam Matrix6xOut3 Matrix6x containing the partial derivatives of the frame spatial | ||
109 | * acceleration with respect to the joint velocity vector. | ||
110 | * @tparam Matrix6xOut4 Matrix6x containing the partial derivatives of the frame spatial | ||
111 | * acceleration with respect to the joint acceleration vector. | ||
112 | * | ||
113 | * @param[in] model The kinematic model | ||
114 | * @param[in] data Data associated to model | ||
115 | * @param[in] joint_id Index of the supporting joint | ||
116 | * @param[in] placement Placement of the Frame w.r.t. the joint frame. | ||
117 | * @param[in] rf Reference frame in which the velocity is expressed. | ||
118 | * @param[out] v_partial_dq Partial derivative of the frame spatial velocity w.r.t. \f$ q \f$. | ||
119 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ q | ||
120 | * \f$. | ||
121 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ v | ||
122 | * \f$. | ||
123 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ | ||
124 | * \dot{v} \f$. | ||
125 | * | ||
126 | */ | ||
127 | template< | ||
128 | typename Scalar, | ||
129 | int Options, | ||
130 | template<typename, int> class JointCollectionTpl, | ||
131 | typename Matrix6xOut1, | ||
132 | typename Matrix6xOut2, | ||
133 | typename Matrix6xOut3, | ||
134 | typename Matrix6xOut4> | ||
135 | void getFrameAccelerationDerivatives( | ||
136 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
137 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
138 | const JointIndex joint_id, | ||
139 | const SE3Tpl<Scalar, Options> & placement, | ||
140 | const ReferenceFrame rf, | ||
141 | const Eigen::MatrixBase<Matrix6xOut1> & v_partial_dq, | ||
142 | const Eigen::MatrixBase<Matrix6xOut2> & a_partial_dq, | ||
143 | const Eigen::MatrixBase<Matrix6xOut3> & a_partial_dv, | ||
144 | const Eigen::MatrixBase<Matrix6xOut4> & a_partial_da); | ||
145 | |||
146 | /** | ||
147 | * @brief Computes the partial derivatives of the frame acceleration quantity with respect to | ||
148 | * q, v and a. You must first call pinocchio::computeForwardKinematicsDerivatives to compute all | ||
149 | * the required quantities. It is important to notice that a direct outcome (for free) of this | ||
150 | * algo is v_partial_dq and v_partial_dv which is equal to a_partial_da. | ||
151 | * | ||
152 | * @tparam JointCollection Collection of Joint types. | ||
153 | * @tparam Matrix6xOut1 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
154 | * with respect to the joint configuration vector. | ||
155 | * @tparam Matrix6xOut2 Matrix6x containing the partial derivatives of the frame spatial | ||
156 | * acceleration with respect to the joint configuration vector. | ||
157 | * @tparam Matrix6xOut3 Matrix6x containing the partial derivatives of the frame spatial | ||
158 | * acceleration with respect to the joint velocity vector. | ||
159 | * @tparam Matrix6xOut4 Matrix6x containing the partial derivatives of the frame spatial | ||
160 | * acceleration with respect to the joint acceleration vector. | ||
161 | * | ||
162 | * @param[in] model The kinematic model | ||
163 | * @param[in] data Data associated to model | ||
164 | * @param[in] frame_id Id of the operational Frame | ||
165 | * @param[in] rf Reference frame in which the velocity is expressed. | ||
166 | * @param[out] v_partial_dq Partial derivative of the frame spatial velocity w.r.t. \f$ q \f$. | ||
167 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ q \f$. | ||
168 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ v \f$. | ||
169 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ | ||
170 | * \dot{v} \f$. | ||
171 | * | ||
172 | */ | ||
173 | template< | ||
174 | typename Scalar, | ||
175 | int Options, | ||
176 | template<typename, int> class JointCollectionTpl, | ||
177 | typename Matrix6xOut1, | ||
178 | typename Matrix6xOut2, | ||
179 | typename Matrix6xOut3, | ||
180 | typename Matrix6xOut4> | ||
181 | 9 | void getFrameAccelerationDerivatives( | |
182 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
183 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
184 | const FrameIndex frame_id, | ||
185 | const ReferenceFrame rf, | ||
186 | const Eigen::MatrixBase<Matrix6xOut1> & v_partial_dq, | ||
187 | const Eigen::MatrixBase<Matrix6xOut2> & a_partial_dq, | ||
188 | const Eigen::MatrixBase<Matrix6xOut3> & a_partial_dv, | ||
189 | const Eigen::MatrixBase<Matrix6xOut4> & a_partial_da) | ||
190 | { | ||
191 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9 | PINOCCHIO_CHECK_INPUT_ARGUMENT((int)frame_id < model.nframes, "The frame_id is not valid."); |
192 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
193 | typedef DataTpl<Scalar, Options, JointCollectionTpl> Data; | ||
194 | typedef typename Model::Frame Frame; | ||
195 | |||
196 | 9 | const Frame & frame = model.frames[frame_id]; | |
197 | 9 | typename Data::SE3 & oMframe = data.oMf[frame_id]; | |
198 |
1/2✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
|
9 | oMframe = data.oMi[frame.parentJoint] * frame.placement; // for backward compatibility |
199 | 9 | getFrameAccelerationDerivatives( | |
200 | 9 | model, data, frame.parentJoint, frame.placement, rf, | |
201 | 9 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut1, v_partial_dq), | |
202 | 9 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut2, a_partial_dq), | |
203 | 9 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut3, a_partial_dv), | |
204 | 9 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut4, a_partial_da)); | |
205 | 9 | } | |
206 | |||
207 | /** | ||
208 | * @brief Computes the partial derivatives of the frame acceleration quantity with respect to | ||
209 | * q, v and a. You must first call pinocchio::computeForwardKinematicsDerivatives to compute all | ||
210 | * the required quantities. It is important to notice that a direct outcome (for free) of this | ||
211 | * algo is v_partial_dq and v_partial_dv which is equal to a_partial_da. | ||
212 | * | ||
213 | * @tparam JointCollection Collection of Joint types. | ||
214 | * @tparam Matrix6xOut1 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
215 | * with respect to the joint configuration vector. | ||
216 | * @tparam Matrix6xOut2 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
217 | * with respect to the joint velocity vector. | ||
218 | * @tparam Matrix6xOut3 Matrix6x containing the partial derivatives of the frame spatial | ||
219 | * acceleration with respect to the joint configuration vector. | ||
220 | * @tparam Matrix6xOut4 Matrix6x containing the partial derivatives of the frame spatial | ||
221 | * acceleration with respect to the joint velocity vector. | ||
222 | * @tparam Matrix6xOut5 Matrix6x containing the partial derivatives of the frame spatial | ||
223 | * acceleration with respect to the joint acceleration vector. | ||
224 | * | ||
225 | * @param[in] model The kinematic model | ||
226 | * @param[in] data Data associated to model | ||
227 | * @param[in] joint_id Index of the supporting joint | ||
228 | * @param[in] placement Placement of the Frame w.r.t. the joint frame. | ||
229 | * @param[in] rf Reference frame in which the velocity is expressed. | ||
230 | * @param[out] v_partial_dq Partial derivative of the frame spatial velocity w.r.t. \f$ q \f$. | ||
231 | * @param[out] v_partial_dv Partial derivative of the frame spatial velociy w.r.t. \f$ v \f$. | ||
232 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ q | ||
233 | * \f$. | ||
234 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ v | ||
235 | * \f$. | ||
236 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ | ||
237 | * \dot{v} \f$. | ||
238 | * | ||
239 | */ | ||
240 | template< | ||
241 | typename Scalar, | ||
242 | int Options, | ||
243 | template<typename, int> class JointCollectionTpl, | ||
244 | typename Matrix6xOut1, | ||
245 | typename Matrix6xOut2, | ||
246 | typename Matrix6xOut3, | ||
247 | typename Matrix6xOut4, | ||
248 | typename Matrix6xOut5> | ||
249 | 3 | void getFrameAccelerationDerivatives( | |
250 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
251 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
252 | const JointIndex joint_id, | ||
253 | const SE3Tpl<Scalar, Options> & placement, | ||
254 | const ReferenceFrame rf, | ||
255 | const Eigen::MatrixBase<Matrix6xOut1> & v_partial_dq, | ||
256 | const Eigen::MatrixBase<Matrix6xOut2> & v_partial_dv, | ||
257 | const Eigen::MatrixBase<Matrix6xOut3> & a_partial_dq, | ||
258 | const Eigen::MatrixBase<Matrix6xOut4> & a_partial_dv, | ||
259 | const Eigen::MatrixBase<Matrix6xOut5> & a_partial_da) | ||
260 | { | ||
261 | 3 | getFrameAccelerationDerivatives( | |
262 | 3 | model, data, joint_id, placement, rf, PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut1, v_partial_dq), | |
263 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut3, a_partial_dq), | |
264 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut4, a_partial_dv), | |
265 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut5, a_partial_da)); | |
266 | |||
267 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut2, v_partial_dv) = a_partial_da; | |
268 | 3 | } | |
269 | |||
270 | /** | ||
271 | * @brief Computes the partial derivatives of the frame acceleration quantity with respect to | ||
272 | * q, v and a. You must first call pinocchio::computeForwardKinematicsDerivatives to compute all | ||
273 | * the required quantities. It is important to notice that a direct outcome (for free) of this | ||
274 | * algo is v_partial_dq and v_partial_dv which is equal to a_partial_da. | ||
275 | * | ||
276 | * @tparam JointCollection Collection of Joint types. | ||
277 | * @tparam Matrix6xOut1 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
278 | * with respect to the joint configuration vector. | ||
279 | * @tparam Matrix6xOut2 Matrix6x containing the partial derivatives of the frame spatial velocity | ||
280 | * with respect to the joint velocity vector. | ||
281 | * @tparam Matrix6xOut3 Matrix6x containing the partial derivatives of the frame spatial | ||
282 | * acceleration with respect to the joint configuration vector. | ||
283 | * @tparam Matrix6xOut4 Matrix6x containing the partial derivatives of the frame spatial | ||
284 | * acceleration with respect to the joint velocity vector. | ||
285 | * @tparam Matrix6xOut5 Matrix6x containing the partial derivatives of the frame spatial | ||
286 | * acceleration with respect to the joint acceleration vector. | ||
287 | * | ||
288 | * @param[in] model The kinematic model | ||
289 | * @param[in] data Data associated to model | ||
290 | * @param[in] frame_id Id of the operational Frame | ||
291 | * @param[in] rf Reference frame in which the velocity is expressed. | ||
292 | * @param[out] v_partial_dq Partial derivative of the frame spatial velocity w.r.t. \f$ q \f$. | ||
293 | * @param[out] v_partial_dv Partial derivative of the frame spatial velociy w.r.t. \f$ v \f$. | ||
294 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ q \f$. | ||
295 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ v \f$. | ||
296 | * @param[out] a_partial_dq Partial derivative of the frame spatial acceleration w.r.t. \f$ | ||
297 | * \dot{v} \f$. | ||
298 | * | ||
299 | */ | ||
300 | template< | ||
301 | typename Scalar, | ||
302 | int Options, | ||
303 | template<typename, int> class JointCollectionTpl, | ||
304 | typename Matrix6xOut1, | ||
305 | typename Matrix6xOut2, | ||
306 | typename Matrix6xOut3, | ||
307 | typename Matrix6xOut4, | ||
308 | typename Matrix6xOut5> | ||
309 | 3 | void getFrameAccelerationDerivatives( | |
310 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
311 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
312 | const FrameIndex frame_id, | ||
313 | const ReferenceFrame rf, | ||
314 | const Eigen::MatrixBase<Matrix6xOut1> & v_partial_dq, | ||
315 | const Eigen::MatrixBase<Matrix6xOut2> & v_partial_dv, | ||
316 | const Eigen::MatrixBase<Matrix6xOut3> & a_partial_dq, | ||
317 | const Eigen::MatrixBase<Matrix6xOut4> & a_partial_dv, | ||
318 | const Eigen::MatrixBase<Matrix6xOut5> & a_partial_da) | ||
319 | { | ||
320 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
3 | PINOCCHIO_CHECK_INPUT_ARGUMENT((int)frame_id < model.nframes, "The frame_id is not valid."); |
321 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
322 | typedef DataTpl<Scalar, Options, JointCollectionTpl> Data; | ||
323 | typedef typename Model::Frame Frame; | ||
324 | |||
325 | 3 | const Frame & frame = model.frames[frame_id]; | |
326 | 3 | typename Data::SE3 & oMframe = data.oMf[frame_id]; | |
327 |
1/2✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
3 | oMframe = data.oMi[frame.parentJoint] * frame.placement; // for backward compatibility |
328 | 3 | getFrameAccelerationDerivatives( | |
329 | 3 | model, data, frame.parentJoint, frame.placement, rf, | |
330 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut1, v_partial_dq), | |
331 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut2, v_partial_dv), | |
332 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut3, a_partial_dq), | |
333 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut4, a_partial_dv), | |
334 | 3 | PINOCCHIO_EIGEN_CONST_CAST(Matrix6xOut5, a_partial_da)); | |
335 | 3 | } | |
336 | } // namespace pinocchio | ||
337 | |||
338 | #include "pinocchio/algorithm/frames-derivatives.hxx" | ||
339 | |||
340 | #if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION | ||
341 | #include "pinocchio/algorithm/frames-derivatives.txx" | ||
342 | #endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION | ||
343 | |||
344 | #endif // ifndef __pinocchio_algorithm_frames_derivatives_hpp__ | ||
345 |