55#ifndef __pinocchio_multibody_joint_spline_hpp__
66#define __pinocchio_multibody_joint_spline_hpp__
77
8- #include " pinocchio/macros.hpp"
9- #include " pinocchio/spatial/inertia.hpp"
8+ #include " pinocchio/eigen-macros.hpp"
109#include " pinocchio/spatial/explog.hpp"
1110#include " pinocchio/multibody/joint/joint-base.hpp"
1211#include " pinocchio/multibody/joint-motion-subspace.hpp"
13- #include " pinocchio/math/fwd.hpp"
14- #include " pinocchio/math/quaternion.hpp"
15-
16- #include < iostream>
1712
1813namespace pinocchio
1914{
2015 struct SpanIndexes
2116 {
22- int start_idx;
23- int end_idx;
17+ size_t start_idx;
18+ size_t end_idx;
2419 };
2520
2621 template <typename Scalar, int Options>
@@ -89,9 +84,6 @@ namespace pinocchio
8984 typedef JointModelSplineTpl<Scalar, Options> JointModelDerived;
9085 // typedef JointMotionSubspace1d Constraint_t;
9186 typedef JointMotionSubspaceTpl<1 , Scalar, Options, 1 > Constraint_t;
92- typedef SE3Tpl<Scalar, Options> Transformation_t;
93- typedef MotionTpl<Scalar, Options> Motion_t;
94- typedef MotionTpl<Scalar, Options> Bias_t;
9587
9688 // [ABA]
9789 typedef Eigen::Matrix<Scalar, 6 , NV, Options> U_t;
@@ -136,7 +128,7 @@ namespace pinocchio
136128 Constraint_t S;
137129 Transformation_t M;
138130 Motion_t v;
139- Bias_t c;
131+ Motion_t c;
140132
141133 // [ABA] specific data
142134 U_t U;
@@ -225,21 +217,17 @@ namespace pinocchio
225217 JointModelSplineTpl (
226218 const PINOCCHIO_ALIGNED_STD_VECTOR (SE3) & controlFrames, const int degree = 3)
227219 : degree(degree)
228- , nbCtrlFrames(controlFrames.size())
229- , ctrlFrames(controlFrames)
230220 {
221+ setControlFrames (controlFrames);
231222 }
232223
233- void addControlFrame (const SE3 & frame )
224+ void setControlFrames (const std::vector< SE3> & controlFrames )
234225 {
235- ctrlFrames.push_back (frame);
236- nbCtrlFrames++;
237- }
238-
239- void buildJoint ()
240- {
241- makeKnots ();
242- computeRelativeMotions ();
226+ nbCtrlFrames = controlFrames.size ();
227+ for (size_t i = 0 ; i < nbCtrlFrames; i++)
228+ ctrlFrames.push_back (controlFrames);
229+
230+ buildJoint ();
243231 }
244232
245233 JointDataDerived createData () const
@@ -265,7 +253,7 @@ namespace pinocchio
265253 }
266254
267255 template <typename ConfigVector>
268- void calc (JointDataDerived & data, const typename Eigen::MatrixBase<ConfigVector> & qs) const
256+ void calc (JointDataDerived & data, const Eigen::MatrixBase<ConfigVector> & qs) const
269257 {
270258 data.joint_q = qs.template segment <NQ>(idx_q ());
271259
@@ -297,8 +285,8 @@ namespace pinocchio
297285 template <typename ConfigVector, typename TangentVector>
298286 void calc (
299287 JointDataDerived & data,
300- const typename Eigen::MatrixBase<ConfigVector> & qs,
301- const typename Eigen::MatrixBase<TangentVector> & vs) const
288+ const Eigen::MatrixBase<ConfigVector> & qs,
289+ const Eigen::MatrixBase<TangentVector> & vs) const
302290 {
303291 data.joint_q = qs.template segment <NQ>(idx_q ());
304292 data.joint_v = vs.template segment <NV>(idx_v ());
@@ -343,7 +331,7 @@ namespace pinocchio
343331 void calc (
344332 JointDataDerived & data,
345333 const Blank not_used,
346- const typename Eigen::MatrixBase<TangentVector> & vs) const
334+ const Eigen::MatrixBase<TangentVector> & vs) const
347335 {
348336 data.joint_v = vs.template segment <NV>(idx_v ());
349337
@@ -358,7 +346,6 @@ namespace pinocchio
358346 data.N_der2 [i] = bsplineBasisDerivative2 (i, degree, data.joint_q [0 ]);
359347 }
360348
361- // Compute time derivative of S (for bias acceleration c)
362349 data.S .matrix ().setZero ();
363350 data.c .setZero ();
364351 for (int i = 0 ; i < nbCtrlFrames - 1 ; ++i)
@@ -414,9 +401,8 @@ namespace pinocchio
414401 res.degree = degree;
415402 res.nbCtrlFrames = nbCtrlFrames;
416403 for (size_t k = 0 ; k < ctrlFrames.size (); k++)
417- {
418404 res.ctrlFrames .push_back (ctrlFrames[k].template cast <NewScalar>());
419- }
405+
420406 res.makeKnots ();
421407 res.computeRelativeMotions ();
422408 res.setIndexes (id (), idx_q (), idx_v (), idx_vExtended ());
@@ -425,6 +411,8 @@ namespace pinocchio
425411
426412 void makeKnots ()
427413 {
414+ if (nbCtrlFrames <= degree)
415+ PINOCCHIO_THROW_PRETTY (std::invalid_argument, " JointSpline - Number of control frames must be greater than degree of the spline." )
428416 const int n_knots = nbCtrlFrames + degree + 1 ;
429417 knots.resize (n_knots);
430418 knots.head (degree + 1 ).setZero ();
@@ -450,10 +438,22 @@ namespace pinocchio
450438 PINOCCHIO_ALIGNED_STD_VECTOR (Motion) relativeMotions;
451439
452440 private:
441+ void buildJoint ()
442+ {
443+ makeKnots ();
444+ computeRelativeMotions ();
445+ }
446+
453447 Scalar bsplineBasis (int i, int k, const Scalar x) const
454448 {
455449 if (k == 0 )
456450 {
451+ // clang-format off
452+ // if(knots[i] <= x && x <= knots[i])
453+ // return 1;
454+ // else
455+ // return 0;
456+ // clang-format on
457457 return pinocchio::internal::if_then_else (
458458 pinocchio::internal::LE, knots[i], x,
459459 pinocchio::internal::if_then_else (
0 commit comments