joint-prismatic-unaligned.hpp 19.7 KB
Newer Older
jcarpent's avatar
jcarpent committed
1
//
2
// Copyright (c) 2015-2019 CNRS INRIA
3
// Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
jcarpent's avatar
jcarpent committed
4
5
//

6
7
#ifndef __pinocchio_joint_prismatic_unaligned_hpp__
#define __pinocchio_joint_prismatic_unaligned_hpp__
jcarpent's avatar
jcarpent committed
8

9
#include "pinocchio/macros.hpp"
jcarpent's avatar
jcarpent committed
10
#include "pinocchio/multibody/joint/joint-base.hpp"
11
#include "pinocchio/multibody/joint/joint-translation.hpp"
jcarpent's avatar
jcarpent committed
12
13
#include "pinocchio/multibody/constraint.hpp"
#include "pinocchio/spatial/inertia.hpp"
14
#include "pinocchio/math/matrix.hpp"
jcarpent's avatar
jcarpent committed
15

16
namespace pinocchio
jcarpent's avatar
jcarpent committed
17
18
{

19
20
21
  template<typename Scalar, int Options=0> struct MotionPrismaticUnalignedTpl;
  typedef MotionPrismaticUnalignedTpl<double> MotionPrismaticUnaligned;
  
22
23
  template<typename Scalar, int Options>
  struct SE3GroupAction< MotionPrismaticUnalignedTpl<Scalar,Options> >
24
  {
25
26
    typedef MotionTpl<Scalar,Options> ReturnType;
  };
jcarpent's avatar
jcarpent committed
27
  
28
29
30
31
32
33
  template<typename Scalar, int Options, typename MotionDerived>
  struct MotionAlgebraAction< MotionPrismaticUnalignedTpl<Scalar,Options>, MotionDerived>
  {
    typedef MotionTpl<Scalar,Options> ReturnType;
  };

34
  template<typename _Scalar, int _Options>
35
  struct traits< MotionPrismaticUnalignedTpl<_Scalar,_Options> >
jcarpent's avatar
jcarpent committed
36
  {
37
    typedef _Scalar Scalar;
38
39
40
41
    enum { Options = _Options };
    typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
    typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
    typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
gabrielebndn's avatar
gabrielebndn committed
42
43
    typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
    typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
44
45
46
47
48
    typedef Vector3 AngularType;
    typedef Vector3 LinearType;
    typedef const Vector3 ConstAngularType;
    typedef const Vector3 ConstLinearType;
    typedef Matrix6 ActionMatrixType;
49
    typedef MotionTpl<Scalar,Options> MotionPlain;
50
    typedef MotionPlain PlainReturnType;
jcarpent's avatar
jcarpent committed
51
52
53
54
    enum {
      LINEAR = 0,
      ANGULAR = 3
    };
55
  }; // traits MotionPrismaticUnalignedTpl
jcarpent's avatar
jcarpent committed
56

57
  template<typename _Scalar, int _Options>
58
59
  struct MotionPrismaticUnalignedTpl
  : MotionBase < MotionPrismaticUnalignedTpl<_Scalar,_Options> >
jcarpent's avatar
jcarpent committed
60
  {
61
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
62
    MOTION_TYPEDEF_TPL(MotionPrismaticUnalignedTpl);
jcarpent's avatar
jcarpent committed
63

64
    MotionPrismaticUnalignedTpl() {}
65
66
    
    template<typename Vector3Like, typename S2>
67
    MotionPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis,
Justin Carpentier's avatar
Justin Carpentier committed
68
69
                                const S2 & v)
    : m_axis(axis), m_v(v)
70
    { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3); }
jcarpent's avatar
jcarpent committed
71

72
    inline PlainReturnType plain() const
73
    {
74
      return PlainReturnType(m_axis*m_v,
75
                             PlainReturnType::Vector3::Zero());
76
77
78
79
80
    }
    
    template<typename OtherScalar>
    MotionPrismaticUnalignedTpl __mult__(const OtherScalar & alpha) const
    {
81
      return MotionPrismaticUnalignedTpl(m_axis,alpha*m_v);
82
    }
83
84
    
    template<typename Derived>
85
    void addTo(MotionDense<Derived> & other) const
86
    {
87
      other.linear() += m_axis * m_v;
88
    }
89
    
90
91
92
    template<typename Derived>
    void setTo(MotionDense<Derived> & other) const
    {
93
      other.linear().noalias() = m_axis*m_v;
94
95
96
      other.angular().setZero();
    }

97
98
99
    template<typename S2, int O2, typename D2>
    void se3Action_impl(const SE3Tpl<S2,O2> & m, MotionDense<D2> & v) const
    {
100
      v.linear().noalias() = m_v * (m.rotation() * m_axis); // TODO: check efficiency
101
      v.angular().setZero();
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    }
    
    template<typename S2, int O2>
    MotionPlain se3Action_impl(const SE3Tpl<S2,O2> & m) const
    {
      MotionPlain res;
      se3Action_impl(m,res);
      return res;
    }
    
    template<typename S2, int O2, typename D2>
    void se3ActionInverse_impl(const SE3Tpl<S2,O2> & m, MotionDense<D2> & v) const
    {
      // Linear
116
      v.linear().noalias() = m_v * (m.rotation().transpose() * m_axis);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
      
      // Angular
      v.angular().setZero();
    }
    
    template<typename S2, int O2>
    MotionPlain se3ActionInverse_impl(const SE3Tpl<S2,O2> & m) const
    {
      MotionPlain res;
      se3ActionInverse_impl(m,res);
      return res;
    }
    
    template<typename M1, typename M2>
    void motionAction(const MotionDense<M1> & v, MotionDense<M2> & mout) const
    {
      // Linear
134
135
      mout.linear().noalias() = v.angular().cross(m_axis);
      mout.linear() *= m_v;
136
137
138
139
140
141
142
143
144
145
146
147
148
      
      // Angular
      mout.angular().setZero();
    }
    
    template<typename M1>
    MotionPlain motionAction(const MotionDense<M1> & v) const
    {
      MotionPlain res;
      motionAction(v,res);
      return res;
    }
    
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
    bool isEqual_impl(const MotionPrismaticUnalignedTpl & other) const
    {
      return m_axis == other.m_axis && m_v == other.m_v;
    }
    
    const Scalar & linearRate() const { return m_v; }
    Scalar & linearRate() { return m_v; }
    
    const Vector3 & axis() const { return m_axis; }
    Vector3 & axis() { return m_axis; }
    
  protected:
    
    Vector3 m_axis;
    Scalar m_v;
164
  }; // struct MotionPrismaticUnalignedTpl
jcarpent's avatar
jcarpent committed
165

166
167
  template<typename Scalar, int Options, typename MotionDerived>
  inline typename MotionDerived::MotionPlain
168
  operator+(const MotionPrismaticUnalignedTpl<Scalar,Options> & m1, const MotionDense<MotionDerived> & m2)
jcarpent's avatar
jcarpent committed
169
  {
170
    typedef typename MotionDerived::MotionPlain ReturnType;
Justin Carpentier's avatar
Justin Carpentier committed
171
    return ReturnType(m1.linearRate() * m1.axis() + m2.linear(), m2.angular());
jcarpent's avatar
jcarpent committed
172
  }
173
174
175
176
177
178
179
180
  
  template<typename MotionDerived, typename S2, int O2>
  inline typename MotionDerived::MotionPlain
  operator^(const MotionDense<MotionDerived> & m1,
            const MotionPrismaticUnalignedTpl<S2,O2> & m2)
  {
    return m2.motionAction(m1);
  }
jcarpent's avatar
jcarpent committed
181

182
  template<typename Scalar, int Options> struct ConstraintPrismaticUnalignedTpl;
183
  
184
  template<typename _Scalar, int _Options>
185
  struct traits< ConstraintPrismaticUnalignedTpl<_Scalar,_Options> >
jcarpent's avatar
jcarpent committed
186
  {
187
    typedef _Scalar Scalar;
188
    enum { Options = _Options };
jcarpent's avatar
jcarpent committed
189
190
191
192
    enum {
      LINEAR = 0,
      ANGULAR = 3
    };
193
    typedef MotionPrismaticUnalignedTpl<Scalar,Options> JointMotion;
194
195
    typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
    typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
196
197
    typedef DenseBase MatrixReturnType;
    typedef const DenseBase ConstMatrixReturnType;
198
199
    
    typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
200
  }; // traits ConstraintPrismaticUnalignedTpl
201
202
  
  template<typename Scalar, int Options>
Justin Carpentier's avatar
Justin Carpentier committed
203
  struct SE3GroupAction< ConstraintPrismaticUnalignedTpl<Scalar,Options> >
204
205
206
  { typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
  
  template<typename Scalar, int Options, typename MotionDerived>
Justin Carpentier's avatar
Justin Carpentier committed
207
  struct MotionAlgebraAction< ConstraintPrismaticUnalignedTpl<Scalar,Options>,MotionDerived >
208
209
210
  { typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };

  template<typename Scalar, int Options, typename ForceDerived>
Justin Carpentier's avatar
Justin Carpentier committed
211
  struct ConstraintForceOp< ConstraintPrismaticUnalignedTpl<Scalar,Options>, ForceDerived>
212
  {
Justin Carpentier's avatar
Justin Carpentier committed
213
    typedef typename traits< ConstraintPrismaticUnalignedTpl<Scalar,Options> >::Vector3 Vector3;
214
215
216
217
    typedef Eigen::Matrix<typename PINOCCHIO_EIGEN_DOT_PRODUCT_RETURN_TYPE(Vector3,typename ForceDense<ForceDerived>::ConstAngularType),1,1,Options> ReturnType;
  };
  
  template<typename Scalar, int Options, typename ForceSet>
Justin Carpentier's avatar
Justin Carpentier committed
218
  struct ConstraintForceSetOp< ConstraintPrismaticUnalignedTpl<Scalar,Options>, ForceSet>
219
  {
Justin Carpentier's avatar
Justin Carpentier committed
220
    typedef typename traits< ConstraintPrismaticUnalignedTpl<Scalar,Options> >::Vector3 Vector3;
221
222
223
224
    typedef typename MatrixMatrixProduct<Eigen::Transpose<const Vector3>,
    typename Eigen::MatrixBase<const ForceSet>::template NRowsBlockXpr<3>::Type
    >::type ReturnType;
  };
jcarpent's avatar
jcarpent committed
225

226
  template<typename _Scalar, int _Options>
227
228
  struct ConstraintPrismaticUnalignedTpl
  : ConstraintBase< ConstraintPrismaticUnalignedTpl<_Scalar,_Options> >
229
  {
230
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
231
    PINOCCHIO_CONSTRAINT_TYPEDEF_TPL(ConstraintPrismaticUnalignedTpl)
232
    
233
    enum { NV = 1 };
234
    
235
    typedef typename traits<ConstraintPrismaticUnalignedTpl>::Vector3 Vector3;
236

237
    ConstraintPrismaticUnalignedTpl() {}
238
239
    
    template<typename Vector3Like>
240
    ConstraintPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
241
242
243
    : axis(axis)
    { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3); }

244
245
    template<typename Vector1Like>
    JointMotion __mult__(const Eigen::MatrixBase<Vector1Like> & v) const
246
    {
247
248
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like,1);
      return JointMotion(axis,v[0]);
249
250
251
    }
    
    template<typename S1, int O1>
252
253
    typename SE3GroupAction<ConstraintPrismaticUnalignedTpl>::ReturnType
    se3Action(const SE3Tpl<S1,O1> & m) const
254
    {
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
      typename SE3GroupAction<ConstraintPrismaticUnalignedTpl>::ReturnType res;
      MotionRef<DenseBase> v(res);
      v.linear().noalias() = m.rotation()*axis;
      v.angular().setZero();
      return res;
    }
    
    template<typename S1, int O1>
    typename SE3GroupAction<ConstraintPrismaticUnalignedTpl>::ReturnType
    se3ActionInverse(const SE3Tpl<S1,O1> & m) const
    {
      typename SE3GroupAction<ConstraintPrismaticUnalignedTpl>::ReturnType res;
      MotionRef<DenseBase> v(res);
      v.linear().noalias() = m.rotation().transpose()*axis;
      v.angular().setZero();
270
271
272
273
274
275
      return res;
    }
    
    int nv_impl() const { return NV; }
    
    struct TransposeConst
jcarpent's avatar
jcarpent committed
276
    {
277
278
      const ConstraintPrismaticUnalignedTpl & ref;
      TransposeConst(const ConstraintPrismaticUnalignedTpl & ref) : ref(ref) {}
279
      
280
      template<typename ForceDerived>
Justin Carpentier's avatar
Justin Carpentier committed
281
      typename ConstraintForceOp<ConstraintPrismaticUnalignedTpl,ForceDerived>::ReturnType
282
      operator* (const ForceDense<ForceDerived> & f) const
jcarpent's avatar
jcarpent committed
283
      {
Justin Carpentier's avatar
Justin Carpentier committed
284
        typedef typename ConstraintForceOp<ConstraintPrismaticUnalignedTpl,ForceDerived>::ReturnType ReturnType;
285
286
287
        ReturnType res;
        res[0] = ref.axis.dot(f.linear());
        return res;
jcarpent's avatar
jcarpent committed
288
      }
289
290
      
      /* [CRBA]  MatrixBase operator* (Constraint::Transpose S, ForceSet::Block) */
291
      template<typename ForceSet>
Justin Carpentier's avatar
Justin Carpentier committed
292
      typename ConstraintForceSetOp<ConstraintPrismaticUnalignedTpl,ForceSet>::ReturnType
293
      operator*(const Eigen::MatrixBase<ForceSet> & F)
jcarpent's avatar
jcarpent committed
294
      {
295
        EIGEN_STATIC_ASSERT(ForceSet::RowsAtCompileTime==6,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
296
        /* Return ax.T * F[1:3,:] */
297
        return ref.axis.transpose() * F.template middleRows<3>(LINEAR);
jcarpent's avatar
jcarpent committed
298
299
      }
      
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
    };
    TransposeConst transpose() const { return TransposeConst(*this); }
    
    
    /* CRBA joint operators
     *   - ForceSet::Block = ForceSet
     *   - ForceSet operator* (Inertia Y,Constraint S)
     *   - MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
     *   - SE3::act(ForceSet::Block)
     */
    DenseBase matrix_impl() const
    {
      DenseBase S;
      S << axis, Vector3::Zero();
      return S;
    }
    
    template<typename MotionDerived>
    DenseBase motionAction(const MotionDense<MotionDerived> & v) const
    {
      DenseBase res;
      res << v.angular().cross(axis), Vector3::Zero();
322
      
323
324
325
      return res;
    }
    
326
    // data
327
328
    Vector3 axis;
    
329
  }; // struct ConstraintPrismaticUnalignedTpl
330
331
332
  
  template<typename S1, int O1,typename S2, int O2>
  struct MultiplicationOp<InertiaTpl<S1,O1>, ConstraintPrismaticUnalignedTpl<S2,O2> >
333
  {
334
335
336
    typedef Eigen::Matrix<S2,6,1,O2> ReturnType;
  };
  
337
  /* [CRBA] ForceSet operator* (Inertia Y,Constraint S) */
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
  namespace impl
  {
    template<typename S1, int O1, typename S2, int O2>
    struct LhsMultiplicationOp<InertiaTpl<S1,O1>, ConstraintPrismaticUnalignedTpl<S2,O2> >
    {
      typedef InertiaTpl<S1,O1> Inertia;
      typedef ConstraintPrismaticUnalignedTpl<S2,O2> Constraint;
      typedef typename MultiplicationOp<Inertia,Constraint>::ReturnType ReturnType;
      
      static inline ReturnType run(const Inertia & Y,
                                   const Constraint & cpu)
      {
        ReturnType res;
        /* YS = [ m -mcx ; mcx I-mcxcx ] [ 0 ; w ] = [ mcxw ; Iw -mcxcxw ] */
        const S1 & m                             = Y.mass();
        const typename Inertia::Vector3 & c      = Y.lever();
        
        res.template head<3>().noalias() = m*cpu.axis;
        res.template tail<3>().noalias() = c.cross(res.template head<3>());
        
        return res;
      }
    };
  } // namespace impl
  
  template<typename M6Like, typename Scalar, int Options>
  struct MultiplicationOp<Eigen::MatrixBase<M6Like>, ConstraintPrismaticUnalignedTpl<Scalar,Options> >
365
  {
366
367
    typedef typename SizeDepType<3>::ColsReturn<M6Like>::ConstType M6LikeCols;
    typedef typename Eigen::internal::remove_const<M6LikeCols>::type M6LikeColsNonConst;
368
    
369
370
371
372
    typedef ConstraintPrismaticUnalignedTpl<Scalar,Options> Constraint;
    typedef typename Constraint::Vector3 Vector3;
    typedef const typename MatrixMatrixProduct<M6LikeColsNonConst,Vector3>::type ReturnType;
  };
jcarpent's avatar
jcarpent committed
373
  
374
375
  /* [ABA] operator* (Inertia Y,Constraint S) */
  namespace impl
376
  {
377
378
379
380
381
382
383
384
385
386
387
388
389
390
    template<typename M6Like, typename Scalar, int Options>
    struct LhsMultiplicationOp<Eigen::MatrixBase<M6Like>, ConstraintPrismaticUnalignedTpl<Scalar,Options> >
    {
      typedef ConstraintPrismaticUnalignedTpl<Scalar,Options> Constraint;
      typedef typename MultiplicationOp<Eigen::MatrixBase<M6Like>,Constraint>::ReturnType ReturnType;
      static inline ReturnType run(const Eigen::MatrixBase<M6Like> & Y,
                                   const Constraint & cru)
      {
        EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like,6,6);
        return Y.derived().template middleCols<3>(Constraint::LINEAR) * cru.axis;
      }
    };
  } // namespace impl
  
391
  template<typename Scalar, int Options> struct JointPrismaticUnalignedTpl;
392
  
393
394
  template<typename _Scalar, int _Options>
  struct traits< JointPrismaticUnalignedTpl<_Scalar,_Options> >
395
396
397
398
  {
    enum {
      NQ = 1,
      NV = 1
jcarpent's avatar
jcarpent committed
399
    };
400
    typedef _Scalar Scalar;
401
402
403
    enum { Options = _Options };
    typedef JointDataPrismaticUnalignedTpl<Scalar,Options> JointDataDerived;
    typedef JointModelPrismaticUnalignedTpl<Scalar,Options> JointModelDerived;
404
    typedef ConstraintPrismaticUnalignedTpl<Scalar,Options> Constraint_t;
405
    typedef TransformTranslationTpl<Scalar,Options> Transformation_t;
406
    typedef MotionPrismaticUnalignedTpl<Scalar,Options> Motion_t;
407
    typedef MotionZeroTpl<Scalar,Options> Bias_t;
Justin Carpentier's avatar
Justin Carpentier committed
408

409
    // [ABA]
410
411
412
    typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
    typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
    typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
413
    
Gabriele Buondonno's avatar
Gabriele Buondonno committed
414
    PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
415
    
416
417
    typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
    typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
418
  };
jcarpent's avatar
jcarpent committed
419

420
421
422
  template<typename Scalar, int Options>
  struct traits< JointDataPrismaticUnalignedTpl<Scalar,Options> >
  { typedef JointPrismaticUnalignedTpl<Scalar,Options> JointDerived; };
jcarpent's avatar
jcarpent committed
423

424
  template<typename _Scalar, int _Options>
425
426
  struct JointDataPrismaticUnalignedTpl
  : public JointDataBase< JointDataPrismaticUnalignedTpl<_Scalar,_Options> >
jcarpent's avatar
jcarpent committed
427
  {
428
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
429
    typedef JointPrismaticUnalignedTpl<_Scalar,_Options> JointDerived;
430
    PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
Gabriele Buondonno's avatar
Gabriele Buondonno committed
431
    PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
432
    
jcarpent's avatar
jcarpent committed
433
434
435
436
437
    Transformation_t M;
    Constraint_t S;
    Motion_t v;
    Bias_t c;

438
439
440
441
    // [ABA] specific data
    U_t U;
    D_t Dinv;
    UD_t UDinv;
jcarpent's avatar
jcarpent committed
442

443
    JointDataPrismaticUnalignedTpl() {}
jcarpent's avatar
jcarpent committed
444
    
445
446
    template<typename Vector3Like>
    JointDataPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
447
    : M()
448
    , S(axis)
449
    , v(axis,(Scalar)NAN)
450
    , U(), Dinv(), UDinv()
jcarpent's avatar
jcarpent committed
451
452
    {}

453
454
455
    static std::string classname() { return std::string("JointDataPrismaticUnaligned"); }
    std::string shortname() const { return classname(); }
    
456
457
  }; // struct JointDataPrismaticUnalignedTpl
  
458
459
460
  template<typename Scalar, int Options>
  struct traits< JointModelPrismaticUnalignedTpl<Scalar,Options> >
  { typedef JointPrismaticUnalignedTpl<Scalar,Options> JointDerived; };
jcarpent's avatar
jcarpent committed
461

Gabriele Buondonno's avatar
Gabriele Buondonno committed
462
  PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelPrismaticUnalignedTpl);
463
  template<typename _Scalar, int _Options>
jcarpent's avatar
jcarpent committed
464
465
  struct JointModelPrismaticUnalignedTpl
  : public JointModelBase< JointModelPrismaticUnalignedTpl<_Scalar,_Options> >
jcarpent's avatar
jcarpent committed
466
  {
467
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
468
    typedef JointPrismaticUnalignedTpl<_Scalar,_Options> JointDerived;
469
    PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
jcarpent's avatar
jcarpent committed
470
471
472
473
474
475
476
477
    
    typedef JointModelBase<JointModelPrismaticUnalignedTpl> Base;
    using Base::id;
    using Base::idx_q;
    using Base::idx_v;
    using Base::setIndexes;
    
    typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
jcarpent's avatar
jcarpent committed
478
    
479
    JointModelPrismaticUnalignedTpl() {}
480
481
482
    JointModelPrismaticUnalignedTpl(const Scalar & x,
                                    const Scalar & y,
                                    const Scalar & z)
483
    : axis(x,y,z)
jcarpent's avatar
jcarpent committed
484
485
    {
      axis.normalize();
486
      assert(isUnitary(axis) && "Translation axis is not unitary");
jcarpent's avatar
jcarpent committed
487
488
    }
    
489
    template<typename Vector3Like>
490
491
    JointModelPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
    : axis(axis)
jcarpent's avatar
jcarpent committed
492
    {
493
      EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
494
      assert(isUnitary(axis) && "Translation axis is not unitary");
jcarpent's avatar
jcarpent committed
495
496
    }

497
    JointDataDerived createData() const { return JointDataDerived(axis); }
jcarpent's avatar
jcarpent committed
498
    
499
500
501
502
503
504
    using Base::isEqual;
    bool isEqual(const JointModelPrismaticUnalignedTpl & other) const
    {
      return Base::isEqual(other) && axis == other.axis;
    }
    
505
506
507
    template<typename ConfigVector>
    void calc(JointDataDerived & data,
              const typename Eigen::MatrixBase<ConfigVector> & qs) const
jcarpent's avatar
jcarpent committed
508
    {
509
510
      typedef typename ConfigVector::Scalar Scalar;
      const Scalar & q = qs[idx_q()];
jcarpent's avatar
jcarpent committed
511

512
      data.M.translation().noalias() = axis * q;
jcarpent's avatar
jcarpent committed
513
514
    }

515
    template<typename ConfigVector, typename TangentVector>
516
    void calc(JointDataDerived & data,
517
518
              const typename Eigen::MatrixBase<ConfigVector> & qs,
              const typename Eigen::MatrixBase<TangentVector> & vs) const
jcarpent's avatar
jcarpent committed
519
    {
520
521
522
523
      calc(data,qs.derived());
      
      typedef typename TangentVector::Scalar S2;
      const S2 & v = vs[idx_v()];
524
      data.v.linearRate() = v;
jcarpent's avatar
jcarpent committed
525
    }
526
    
527
528
    template<typename Matrix6Like>
    void calc_aba(JointDataDerived & data, const Eigen::MatrixBase<Matrix6Like> & I, const bool update_I) const
529
    {
530
      data.U.noalias() = I.template block<6,3> (0,Inertia::LINEAR) * axis;
531
      data.Dinv[0] = Scalar(1)/axis.dot(data.U.template segment <3> (Inertia::LINEAR));
532
      data.UDinv.noalias() = data.U * data.Dinv;
533
534
      
      if (update_I)
gabrielebndn's avatar
gabrielebndn committed
535
        PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
536
    }
537
    
538
    static std::string classname() { return std::string("JointModelPrismaticUnaligned"); }
539
    std::string shortname() const { return classname(); }
540
541
542
543
544
545
546
547
548
549
    
    /// \returns An expression of *this with the Scalar type casted to NewScalar.
    template<typename NewScalar>
    JointModelPrismaticUnalignedTpl<NewScalar,Options> cast() const
    {
      typedef JointModelPrismaticUnalignedTpl<NewScalar,Options> ReturnType;
      ReturnType res(axis.template cast<NewScalar>());
      res.setIndexes(id(),idx_q(),idx_v());
      return res;
    }
550
551
552
553
554
555
    
    // data
    
    ///
    /// \brief 3d main axis of the joint.
    ///
556
    Vector3 axis;
557
558
  }; // struct JointModelPrismaticUnalignedTpl
  
559
} //namespace pinocchio
jcarpent's avatar
jcarpent committed
560

561
562
563
564
565
#include <boost/type_traits.hpp>

namespace boost
{
  template<typename Scalar, int Options>
566
  struct has_nothrow_constructor< ::pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> >
567
568
569
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
570
  struct has_nothrow_copy< ::pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> >
571
572
573
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
574
  struct has_nothrow_constructor< ::pinocchio::JointDataPrismaticUnalignedTpl<Scalar,Options> >
575
576
577
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
578
  struct has_nothrow_copy< ::pinocchio::JointDataPrismaticUnalignedTpl<Scalar,Options> >
579
580
581
  : public integral_constant<bool,true> {};
}

jcarpent's avatar
jcarpent committed
582

583
#endif // ifndef __pinocchio_joint_prismatic_unaligned_hpp__