@@ -225,7 +225,7 @@ namespace pinocchio
225225 void calc (JointDataDerived & data, const Eigen::MatrixBase<ConfigVector> & qs) const
226226 {
227227 assert (
228- check_expression_if_real<Scalar>(qs[0 ] >= 0.0 && qs[0 ] <= 1.0 )
228+ check_expression_if_real<Scalar>(qs[0 ] >= knots[ 0 ] && qs[0 ] <= knots (knots. size () - 1 ) )
229229 && " Spline joint configuration (q) must be between 0 and 1. " );
230230
231231 data.joint_q = qs.template segment <NQ >(idx_q ());
@@ -264,7 +264,7 @@ namespace pinocchio
264264 const Eigen::MatrixBase<TangentVector> & vs) const
265265 {
266266 assert (
267- check_expression_if_real<Scalar>(qs[0 ] >= 0.0 && qs[0 ] <= 1.0 )
267+ check_expression_if_real<Scalar>(qs[0 ] >= knots[ 0 ] && qs[0 ] <= knots (knots. size () - 1 ) )
268268 && " Spline joint configuration (q) must be between 0 and 1. " );
269269
270270 data.joint_q = qs.template segment <NQ >(idx_q ());
@@ -285,6 +285,7 @@ namespace pinocchio
285285
286286 data.S .matrix ().setZero ();
287287 data.c .setZero ();
288+ data.v .setZero ();
288289 data.M = ctrlFrames[indexes.start_idx ];
289290 for (size_t i = indexes.start_idx + 1 ; i < indexes.end_idx ; i++)
290291 {
@@ -313,11 +314,13 @@ namespace pinocchio
313314 {
314315 data.joint_v = vs.template segment <NV >(idx_v ());
315316
317+ SpanIndexes indexes = FindSpan<Scalar, Options>::run (data.joint_q , degree, nbCtrlFrames, knots);
318+
316319 // Basis functions and their derivatives
317320 data.N .setZero ();
318321 data.N_der .setZero ();
319322 data.N_der2 .setZero ();
320- for (int i = 0 ; i < nbCtrlFrames; ++i )
323+ for (size_t i = indexes. start_idx ; i < indexes. end_idx ; i++ )
321324 {
322325 data.N [i] = bsplineBasis (i, degree, data.joint_q [0 ]);
323326 data.N_der [i] = bsplineBasisDerivative (i, degree, data.joint_q [0 ]);
@@ -326,21 +329,25 @@ namespace pinocchio
326329
327330 data.S .matrix ().setZero ();
328331 data.c .setZero ();
329- for (int i = 0 ; i < nbCtrlFrames - 1 ; ++i)
332+ data.v .setZero ();
333+ data.M = ctrlFrames[indexes.start_idx ];
334+ for (size_t i = indexes.start_idx + 1 ; i < indexes.end_idx ; i++)
330335 {
331- const Scalar phi_i = data.N .tail (nbCtrlFrames - (i + 1 ) ).sum ();
332- const Scalar phi_dot_i = data.N_der .tail (nbCtrlFrames - (i + 1 ) ).sum ();
333- const Scalar phi_ddot_i = data.N_der2 .tail (nbCtrlFrames - (i + 1 ) ).sum ();
336+ const Scalar phi_i = data.N .segment (i, indexes. end_idx - i ).sum ();
337+ const Scalar phi_dot_i = data.N_der .segment (i, indexes. end_idx - i ).sum ();
338+ const Scalar phi_ddot_i = data.N_der2 .segment (i, indexes. end_idx - i ).sum ();
334339
335- const Transformation_t transformation_temp (exp6 (relativeMotions[i] * phi_i));
340+ const Transformation_t transformation_temp (exp6 (relativeMotions[i - 1 ] * phi_i));
336341
337- data.c = relativeMotions[i] * phi_ddot_i
342+ data.M = data.M * transformation_temp;
343+ // Compute dS/dq recursively
344+ data.c = relativeMotions[i - 1 ] * phi_ddot_i
338345 + transformation_temp.actInv (
339- data.c + Motion (data.S .matrix ()).cross (relativeMotions[i]) * phi_dot_i);
346+ data.c + Motion_t (data.S .matrix ()).cross (relativeMotions[i - 1 ]) * phi_dot_i);
340347 data.S .matrix () =
341- transformation_temp.actInv (data.S ) + relativeMotions[i].toVector () * phi_dot_i;
348+ transformation_temp.actInv (data.S ) + relativeMotions[i - 1 ].toVector () * phi_dot_i;
342349 }
343-
350+ // C = Sdot * qdot = (dS/dq * qdot) * dot
344351 data.c = data.c * data.joint_v [0 ] * data.joint_v [0 ];
345352 data.v = data.S * data.joint_v ;
346353 }
@@ -538,6 +545,7 @@ namespace pinocchio
538545 int degree;
539546 int nbCtrlFrames;
540547 Vector knots;
548+
541549 PINOCCHIO_ALIGNED_STD_VECTOR (Transformation_t) ctrlFrames;
542550 PINOCCHIO_ALIGNED_STD_VECTOR (Motion_t) relativeMotions;
543551 }; // struct JointModelSplineTpl
0 commit comments