GCC Code Coverage Report


Directory: ./
File: include/pinocchio/algorithm/jacobian.hpp
Date: 2025-02-12 21:03:38
Exec Total Coverage
Lines: 4 4 100.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2015-2020 CNRS INRIA
3 //
4
5 #ifndef __pinocchio_algorithm_jacobian_hpp__
6 #define __pinocchio_algorithm_jacobian_hpp__
7
8 #include "pinocchio/multibody/model.hpp"
9 #include "pinocchio/multibody/data.hpp"
10
11 namespace pinocchio
12 {
13 ///
14 /// \brief Computes the full model Jacobian, i.e. the stack of all motion subspace expressed in
15 /// the world frame.
16 /// The result is accessible through data.J. This function computes also the
17 /// forwardKinematics of the model.
18 ///
19 /// \note This Jacobian does not correspond to any specific joint frame Jacobian. From this
20 /// Jacobian, it is then possible to easily extract the Jacobian of a specific joint frame. \sa
21 /// pinocchio::getJointJacobian for doing this specific extraction.
22 ///
23 /// \tparam JointCollection Collection of Joint types.
24 /// \tparam ConfigVectorType Type of the joint configuration vector.
25 ///
26 /// \param[in] model The model structure of the rigid body system.
27 /// \param[in] data The data structure of the rigid body system.
28 /// \param[in] q The joint configuration vector (dim model.nq).
29 ///
30 /// \return The full model Jacobian (matrix 6 x model.nv).
31 ///
32 template<
33 typename Scalar,
34 int Options,
35 template<typename, int> class JointCollectionTpl,
36 typename ConfigVectorType>
37 const typename DataTpl<Scalar, Options, JointCollectionTpl>::Matrix6x & computeJointJacobians(
38 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
39 DataTpl<Scalar, Options, JointCollectionTpl> & data,
40 const Eigen::MatrixBase<ConfigVectorType> & q);
41
42 ///
43 /// \brief Computes the full model Jacobian, i.e. the stack of all motion subspace expressed in
44 /// the world frame.
45 /// The result is accessible through data.J. This function assumes that
46 /// pinocchio::forwardKinematics has been called before.
47 ///
48 /// \note This Jacobian does not correspond to any specific joint frame Jacobian. From this
49 /// Jacobian, it is then possible to easily extract the Jacobian of a specific joint frame. \sa
50 /// pinocchio::getJointJacobian for doing this specific extraction.
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 ///
57 /// \return The full model Jacobian (matrix 6 x model.nv).
58 ///
59 template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
60 const typename DataTpl<Scalar, Options, JointCollectionTpl>::Matrix6x & computeJointJacobians(
61 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
62 DataTpl<Scalar, Options, JointCollectionTpl> & data);
63
64 /// \brief Computes the Jacobian of a specific joint frame expressed in one of the
65 /// pinocchio::ReferenceFrame options.
66 ///
67 /// \details For the LOCAL reference frame, the Jacobian \f${}^j J_{0j}\f$ from the joint frame
68 /// \f$j\f$ to the world frame \f$0\f$ is such that \f${}^j v_{0j} = {}^j J_{0j} \dot{q}\f$, where
69 /// \f${}^j v_{0j}\f$ is the velocity of the origin of the moving joint frame relative to the
70 /// fixed world frame, projected into the basis of the joint frame. LOCAL_WORLD_ALIGNED is the
71 /// same velocity but projected into the world frame basis.
72 ///
73 /// For the WORLD reference frame, the Jacobian \f${}^0 J_{0j}\f$ from the joint frame \f$j\f$ to
74 /// the world frame \f$0\f$ is such that \f${}^0 v_{0j} = {}^0 J_{0j} \dot{q}\f$, where \f${}^0
75 /// v_{0j}\f$ is the spatial velocity of the joint frame. The linear component of this spatial
76 /// velocity is the velocity of a (possibly imaginary) point attached to the moving joint frame j
77 /// which is traveling through the origin of the world frame at that instant. The angular
78 /// component is the instantaneous angular velocity of the joint frame as viewed in the world
79 /// frame.
80 ///
81 /// When serialized to a 6D vector, the order of coordinates is: three linear followed by three
82 /// angular.
83 ///
84 /// For further details regarding the different velocities or the Jacobian see Chapters 2 and 3
85 /// respectively in [A Mathematical Introduction to Robotic
86 /// Manipulation](https://www.cse.lehigh.edu/~trink/Courses/RoboticsII/reading/murray-li-sastry-94-complete.pdf)
87 /// by Murray, Li and Sastry.
88 ///
89 /// \note This jacobian is extracted from data.J. You have to run pinocchio::computeJointJacobians
90 /// before calling it.
91 ///
92 /// \tparam JointCollection Collection of Joint types.
93 /// \tparam Matrix6xLike Type of the matrix containing the joint Jacobian.
94 ///
95 /// \param[in] model The model structure of the rigid body system.
96 /// \param[in] data The data structure of the rigid body system.
97 /// \param[in] joint_id The id of the joint.
98 /// \param[in] reference_frame Reference frame in which the result is expressed.
99 /// \param[out] J A reference on the Jacobian matrix where the results will be stored in (dim 6 x
100 /// model.nv). You must fill J with zero elements, e.g. J.fill(0.).
101 ///
102 template<
103 typename Scalar,
104 int Options,
105 template<typename, int> class JointCollectionTpl,
106 typename Matrix6Like>
107 void getJointJacobian(
108 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
109 const DataTpl<Scalar, Options, JointCollectionTpl> & data,
110 const JointIndex joint_id,
111 const ReferenceFrame reference_frame,
112 const Eigen::MatrixBase<Matrix6Like> & J);
113 ///
114 /// \brief Computes the Jacobian of a specific joint frame expressed either in the world (rf =
115 /// WORLD) frame, in the local world aligned (rf = LOCAL_WORLD_ALIGNED) frame or in the local
116 /// frame (rf = LOCAL) of the joint. \note This jacobian is extracted from data.J. You have to run
117 /// pinocchio::computeJointJacobians before calling it.
118 ///
119 /// \tparam JointCollection Collection of Joint types.
120 ///
121 /// \param[in] model The model structure of the rigid body system.
122 /// \param[in] data The data structure of the rigid body system.
123 /// \param[in] joint_id The index of the joint.
124 /// \param[in] reference_frame Reference frame in which the result is expressed.
125 ///
126 template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
127 9 Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> getJointJacobian(
128 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
129 const DataTpl<Scalar, Options, JointCollectionTpl> & data,
130 const JointIndex joint_id,
131 const ReferenceFrame reference_frame)
132 {
133 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> ReturnType;
134
1/2
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 ReturnType res(ReturnType::Zero(6, model.nv));
135
136
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 getJointJacobian(model, data, joint_id, reference_frame, res);
137 9 return res;
138 }
139
140 ///
141 /// \brief Computes the Jacobian of a specific joint frame expressed in the local frame of the
142 /// joint and store the result in the input argument J.
143 ///
144 /// \tparam JointCollection Collection of Joint types.
145 /// \tparam ConfigVectorType Type of the joint configuration vector.
146 /// \tparam Matrix6xLike Type of the matrix containing the joint Jacobian.
147 ///
148 /// \param[in] model The model structure of the rigid body system.
149 /// \param[in] data The data structure of the rigid body system.
150 /// \param[in] q The joint configuration vector (dim model.nq).
151 /// \param[in] joint_id The id of the joint refering to model.joints[jointId].
152 /// \param[out] J A reference on the Jacobian matrix where the results will be stored in (dim 6 x
153 /// model.nv). You must fill J with zero elements, e.g. J.setZero().
154 ///
155 /// \return The Jacobian of the specific joint frame expressed in the local frame of the joint
156 /// (matrix 6 x model.nv).
157 ///
158 /// \remarks The result of this function is equivalent to call first
159 /// computeJointJacobians(model,data,q) and then call
160 /// getJointJacobian(model,data,jointId,LOCAL,J),
161 /// but forwardKinematics is not fully computed.
162 /// It is worth to call jacobian if you only need a single Jacobian for a specific joint.
163 /// Otherwise, for several Jacobians, it is better to call
164 /// computeJointJacobians(model,data,q) followed by
165 /// getJointJacobian(model,data,jointId,LOCAL,J) for each Jacobian.
166 ///
167 template<
168 typename Scalar,
169 int Options,
170 template<typename, int> class JointCollectionTpl,
171 typename ConfigVectorType,
172 typename Matrix6Like>
173 void computeJointJacobian(
174 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
175 DataTpl<Scalar, Options, JointCollectionTpl> & data,
176 const Eigen::MatrixBase<ConfigVectorType> & q,
177 const JointIndex joint_id,
178 const Eigen::MatrixBase<Matrix6Like> & J);
179
180 ///
181 /// \brief Computes the full model Jacobian variations with respect to time. It corresponds to
182 /// dJ/dt which depends both on q and v.
183 /// The result is accessible through data.dJ.
184 ///
185 /// \tparam JointCollection Collection of Joint types.
186 /// \tparam ConfigVectorType Type of the joint configuration vector.
187 /// \tparam TangentVectorType Type of the joint velocity vector.
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[in] q The joint configuration vector (dim model.nq).
192 /// \param[in] v The joint velocity vector (dim model.nv).
193 ///
194 /// \return The full model Jacobian (matrix 6 x model.nv).
195 ///
196 template<
197 typename Scalar,
198 int Options,
199 template<typename, int> class JointCollectionTpl,
200 typename ConfigVectorType,
201 typename TangentVectorType>
202 const typename DataTpl<Scalar, Options, JointCollectionTpl>::Matrix6x &
203 computeJointJacobiansTimeVariation(
204 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
205 DataTpl<Scalar, Options, JointCollectionTpl> & data,
206 const Eigen::MatrixBase<ConfigVectorType> & q,
207 const Eigen::MatrixBase<TangentVectorType> & v);
208
209 ///
210 /// \brief Computes the Jacobian time variation of a specific joint frame expressed either in the
211 /// world frame (rf = WORLD), in the local world aligned (rf = LOCAL_WORLD_ALIGNED) frame or in
212 /// the local frame (rf = LOCAL) of the joint. \note This jacobian is extracted from data.dJ. You
213 /// have to run pinocchio::computeJointJacobiansTimeVariation before calling it.
214 ///
215 /// \tparam JointCollection Collection of Joint types.
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] joint_id The id of the joint.
221 /// \param[in] reference_frame Reference frame in which the result is expressed.
222 /// \param[out] dJ A reference on the Jacobian matrix where the results will be stored in (dim 6 x
223 /// model.nv). You must fill dJ with zero elements, e.g. dJ.fill(0.).
224 ///
225 template<
226 typename Scalar,
227 int Options,
228 template<typename, int> class JointCollectionTpl,
229 typename Matrix6Like>
230 void getJointJacobianTimeVariation(
231 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
232 const DataTpl<Scalar, Options, JointCollectionTpl> & data,
233 const JointIndex joint_id,
234 const ReferenceFrame reference_frame,
235 const Eigen::MatrixBase<Matrix6Like> & dJ);
236
237 } // namespace pinocchio
238
239 /* --- Details -------------------------------------------------------------------- */
240 /* --- Details -------------------------------------------------------------------- */
241 /* --- Details -------------------------------------------------------------------- */
242
243 #include "pinocchio/algorithm/jacobian.hxx"
244
245 #if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
246 #include "pinocchio/algorithm/jacobian.txx"
247 #endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
248
249 #endif // ifndef __pinocchio_algorithm_jacobian_hpp__
250