joint-prismatic-unaligned.hpp 20.4 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
    : m_axis(axis)
242
243
    { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3); }

244
245
    template<typename Vector1Like>
    JointMotion __mult__(const Eigen::MatrixBase<Vector1Like> & v) const
246
    {
247
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like,1);
248
      return JointMotion(m_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
      typename SE3GroupAction<ConstraintPrismaticUnalignedTpl>::ReturnType res;
      MotionRef<DenseBase> v(res);
257
      v.linear().noalias() = m.rotation()*m_axis;
258
259
260
261
262
263
264
265
266
267
      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);
268
      v.linear().noalias() = m.rotation().transpose()*m_axis;
269
      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
        ReturnType res;
286
        res[0] = ref.axis().dot(f.linear());
287
        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
    TransposeConst transpose() const { return TransposeConst(*this); }
303
304
305
306
307
308
309
310
311
312
    
    /* 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;
313
314
      S.template segment<3>(LINEAR) = m_axis;
      S.template segment<3>(ANGULAR).setZero();
315
316
317
318
319
320
321
      return S;
    }
    
    template<typename MotionDerived>
    DenseBase motionAction(const MotionDense<MotionDerived> & v) const
    {
      DenseBase res;
322
323
      res.template segment<3>(LINEAR).noalias() = v.angular().cross(m_axis);
      res.template segment<3>(ANGULAR).setZero();
324
      
325
326
      return res;
    }
327
328
329
330
      
    const Vector3 & axis() const { return m_axis; }
    Vector3 & axis() { return m_axis; }
    
331
332
333
334
335
    bool isEqual(const ConstraintPrismaticUnalignedTpl & other) const
    {
      return m_axis == other.m_axis;
    }
    
336
  protected:
337
    
338
    Vector3 m_axis;
339
    
340
  }; // struct ConstraintPrismaticUnalignedTpl
341
342
343
  
  template<typename S1, int O1,typename S2, int O2>
  struct MultiplicationOp<InertiaTpl<S1,O1>, ConstraintPrismaticUnalignedTpl<S2,O2> >
344
  {
345
346
347
    typedef Eigen::Matrix<S2,6,1,O2> ReturnType;
  };
  
348
  /* [CRBA] ForceSet operator* (Inertia Y,Constraint S) */
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
  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();
        
366
367
        res.template segment<3>(Constraint::LINEAR).noalias() = m*cpu.axis();
        res.template segment<3>(Constraint::ANGULAR).noalias() = c.cross(res.template segment<3>(Constraint::LINEAR));
368
369
370
371
372
373
374
375
        
        return res;
      }
    };
  } // namespace impl
  
  template<typename M6Like, typename Scalar, int Options>
  struct MultiplicationOp<Eigen::MatrixBase<M6Like>, ConstraintPrismaticUnalignedTpl<Scalar,Options> >
376
  {
377
378
    typedef typename SizeDepType<3>::ColsReturn<M6Like>::ConstType M6LikeCols;
    typedef typename Eigen::internal::remove_const<M6LikeCols>::type M6LikeColsNonConst;
379
    
380
381
382
383
    typedef ConstraintPrismaticUnalignedTpl<Scalar,Options> Constraint;
    typedef typename Constraint::Vector3 Vector3;
    typedef const typename MatrixMatrixProduct<M6LikeColsNonConst,Vector3>::type ReturnType;
  };
jcarpent's avatar
jcarpent committed
384
  
385
386
  /* [ABA] operator* (Inertia Y,Constraint S) */
  namespace impl
387
  {
388
389
390
391
392
393
394
395
396
    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);
397
        return Y.derived().template middleCols<3>(Constraint::LINEAR) * cru.axis();
398
399
400
401
      }
    };
  } // namespace impl
  
402
  template<typename Scalar, int Options> struct JointPrismaticUnalignedTpl;
403
  
404
405
  template<typename _Scalar, int _Options>
  struct traits< JointPrismaticUnalignedTpl<_Scalar,_Options> >
406
407
408
409
  {
    enum {
      NQ = 1,
      NV = 1
jcarpent's avatar
jcarpent committed
410
    };
411
    typedef _Scalar Scalar;
412
413
414
    enum { Options = _Options };
    typedef JointDataPrismaticUnalignedTpl<Scalar,Options> JointDataDerived;
    typedef JointModelPrismaticUnalignedTpl<Scalar,Options> JointModelDerived;
415
    typedef ConstraintPrismaticUnalignedTpl<Scalar,Options> Constraint_t;
416
    typedef TransformTranslationTpl<Scalar,Options> Transformation_t;
417
    typedef MotionPrismaticUnalignedTpl<Scalar,Options> Motion_t;
418
    typedef MotionZeroTpl<Scalar,Options> Bias_t;
Justin Carpentier's avatar
Justin Carpentier committed
419

420
    // [ABA]
421
422
423
    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;
424
    
Gabriele Buondonno's avatar
Gabriele Buondonno committed
425
    PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
426
    
427
428
    typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
    typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
429
  };
jcarpent's avatar
jcarpent committed
430

431
432
433
  template<typename Scalar, int Options>
  struct traits< JointDataPrismaticUnalignedTpl<Scalar,Options> >
  { typedef JointPrismaticUnalignedTpl<Scalar,Options> JointDerived; };
jcarpent's avatar
jcarpent committed
434

435
  template<typename _Scalar, int _Options>
436
437
  struct JointDataPrismaticUnalignedTpl
  : public JointDataBase< JointDataPrismaticUnalignedTpl<_Scalar,_Options> >
jcarpent's avatar
jcarpent committed
438
  {
439
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
440
    typedef JointPrismaticUnalignedTpl<_Scalar,_Options> JointDerived;
441
    PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
Gabriele Buondonno's avatar
Gabriele Buondonno committed
442
    PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
443
    
jcarpent's avatar
jcarpent committed
444
445
446
447
448
    Transformation_t M;
    Constraint_t S;
    Motion_t v;
    Bias_t c;

449
450
451
452
    // [ABA] specific data
    U_t U;
    D_t Dinv;
    UD_t UDinv;
jcarpent's avatar
jcarpent committed
453

454
    JointDataPrismaticUnalignedTpl()
455
456
457
458
    : M(Transformation_t::Vector3::Zero())
    , S(Constraint_t::Vector3::Zero())
    , v(Constraint_t::Vector3::Zero(),(Scalar)0)
    , U(U_t::Zero())
459
460
461
    , Dinv(D_t::Zero())
    , UDinv(UD_t::Zero())
    {}
jcarpent's avatar
jcarpent committed
462
    
463
464
    template<typename Vector3Like>
    JointDataPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
465
    : M()
466
    , S(axis)
467
    , v(axis,(Scalar)NAN)
468
    , U(), Dinv(), UDinv()
jcarpent's avatar
jcarpent committed
469
470
    {}

471
472
473
    static std::string classname() { return std::string("JointDataPrismaticUnaligned"); }
    std::string shortname() const { return classname(); }
    
474
475
  }; // struct JointDataPrismaticUnalignedTpl
  
476
477
478
  template<typename Scalar, int Options>
  struct traits< JointModelPrismaticUnalignedTpl<Scalar,Options> >
  { typedef JointPrismaticUnalignedTpl<Scalar,Options> JointDerived; };
jcarpent's avatar
jcarpent committed
479

Gabriele Buondonno's avatar
Gabriele Buondonno committed
480
  PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelPrismaticUnalignedTpl);
481
  template<typename _Scalar, int _Options>
jcarpent's avatar
jcarpent committed
482
483
  struct JointModelPrismaticUnalignedTpl
  : public JointModelBase< JointModelPrismaticUnalignedTpl<_Scalar,_Options> >
jcarpent's avatar
jcarpent committed
484
  {
485
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
486
    typedef JointPrismaticUnalignedTpl<_Scalar,_Options> JointDerived;
487
    PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
jcarpent's avatar
jcarpent committed
488
489
490
491
492
493
494
495
    
    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
496
    
497
    JointModelPrismaticUnalignedTpl() {}
498
499
500
    JointModelPrismaticUnalignedTpl(const Scalar & x,
                                    const Scalar & y,
                                    const Scalar & z)
501
    : axis(x,y,z)
jcarpent's avatar
jcarpent committed
502
503
    {
      axis.normalize();
504
      assert(isUnitary(axis) && "Translation axis is not unitary");
jcarpent's avatar
jcarpent committed
505
506
    }
    
507
    template<typename Vector3Like>
508
509
    JointModelPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
    : axis(axis)
jcarpent's avatar
jcarpent committed
510
    {
511
      EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
512
      assert(isUnitary(axis) && "Translation axis is not unitary");
jcarpent's avatar
jcarpent committed
513
514
    }

515
    JointDataDerived createData() const { return JointDataDerived(axis); }
jcarpent's avatar
jcarpent committed
516
    
517
518
519
520
521
522
    using Base::isEqual;
    bool isEqual(const JointModelPrismaticUnalignedTpl & other) const
    {
      return Base::isEqual(other) && axis == other.axis;
    }
    
523
524
525
    template<typename ConfigVector>
    void calc(JointDataDerived & data,
              const typename Eigen::MatrixBase<ConfigVector> & qs) const
jcarpent's avatar
jcarpent committed
526
    {
527
528
      typedef typename ConfigVector::Scalar Scalar;
      const Scalar & q = qs[idx_q()];
jcarpent's avatar
jcarpent committed
529

530
      data.M.translation().noalias() = axis * q;
jcarpent's avatar
jcarpent committed
531
532
    }

533
    template<typename ConfigVector, typename TangentVector>
534
    void calc(JointDataDerived & data,
535
536
              const typename Eigen::MatrixBase<ConfigVector> & qs,
              const typename Eigen::MatrixBase<TangentVector> & vs) const
jcarpent's avatar
jcarpent committed
537
    {
538
539
540
541
      calc(data,qs.derived());
      
      typedef typename TangentVector::Scalar S2;
      const S2 & v = vs[idx_v()];
542
      data.v.linearRate() = v;
jcarpent's avatar
jcarpent committed
543
    }
544
    
545
546
    template<typename Matrix6Like>
    void calc_aba(JointDataDerived & data, const Eigen::MatrixBase<Matrix6Like> & I, const bool update_I) const
547
    {
548
      data.U.noalias() = I.template block<6,3> (0,Inertia::LINEAR) * axis;
549
      data.Dinv[0] = Scalar(1)/axis.dot(data.U.template segment <3> (Inertia::LINEAR));
550
      data.UDinv.noalias() = data.U * data.Dinv;
551
552
      
      if (update_I)
gabrielebndn's avatar
gabrielebndn committed
553
        PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
554
    }
555
    
556
    static std::string classname() { return std::string("JointModelPrismaticUnaligned"); }
557
    std::string shortname() const { return classname(); }
558
559
560
561
562
563
564
565
566
567
    
    /// \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;
    }
568
569
570
571
572
573
    
    // data
    
    ///
    /// \brief 3d main axis of the joint.
    ///
574
    Vector3 axis;
575
576
  }; // struct JointModelPrismaticUnalignedTpl
  
577
} //namespace pinocchio
jcarpent's avatar
jcarpent committed
578

579
580
581
582
583
#include <boost/type_traits.hpp>

namespace boost
{
  template<typename Scalar, int Options>
584
  struct has_nothrow_constructor< ::pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> >
585
586
587
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
588
  struct has_nothrow_copy< ::pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> >
589
590
591
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
592
  struct has_nothrow_constructor< ::pinocchio::JointDataPrismaticUnalignedTpl<Scalar,Options> >
593
594
595
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
596
  struct has_nothrow_copy< ::pinocchio::JointDataPrismaticUnalignedTpl<Scalar,Options> >
597
598
599
  : public integral_constant<bool,true> {};
}

jcarpent's avatar
jcarpent committed
600

601
#endif // ifndef __pinocchio_joint_prismatic_unaligned_hpp__