Skip to content

Commit 1c1f96b

Browse files
author
ipuch
committed
precommit
precommit again
1 parent d517b8d commit 1c1f96b

File tree

3 files changed

+77
-139
lines changed

3 files changed

+77
-139
lines changed

examples/ellipsoid-joint-kinematics.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
- The position on the ellipsoid surface
66
- The orientation of the body
77
8-
Note: the joint is not purely normal to the ellipsoid surface; it translates along a ellipsoid,
9-
but the rotational part is "normal" to a sphere.
8+
Note: the joint is not purely normal to the ellipsoid surface;
9+
it translates along a ellipsoid, but the rotational part is "normal" to a sphere.
1010
"""
1111

12-
import pinocchio as pin
1312
import numpy as np
13+
import pinocchio as pin
1414

1515
# For visualization (optional)
1616
try:
@@ -107,7 +107,7 @@ def compute_kinematics_example():
107107
model = create_ellipsoid_robot(radius_a, radius_b, radius_c)
108108
data = model.createData()
109109

110-
print(f"\nEllipsoid parameters:")
110+
print("\nEllipsoid parameters:")
111111
print(f" radius_a (x-axis): {radius_a}")
112112
print(f" radius_b (y-axis): {radius_b}")
113113
print(f" radius_c (z-axis): {radius_c}")
@@ -163,7 +163,8 @@ def compute_dynamics_example():
163163
print(f"Acceleration: a = {a}")
164164

165165
# Compute dynamics with RNEA (Recursive Newton-Euler Algorithm)
166-
# Important Note: the generalized forces dimension matches the number of DOFs (3 for ellipsoid joint)
166+
# Important Note:
167+
# the generalized forces dimension matches the number of DOFs
167168
# but they are not pure torques due to the joint's nature and because the last
168169
# The last step of rnea is tau = S.T * f
169170
# where S is the joint motion subspace, and f the spatial force of the joint
@@ -172,7 +173,9 @@ def compute_dynamics_example():
172173
tau = pin.rnea(model, data, q, v, a)
173174
print(f"\nRequired torques (RNEA): τ = {tau}")
174175

175-
# For example tau[0] is a combination of S_11(q)* f_x + S_21(q)* f_y + S_31(q)* f_z + S_41(q)* τ_x + S_51(q)* τ_y + S_61(q)* τ_z
176+
# For example tau[0] is a combination of
177+
# S_11(q)* f_x + S_21(q)* f_y + S_31(q)* f_z
178+
# + S_41(q)* τ_x + S_51(q)* τ_y + S_61(q)* τ_z
176179

177180
# Create composite model for comparison of joint spatial forces `data.f[1]`
178181
composite_model = create_composite_model()
@@ -196,7 +199,7 @@ def compute_dynamics_example():
196199
composite_model, composite_data, q_composite, v_composite, a_composite
197200
)
198201
print(f"\nComposite joint required torques (RNEA): τ = {tau_composite}")
199-
print(f"\nComparison of spatial forces at the joint:")
202+
print("\nComparison of spatial forces at the joint:")
200203
print(f" - Ellipsoid joint spatial force: f = {data.f[1]} ")
201204
print(f" - Composite joint spatial force: f = {composite_data.f[1]} ")
202205

@@ -296,7 +299,8 @@ def visualize_ellipsoid_motion():
296299

297300
if i % 50 == 0:
298301
print(
299-
f" Frame {i}/500 - Configuration: [{q[0]:.3f}, {q[1]:.3f}, {q[2]:.3f}]"
302+
f" Frame {i}/500 - Configuration: \n"
303+
f" [{q[0]:.3f}, {q[1]:.3f}, {q[2]:.3f}]"
300304
)
301305

302306
# create extra motion that slides along the principal axes q0

include/pinocchio/multibody/joint/joint-ellipsoid.hpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ namespace pinocchio
7272
///
7373
/// The configuration space uses three angles (q₀, q₁, q₂) representing:
7474
/// - Rotation about the x-axis
75-
/// - Rotation about the y-axis
75+
/// - Rotation about the y-axis
7676
/// - Spin about the "normal" direction
7777
///
7878
/// The joint position on the ellipsoid surface is computed as:
7979
/// \f$ \mathbf{p} = (a \sin q_1, -b \sin q_0 \cos q_1, c \cos q_0 \cos q_1) \f$
8080
///
8181
/// where \f$ a, b, c \f$ are the radii along the x, y, z axes respectively.
8282
///
83-
/// \note For non-spherical ellipsoids, the third rotation axis is only approximately
83+
/// \note For non-spherical ellipsoids, the third rotation axis is only approximately
8484
/// normal to the surface. It corresponds to the normal of an equivalent sphere while
8585
/// the translation follows the true ellipsoid surface. The "normal" direction is
8686
/// truly normal only when all radii are equal (sphere case).
@@ -159,7 +159,7 @@ namespace pinocchio
159159
{
160160
return JointDataDerived();
161161
}
162-
162+
163163
/// @brief Default constructor. Creates a sphere (0.01, 0.01, 0.01).
164164
JointModelEllipsoidTpl()
165165
: radius_a(Scalar(0.01))
@@ -195,11 +195,12 @@ namespace pinocchio
195195
/// @param[in] c2, s2 Cosine and sine of q[2]
196196
/// @param[out] data Joint data where M will be stored
197197
void computeSpatialTransform(
198-
Scalar c0, Scalar s0, Scalar c1, Scalar s1, Scalar c2, Scalar s2, JointDataDerived & data) const
198+
Scalar c0, Scalar s0, Scalar c1, Scalar s1, Scalar c2, Scalar s2, JointDataDerived & data)
199+
const
199200
{
200201
// clang-format off
201202
data.M.rotation() << c1 * c2 , -c1 * s2 , s1 ,
202-
c0 * s2 + c2 * s0 * s1 , c0 * c2 - s0 * s1 * s2 ,-c1 * s0 ,
203+
c0 * s2 + c2 * s0 * s1 , c0 * c2 - s0 * s1 * s2 ,-c1 * s0 ,
203204
-c0 * c2 * s1 + s0 * s2 , c0 * s1 * s2 + c2 * s0 , c0 * c1;
204205
// clang-format on
205206
Scalar nx, ny, nz;
@@ -208,7 +209,6 @@ namespace pinocchio
208209
nz = c0 * c1;
209210

210211
data.M.translation() << radius_a * nx, radius_b * ny, radius_c * nz;
211-
212212
}
213213

214214
template<typename ConfigVector>
@@ -223,7 +223,7 @@ namespace pinocchio
223223
Scalar c2, s2;
224224
SINCOS(data.joint_q(2), &s2, &c2);
225225

226-
computeSpatialTransform(c0,s0,c1,s1,c2,s2, data);
226+
computeSpatialTransform(c0, s0, c1, s1, c2, s2, data);
227227

228228
computeMotionSubspace(s0, c0, s1, c1, s2, c2, data);
229229
}
@@ -278,7 +278,7 @@ namespace pinocchio
278278
SINCOS(data.joint_q(2), &s2, &c2);
279279

280280
computeSpatialTransform(c0, s0, c1, s1, c2, s2, data);
281-
281+
282282
Scalar dndotx_dqdot1, dndoty_dqdot0, dndoty_dqdot1, dndotz_dqdot0, dndotz_dqdot1;
283283
dndotx_dqdot1 = c1;
284284
dndoty_dqdot0 = -c0 * c1;
@@ -392,15 +392,15 @@ namespace pinocchio
392392
S_32 = dndotx_dqdot1 * radius_a * s1 - dndoty_dqdot1 * radius_b * c1 * s0
393393
+ dndotz_dqdot1 * radius_c * c0 * c1;
394394

395-
data.S.matrix() << S_11 , S_12 , Scalar(0),
396-
S_21 , S_22 , Scalar(0),
395+
data.S.matrix() << S_11 , S_12 , Scalar(0),
396+
S_21 , S_22 , Scalar(0),
397397
S_31 , S_32 , Scalar(0),
398-
c1 * c2, s2 , Scalar(0),
399-
-c1 * s2, c2 , Scalar(0),
398+
c1 * c2, s2 , Scalar(0),
399+
-c1 * s2, c2 , Scalar(0),
400400
s1 , Scalar(0), Scalar(1);
401401
// clang-format on
402402
}
403-
403+
404404
/// @brief Computes the bias acceleration c(q, v) = Sdot(q)·v.
405405
template<typename ConfigVector, typename TangentVector>
406406
void computeBiais(
@@ -447,7 +447,7 @@ namespace pinocchio
447447
qdot1 = data.joint_v(1);
448448
qdot2 = data.joint_v(2);
449449

450-
// last columns and last element of the second column are zero,
450+
// last columns and last element of the second column are zero,
451451
// so we do not compute them
452452
Scalar Sdot_11, Sdot_21, Sdot_31, Sdot_41, Sdot_51, Sdot_61;
453453
Scalar Sdot_12, Sdot_22, Sdot_32, Sdot_42, Sdot_52;
@@ -496,7 +496,6 @@ namespace pinocchio
496496
* (dndoty_dqdot1 * radius_b * (c0 * s1 * s2 + c2 * s0) + dndotz_dqdot1 * radius_c * (-c0 * c2 + s0 * s1 * s2) + radius_b * (-c0 * c2 + s0 * s1 * s2) * d_dndoty_dqdot0_dq1 - radius_c * (c0 * s1 * s2 + c2 * s0) * d_dndotz_dqdot0_dq1)
497497
+ qdot1 * (dndotx_dqdot1 * radius_a * s1 * s2 - dndoty_dqdot1 * radius_b * c1 * s0 * s2 + dndotz_dqdot1 * radius_c * c0 * c1 * s2 - radius_a * c1 * s2 * d_dndotx_dqdot1_dq1 - radius_b * (-c0 * c2 + s0 * s1 * s2) * d_dndoty_dqdot1_dq1 + radius_c * (c0 * s1 * s2 + c2 * s0) * d_dndotz_dqdot1_dq1) - qdot2 * (dndotx_dqdot1 * radius_a * c1 * c2 + dndoty_dqdot1 * radius_b * (c0 * s2 + c2 * s0 * s1) + dndotz_dqdot1 * radius_c * (-c0 * c2 * s1 + s0 * s2));
498498

499-
500499
// Row 3, Column 1
501500
Sdot_31 =
502501
-qdot0 * c1
@@ -518,13 +517,10 @@ namespace pinocchio
518517

519518
Sdot_42 = qdot2 * c2;
520519
Sdot_52 = -qdot2 * s2;
521-
522-
data.c.toVector() << Sdot_11 * qdot0 + Sdot_12 * qdot1,
523-
Sdot_21 * qdot0 + Sdot_22 * qdot1,
524-
Sdot_31 * qdot0 + Sdot_32 * qdot1,
525-
Sdot_41 * qdot0 + Sdot_42 * qdot1,
526-
Sdot_51 * qdot0 + Sdot_52 * qdot1,
527-
Sdot_61 * qdot0;
520+
521+
data.c.toVector() << Sdot_11 * qdot0 + Sdot_12 * qdot1, Sdot_21 * qdot0 + Sdot_22 * qdot1,
522+
Sdot_31 * qdot0 + Sdot_32 * qdot1, Sdot_41 * qdot0 + Sdot_42 * qdot1,
523+
Sdot_51 * qdot0 + Sdot_52 * qdot1, Sdot_61 * qdot0;
528524
}
529525
}; // struct JointModelEllipsoidTpl
530526

0 commit comments

Comments
 (0)