GCC Code Coverage Report


Directory: ./
File: bindings/python/algorithm/expose-kinematics-derivatives.cpp
Date: 2025-04-30 16:14:33
Exec Total Coverage
Lines: 38 50 76.0%
Branches: 30 92 32.6%

Line Branch Exec Source
1 //
2 // Copyright (c) 2018-2021 CNRS INRIA
3 //
4 #include "pinocchio/bindings/python/algorithm/algorithms.hpp"
5 #include "pinocchio/algorithm/kinematics-derivatives.hpp"
6 #include "pinocchio/algorithm/center-of-mass-derivatives.hpp"
7
8 #include "pinocchio/bindings/python/utils/model-checker.hpp"
9
10 #include <boost/python/tuple.hpp>
11
12 namespace pinocchio
13 {
14 namespace python
15 {
16 namespace bp = boost::python;
17
18 5 bp::tuple getJointVelocityDerivatives_proxy(
19 const context::Model & model,
20 context::Data & data,
21 const JointIndex jointId,
22 ReferenceFrame rf)
23 {
24 typedef context::Data::Matrix6x Matrix6x;
25
26
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 Matrix6x partial_dq(Matrix6x::Zero(6, model.nv));
27
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 Matrix6x partial_dv(Matrix6x::Zero(6, model.nv));
28
29
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 getJointVelocityDerivatives(model, data, jointId, rf, partial_dq, partial_dv);
30
31
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
10 return bp::make_tuple(partial_dq, partial_dv);
32 5 }
33
34 bp::tuple getPointVelocityDerivatives_proxy(
35 const context::Model & model,
36 context::Data & data,
37 const JointIndex joint_id,
38 const context::SE3 & placement,
39 ReferenceFrame rf)
40 {
41 typedef context::Data::Matrix3x Matrix3x;
42
43 Matrix3x v_partial_dq(Matrix3x::Zero(3, model.nv));
44 Matrix3x v_partial_dv(Matrix3x::Zero(3, model.nv));
45
46 getPointVelocityDerivatives(model, data, joint_id, placement, rf, v_partial_dq, v_partial_dv);
47
48 return bp::make_tuple(v_partial_dq, v_partial_dv);
49 }
50
51 5 bp::tuple getJointAccelerationDerivatives_proxy(
52 const context::Model & model,
53 context::Data & data,
54 const JointIndex jointId,
55 ReferenceFrame rf)
56 {
57 typedef context::Data::Matrix6x Matrix6x;
58
59
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 Matrix6x v_partial_dq(Matrix6x::Zero(6, model.nv));
60
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 Matrix6x a_partial_dq(Matrix6x::Zero(6, model.nv));
61
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 Matrix6x a_partial_dv(Matrix6x::Zero(6, model.nv));
62
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 Matrix6x a_partial_da(Matrix6x::Zero(6, model.nv));
63
64
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 getJointAccelerationDerivatives(
65 model, data, jointId, rf, v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da);
66
67
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
10 return bp::make_tuple(v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da);
68 5 }
69
70 bp::tuple getPointClassicAccelerationDerivatives_proxy(
71 const context::Model & model,
72 context::Data & data,
73 const JointIndex joint_id,
74 const context::SE3 & placement,
75 ReferenceFrame rf)
76 {
77 typedef context::Data::Matrix3x Matrix3x;
78
79 Matrix3x v_partial_dq(Matrix3x::Zero(3, model.nv));
80 Matrix3x a_partial_dq(Matrix3x::Zero(3, model.nv));
81 Matrix3x a_partial_dv(Matrix3x::Zero(3, model.nv));
82 Matrix3x a_partial_da(Matrix3x::Zero(3, model.nv));
83
84 getPointClassicAccelerationDerivatives(
85 model, data, joint_id, placement, rf, v_partial_dq, a_partial_dq, a_partial_dv,
86 a_partial_da);
87
88 return bp::make_tuple(v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da);
89 }
90
91 context::Data::Matrix3x
92 1 getCoMVelocityDerivatives_proxy(const context::Model & model, context::Data & data)
93 {
94 typedef context::Data::Matrix3x Matrix3x;
95
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 Matrix3x partial_dq(Matrix3x::Zero(3, model.nv));
96
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 getCenterOfMassVelocityDerivatives(model, data, partial_dq);
97 1 return partial_dq;
98 }
99
100 72 void exposeKinematicsDerivatives()
101 {
102 typedef context::Scalar Scalar;
103 typedef context::VectorXs VectorXs;
104 enum
105 {
106 Options = context::Options
107 };
108
109
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
110 "computeForwardKinematicsDerivatives",
111 &computeForwardKinematicsDerivatives<
112 Scalar, Options, JointCollectionDefaultTpl, VectorXs, VectorXs, VectorXs>,
113
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
144 bp::args("model", "data", "q", "v", "a"),
114 "Computes all the terms required to compute the derivatives of the placement, "
115 "spatial velocity and acceleration\n"
116 "for any joint of the model.\n"
117 "The results are stored in data.\n\n"
118 "Parameters:\n"
119 "\tmodel: model of the kinematic tree\n"
120 "\tdata: data related to the model\n"
121 "\tq: the joint configuration vector (size model.nq)\n"
122 "\tv: the joint velocity vector (size model.nv)\n"
123 "\ta: the joint acceleration vector (size model.nv)\n",
124 72 mimic_not_supported_function<>(0));
125
126
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
127 "getJointVelocityDerivatives", getJointVelocityDerivatives_proxy,
128
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
144 bp::args("model", "data", "joint_id", "reference_frame"),
129 "Computes the partial derivatives of the spatial velocity of a given joint with respect "
130 "to\n"
131 "the joint configuration and velocity and returns them as a tuple.\n"
132 "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the "
133 "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of "
134 "reference_frame.\n"
135 "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n"
136 "Parameters:\n"
137 "\tmodel: model of the kinematic tree\n"
138 "\tdata: data related to the model\n"
139 "\tjoint_id: index of the joint\n"
140 "\treference_frame: reference frame in which the resulting derivatives are expressed\n",
141 72 mimic_not_supported_function<>(0));
142
143
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
144 "getPointVelocityDerivatives", getPointVelocityDerivatives_proxy,
145
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
144 bp::args("model", "data", "joint_id", "placement", "reference_frame"),
146 "Computes the partial derivatives of the velocity of a point given by its placement "
147 "information w.r.t. the joint frame and returns them as a tuple.\n"
148 "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the "
149 "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of "
150 "reference_frame.\n"
151 "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n"
152 "Parameters:\n"
153 "\tmodel: model of the kinematic tree\n"
154 "\tdata: data related to the model\n"
155 "\tjoint_id: index of the joint\n"
156 "\tplacement: relative placement of the point w.r.t. the joint frame\n"
157 "\treference_frame: reference frame in which the resulting derivatives are expressed\n",
158 72 mimic_not_supported_function<>(0));
159
160
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
161 "getPointClassicAccelerationDerivatives", getPointClassicAccelerationDerivatives_proxy,
162
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
144 bp::args("model", "data", "joint_id", "placement", "reference_frame"),
163 "Computes the partial derivatives of the classic acceleration of a point given by its "
164 "placement information w.r.t. the joint frame and returns them as a tuple.\n"
165 "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the "
166 "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of "
167 "reference_frame.\n"
168 "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n"
169 "Parameters:\n"
170 "\tmodel: model of the kinematic tree\n"
171 "\tdata: data related to the model\n"
172 "\tjoint_id: index of the joint\n"
173 "\tplacement: relative placement of the point w.r.t. the joint frame\n"
174 "\treference_frame: reference frame in which the resulting derivatives are expressed\n",
175 72 mimic_not_supported_function<>(0));
176
177
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
178 "getJointAccelerationDerivatives", getJointAccelerationDerivatives_proxy,
179
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
144 bp::args("model", "data", "joint_id", "reference_frame"),
180 "Computes the partial derivatives of the spatial acceleration of a given joint with "
181 "respect to\n"
182 "the joint configuration, velocity and acceleration and returns them as a tuple.\n"
183 "The partial derivatives can be either expressed in the LOCAL frame of the joint, in the "
184 "LOCAL_WORLD_ALIGNED frame or in the WORLD coordinate frame depending on the value of "
185 "reference_frame.\n"
186 "You must first call computeForwardKinematicsDerivatives before calling this function.\n\n"
187 "Parameters:\n"
188 "\tmodel: model of the kinematic tree\n"
189 "\tdata: data related to the model\n"
190 "\tjoint_id: index of the joint\n"
191 "\treference_frame: reference frame in which the resulting derivatives are expressed\n",
192 72 mimic_not_supported_function<>(0));
193
194
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
195 "getCenterOfMassVelocityDerivatives", getCoMVelocityDerivatives_proxy,
196
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
144 bp::args("model", "data"),
197 "Computes the partial derivaties of the center of mass velocity with respect to\n"
198 "the joint configuration.\n"
199 "You must first call computeAllTerms(model,data,q,v) or centerOfMass(model,data,q,v) "
200 "before calling this function.\n\n"
201 "Parameters:\n"
202 "\tmodel: model of the kinematic tree\n"
203 "\tdata: data related to the model\n",
204 72 mimic_not_supported_function<>(0));
205 72 }
206
207 } // namespace python
208 } // namespace pinocchio
209