joint-revolute-unaligned.hpp 21.1 KB
Newer Older
1
//
2
// Copyright (c) 2015-2019 CNRS INRIA
3
// Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4
5
//

6
7
#ifndef __pinocchio_joint_revolute_unaligned_hpp__
#define __pinocchio_joint_revolute_unaligned_hpp__
8

9
#include "pinocchio/fwd.hpp"
10
11
12
#include "pinocchio/multibody/joint/joint-base.hpp"
#include "pinocchio/multibody/constraint.hpp"
#include "pinocchio/spatial/inertia.hpp"
13
#include "pinocchio/math/matrix.hpp"
14

15
namespace pinocchio
16
17
{

18
19
  template<typename Scalar, int Options=0> struct MotionRevoluteUnalignedTpl;
  typedef MotionRevoluteUnalignedTpl<double> MotionRevoluteUnaligned;
20
  
21
22
  template<typename Scalar, int Options>
  struct SE3GroupAction< MotionRevoluteUnalignedTpl<Scalar,Options> >
23
  {
24
25
26
27
28
29
30
31
    typedef MotionTpl<Scalar,Options> ReturnType;
  };
  
  template<typename Scalar, int Options, typename MotionDerived>
  struct MotionAlgebraAction< MotionRevoluteUnalignedTpl<Scalar,Options>, MotionDerived>
  {
    typedef MotionTpl<Scalar,Options> ReturnType;
  };
32

33
34
  template<typename _Scalar, int _Options>
  struct traits< MotionRevoluteUnalignedTpl<_Scalar,_Options> >
35
  {
36
37
38
39
40
    typedef _Scalar Scalar;
    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
41
42
    typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
    typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
43
44
45
46
47
    typedef Vector3 AngularType;
    typedef Vector3 LinearType;
    typedef const Vector3 ConstAngularType;
    typedef const Vector3 ConstLinearType;
    typedef Matrix6 ActionMatrixType;
48
    typedef MotionTpl<Scalar,Options> MotionPlain;
49
    typedef MotionPlain PlainReturnType;
50
51
52
    enum {
      LINEAR = 0,
      ANGULAR = 3
53
    };
54
  }; // traits MotionRevoluteUnalignedTpl
55

56
  template<typename _Scalar, int _Options>
57
58
  struct MotionRevoluteUnalignedTpl
  : MotionBase< MotionRevoluteUnalignedTpl<_Scalar,_Options> >
59
  {
60
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
61
    MOTION_TYPEDEF_TPL(MotionRevoluteUnalignedTpl);
62

63
    MotionRevoluteUnalignedTpl() {}
64
65
66
67
    
    template<typename Vector3Like, typename OtherScalar>
    MotionRevoluteUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis,
                               const OtherScalar & w)
68
69
    : m_axis(axis)
    , m_w(w)
70
    {}
71
    
72
    inline PlainReturnType plain() const
73
    {
74
      return PlainReturnType(PlainReturnType::Vector3::Zero(),
75
                             m_axis*m_w);
76
77
78
79
80
    }
    
    template<typename OtherScalar>
    MotionRevoluteUnalignedTpl __mult__(const OtherScalar & alpha) const
    {
81
      return MotionRevoluteUnalignedTpl(m_axis,alpha*m_w);
82
    }
83
    
84
    template<typename MotionDerived>
85
    inline void addTo(MotionDense<MotionDerived> & v) const
86
    {
87
      v.angular() += m_axis*m_w;
88
    }
89
90
91
92
93
    
    template<typename Derived>
    void setTo(MotionDense<Derived> & other) const
    {
      other.linear().setZero();
94
      other.angular().noalias() = m_axis*m_w;
95
    }
96
97
98
99
100

    template<typename S2, int O2, typename D2>
    void se3Action_impl(const SE3Tpl<S2,O2> & m, MotionDense<D2> & v) const
    {
      // Angular
101
      v.angular().noalias() = m_w * m.rotation() * m_axis;
102

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      // Linear
      v.linear().noalias() = m.translation().cross(v.angular());
    }
    
    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
      // TODO: use v.angular() as temporary variable
      Vector3 v3_tmp;
121
122
      v3_tmp.noalias() = m_axis.cross(m.translation());
      v3_tmp *= m_w;
123
124
125
      v.linear().noalias() = m.rotation().transpose() * v3_tmp;
      
      // Angular
126
127
      v.angular().noalias() = m.rotation().transpose() * m_axis;
      v.angular() *= m_w;
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    }
    
    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
142
143
      mout.linear().noalias() = v.linear().cross(m_axis);
      mout.linear() *= m_w;
144
145
      
      // Angular
146
147
      mout.angular().noalias() = v.angular().cross(m_axis);
      mout.angular() *= m_w;
148
149
150
151
152
153
154
155
156
    }
    
    template<typename M1>
    MotionPlain motionAction(const MotionDense<M1> & v) const
    {
      MotionPlain res;
      motionAction(v,res);
      return res;
    }
157
    
158
159
160
161
162
163
164
165
166
167
168
169
170
171
    bool isEqual_impl(const MotionRevoluteUnalignedTpl & other) const
    {
      return m_axis == other.m_axis && m_w == other.m_w;
    }
    
    const Scalar & angularRate() const { return m_w; }
    Scalar & angularRate() { return m_w; }
    
    const Vector3 & axis() const { return m_axis; }
    Vector3 & axis() { return m_axis; }
    
  protected:
    Vector3 m_axis;
    Scalar m_w;
172
173
    
  }; // struct MotionRevoluteUnalignedTpl
174

175
176
  template<typename S1, int O1, typename MotionDerived>
  inline typename MotionDerived::MotionPlain
177
178
  operator+(const MotionRevoluteUnalignedTpl<S1,O1> & m1,
            const MotionDense<MotionDerived> & m2)
179
  {
180
181
182
    typename MotionDerived::MotionPlain res(m2);
    res += m1;
    return res;
183
  }
184
185
186
187
188
189
190
191
  
  template<typename MotionDerived, typename S2, int O2>
  inline typename MotionDerived::MotionPlain
  operator^(const MotionDense<MotionDerived> & m1,
            const MotionRevoluteUnalignedTpl<S2,O2> & m2)
  {
    return m2.motionAction(m1);
  }
192

193
194
195
196
  template<typename Scalar, int Options> struct ConstraintRevoluteUnalignedTpl;
  
  template<typename _Scalar, int _Options>
  struct traits< ConstraintRevoluteUnalignedTpl<_Scalar,_Options> >
197
  {
198
199
    typedef _Scalar Scalar;
    enum { Options = _Options };
200
201
202
203
    enum {
      LINEAR = 0,
      ANGULAR = 3
    };
204
    typedef MotionRevoluteUnalignedTpl<Scalar,Options> JointMotion;
205
206
    typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
    typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
207
208
    typedef DenseBase MatrixReturnType;
    typedef const DenseBase ConstMatrixReturnType;
209
210
    
    typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
211
  }; // traits ConstraintRevoluteUnalignedTpl
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
  
  template<typename Scalar, int Options>
  struct SE3GroupAction< ConstraintRevoluteUnalignedTpl<Scalar,Options> >
  { typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
  
  template<typename Scalar, int Options, typename MotionDerived>
  struct MotionAlgebraAction< ConstraintRevoluteUnalignedTpl<Scalar,Options>, MotionDerived >
  { typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
  
  template<typename Scalar, int Options, typename ForceDerived>
  struct ConstraintForceOp< ConstraintRevoluteUnalignedTpl<Scalar,Options>, ForceDerived>
  {
    typedef typename traits< ConstraintRevoluteUnalignedTpl<Scalar,Options> >::Vector3 Vector3;
    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>
  struct ConstraintForceSetOp< ConstraintRevoluteUnalignedTpl<Scalar,Options>, ForceSet>
  {
    typedef typename traits< ConstraintRevoluteUnalignedTpl<Scalar,Options> >::Vector3 Vector3;
    typedef typename MatrixMatrixProduct<Eigen::Transpose<const Vector3>,
    typename Eigen::MatrixBase<const ForceSet>::template NRowsBlockXpr<3>::Type
    >::type ReturnType;
  };
236

237
  template<typename _Scalar, int _Options>
238
239
  struct ConstraintRevoluteUnalignedTpl
  : ConstraintBase< ConstraintRevoluteUnalignedTpl<_Scalar,_Options> >
240
  {
241
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
242
243
    PINOCCHIO_CONSTRAINT_TYPEDEF_TPL(ConstraintRevoluteUnalignedTpl)
    
244
    enum { NV = 1 };
245
    
246
    typedef typename traits<ConstraintRevoluteUnalignedTpl>::Vector3 Vector3;
247
    
248
    ConstraintRevoluteUnalignedTpl() {}
249
250
251
    
    template<typename Vector3Like>
    ConstraintRevoluteUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
252
    : m_axis(axis)
253
254
    {}
    
255
256
    template<typename Vector1Like>
    JointMotion __mult__(const Eigen::MatrixBase<Vector1Like> & v) const
257
    {
258
      EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like,1);
259
      return JointMotion(m_axis,v[0]);
260
261
262
    }
    
    template<typename S1, int O1>
263
264
    typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType
    se3Action(const SE3Tpl<S1,O1> & m) const
265
    {
266
267
      typedef typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType ReturnType;
      
268
      /* X*S = [ R pxR ; 0 R ] [ 0 ; a ] = [ px(Ra) ; Ra ] */
269
      ReturnType res;
270
      res.template segment<3>(ANGULAR).noalias() = m.rotation() * m_axis;
271
272
273
274
      res.template segment<3>(LINEAR).noalias() = m.translation().cross(res.template segment<3>(ANGULAR));
      return res;
    }
    
275
276
277
278
279
280
281
    template<typename S1, int O1>
    typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType
    se3ActionInverse(const SE3Tpl<S1,O1> & m) const
    {
      typedef typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType ReturnType;
      
      ReturnType res;
282
283
      res.template segment<3>(ANGULAR).noalias() = m.rotation().transpose() * m_axis;
      res.template segment<3>(LINEAR).noalias() = -m.rotation().transpose() * m.translation().cross(m_axis);
284
285
286
      return res;
    }
    
287
288
289
290
291
292
293
    int nv_impl() const { return NV; }
    
    struct TransposeConst
    {
      const ConstraintRevoluteUnalignedTpl & ref;
      TransposeConst(const ConstraintRevoluteUnalignedTpl & ref) : ref(ref) {}
      
294
295
296
      template<typename ForceDerived>
      typename ConstraintForceOp<ConstraintRevoluteUnalignedTpl,ForceDerived>::ReturnType
      operator*(const ForceDense<ForceDerived> & f) const
297
      {
298
        typedef typename ConstraintForceOp<ConstraintRevoluteUnalignedTpl,ForceDerived>::ReturnType ReturnType;
299
        ReturnType res;
300
        res[0] = ref.axis().dot(f.angular());
301
        return res;
302
303
304
      }
      
      /* [CRBA]  MatrixBase operator* (Constraint::Transpose S, ForceSet::Block) */
305
306
307
      template<typename ForceSet>
      typename ConstraintForceSetOp<ConstraintRevoluteUnalignedTpl,ForceSet>::ReturnType
      operator*(const Eigen::MatrixBase<ForceSet> & F)
308
      {
309
        EIGEN_STATIC_ASSERT(ForceSet::RowsAtCompileTime==6,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
310
        /* Return ax.T * F[3:end,:] */
311
        return ref.axis().transpose() * F.template middleRows<3>(ANGULAR);
312
313
      }
      
314
315
316
317
318
319
320
321
322
323
324
    };
    
    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
325
    {
326
      DenseBase S;
327
328
      S.template segment<3>(LINEAR).setZero();
      S.template segment<3>(ANGULAR) = m_axis;
329
      return S;
330
    }
331
332
    
    template<typename MotionDerived>
333
334
    typename MotionAlgebraAction<ConstraintRevoluteUnalignedTpl,MotionDerived>::ReturnType
    motionAction(const MotionDense<MotionDerived> & m) const
335
336
337
338
339
    {
      const typename MotionDerived::ConstLinearType v = m.linear();
      const typename MotionDerived::ConstAngularType w = m.angular();
      
      DenseBase res;
340
341
      res.template segment<3>(LINEAR).noalias() = v.cross(m_axis);
      res.template segment<3>(ANGULAR).noalias() = w.cross(m_axis);
342
      
343
344
      return res;
    }
345
    
346
347
348
    const Vector3 & axis() const { return m_axis; }
    Vector3 & axis() { return m_axis; }
    
349
350
351
352
353
    bool isEqual(const ConstraintRevoluteUnalignedTpl & other) const
    {
      return m_axis == other.m_axis;
    }
    
354
355
356
  protected:
    
    Vector3 m_axis;
357
358
359
    
  }; // struct ConstraintRevoluteUnalignedTpl
  
360
361
  template<typename S1, int O1,typename S2, int O2>
  struct MultiplicationOp<InertiaTpl<S1,O1>, ConstraintRevoluteUnalignedTpl<S2,O2> >
362
  {
363
364
    typedef Eigen::Matrix<S2,6,1,O2> ReturnType;
  };
365
366
  
  /* [CRBA] ForceSet operator* (Inertia Y,Constraint S) */
367
  namespace impl
368
  {
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
    template<typename S1, int O1, typename S2, int O2>
    struct LhsMultiplicationOp<InertiaTpl<S1,O1>, ConstraintRevoluteUnalignedTpl<S2,O2> >
    {
      typedef InertiaTpl<S1,O1> Inertia;
      typedef ConstraintRevoluteUnalignedTpl<S2,O2> Constraint;
      typedef typename MultiplicationOp<Inertia,Constraint>::ReturnType ReturnType;
      static inline ReturnType run(const Inertia & Y,
                                   const Constraint & cru)
      {
        ReturnType res;
        
        /* YS = [ m -mcx ; mcx I-mcxcx ] [ 0 ; w ] = [ mcxw ; Iw -mcxcxw ] */
        const typename Inertia::Scalar & m       = Y.mass();
        const typename Inertia::Vector3 & c      = Y.lever();
        const typename Inertia::Symmetric3 & I   = Y.inertia();

385
386
        res.template segment<3>(Inertia::LINEAR) = -m*c.cross(cru.axis());
        res.template segment<3>(Inertia::ANGULAR).noalias() = I*cru.axis();
387
388
389
390
391
392
        res.template segment<3>(Inertia::ANGULAR) += c.cross(res.template segment<3>(Inertia::LINEAR));
        
        return res;
      }
    };
  } // namespace impl
393
  
394
395
  template<typename M6Like, typename Scalar, int Options>
  struct MultiplicationOp<Eigen::MatrixBase<M6Like>, ConstraintRevoluteUnalignedTpl<Scalar,Options> >
396
  {
397
398
399
400
401
402
403
    typedef typename SizeDepType<3>::ColsReturn<M6Like>::ConstType M6LikeCols;
    typedef typename Eigen::internal::remove_const<M6LikeCols>::type M6LikeColsNonConst;
    
    typedef ConstraintRevoluteUnalignedTpl<Scalar,Options> Constraint;
    typedef typename Constraint::Vector3 Vector3;
    typedef const typename MatrixMatrixProduct<M6LikeColsNonConst,Vector3>::type ReturnType;
  };
404
  
405
406
407
408
409
410
411
412
413
414
415
416
417
  /* [ABA] operator* (Inertia Y,Constraint S) */
  namespace impl
  {
    template<typename M6Like, typename Scalar, int Options>
    struct LhsMultiplicationOp<Eigen::MatrixBase<M6Like>, ConstraintRevoluteUnalignedTpl<Scalar,Options> >
    {
      typedef ConstraintRevoluteUnalignedTpl<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);
418
        return Y.derived().template middleCols<3>(Constraint::ANGULAR) * cru.axis();
419
420
421
422
      }
    };
  } // namespace impl

423
424
425
426
427
428
429
430
  template<typename Scalar, int Options> struct JointRevoluteUnalignedTpl;
  
  template<typename _Scalar, int _Options>
  struct traits< JointRevoluteUnalignedTpl<_Scalar,_Options> >
  {
    enum {
      NQ = 1,
      NV = 1
431
    };
432
433
434
435
436
437
438
    typedef _Scalar Scalar;
    enum { Options = _Options };
    typedef JointDataRevoluteUnalignedTpl<Scalar,Options> JointDataDerived;
    typedef JointModelRevoluteUnalignedTpl<Scalar,Options> JointModelDerived;
    typedef ConstraintRevoluteUnalignedTpl<Scalar,Options> Constraint_t;
    typedef SE3Tpl<Scalar,Options> Transformation_t;
    typedef MotionRevoluteUnalignedTpl<Scalar,Options> Motion_t;
439
    typedef MotionZeroTpl<Scalar,Options> Bias_t;
Justin Carpentier's avatar
Justin Carpentier committed
440

441
442
443
444
445
    // [ABA]
    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;
    
Gabriele Buondonno's avatar
Gabriele Buondonno committed
446
    PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
447
    
448
449
450
451
    typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
    typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
    
  };
452

453
454
455
456
457
458
459
  template<typename Scalar, int Options>
  struct traits< JointDataRevoluteUnalignedTpl<Scalar,Options> >
  { typedef JointRevoluteUnalignedTpl<Scalar,Options> JointDerived; };
  
  template<typename Scalar, int Options>
  struct traits <JointModelRevoluteUnalignedTpl<Scalar,Options> >
  { typedef JointRevoluteUnalignedTpl<Scalar,Options> JointDerived; };
460

461
  template<typename _Scalar, int _Options>
462
463
  struct JointDataRevoluteUnalignedTpl
  : public JointDataBase< JointDataRevoluteUnalignedTpl<_Scalar,_Options> >
464
  {
465
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
466
    typedef JointRevoluteUnalignedTpl<_Scalar,_Options> JointDerived;
467
    PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
Gabriele Buondonno's avatar
Gabriele Buondonno committed
468
    PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
469
470
471
472
473
474

    Transformation_t M;
    Constraint_t S;
    Motion_t v;
    Bias_t c;

475
476
477
478
    // [ABA] specific data
    U_t U;
    D_t Dinv;
    UD_t UDinv;
479

480
    JointDataRevoluteUnalignedTpl()
481
482
483
484
    : M(Transformation_t::Identity())
    , S(Constraint_t::Vector3::Zero())
    , v(Constraint_t::Vector3::Zero(),(Scalar)0)
    , U(U_t::Zero())
485
486
487
    , Dinv(D_t::Zero())
    , UDinv(UD_t::Zero())
    {}
488
    
489
490
    template<typename Vector3Like>
    JointDataRevoluteUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
491
    : M(Transformation_t::Identity())
492
493
    , S(axis)
    , v(axis,(Scalar)NAN)
494
495
496
    , U(U_t::Zero())
    , Dinv(D_t::Zero())
    , UDinv(UD_t::Zero())
497
    {}
498

499
500
501
    static std::string classname() { return std::string("JointDataRevoluteUnaligned"); }
    std::string shortname() const { return classname(); }
    
502
  }; // struct JointDataRevoluteUnalignedTpl
503

Gabriele Buondonno's avatar
Gabriele Buondonno committed
504
  PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelRevoluteUnalignedTpl);
505
  template<typename _Scalar, int _Options>
jcarpent's avatar
jcarpent committed
506
507
  struct JointModelRevoluteUnalignedTpl
  : public JointModelBase< JointModelRevoluteUnalignedTpl<_Scalar,_Options> >
508
  {
509
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
510
    typedef JointRevoluteUnalignedTpl<_Scalar,_Options> JointDerived;
511
    PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
jcarpent's avatar
jcarpent committed
512
513
514
515
516
517
518
    typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
    
    typedef JointModelBase<JointModelRevoluteUnalignedTpl> Base;
    using Base::id;
    using Base::idx_q;
    using Base::idx_v;
    using Base::setIndexes;
519
    
520
    JointModelRevoluteUnalignedTpl() {}
521
    
522
523
524
    JointModelRevoluteUnalignedTpl(const Scalar & x,
                                   const Scalar & y,
                                   const Scalar & z)
525
    : axis(x,y,z)
526
527
    {
      axis.normalize();
528
      assert(isUnitary(axis) && "Rotation axis is not unitary");
529
    }
530
531
532
533
    
    template<typename Vector3Like>
    JointModelRevoluteUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
    : axis(axis)
534
    {
535
      EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
536
      assert(isUnitary(axis) && "Rotation axis is not unitary");
537
538
    }

539
    JointDataDerived createData() const { return JointDataDerived(axis); }
540
    
541
542
543
544
545
546
    using Base::isEqual;
    bool isEqual(const JointModelRevoluteUnalignedTpl & other) const
    {
      return Base::isEqual(other) && axis == other.axis;
    }
    
547
548
549
    template<typename ConfigVector>
    void calc(JointDataDerived & data,
              const typename Eigen::MatrixBase<ConfigVector> & qs) const
550
    {
551
552
      typedef typename ConfigVector::Scalar OtherScalar;
      typedef Eigen::AngleAxis<Scalar> AngleAxis;
553
      
554
555
556
      const OtherScalar & q = qs[idx_q()];
      
      data.M.rotation(AngleAxis(q,axis).toRotationMatrix());
557
558
    }

559
560
561
562
    template<typename ConfigVector, typename TangentVector>
    void calc(JointDataDerived & data,
              const typename Eigen::MatrixBase<ConfigVector> & qs,
              const typename Eigen::MatrixBase<TangentVector> & vs) const
563
    {
564
      calc(data,qs.derived());
565

566
      data.v.angularRate() = static_cast<Scalar>(vs[idx_v()]);
567
    }
568
    
569
570
    template<typename Matrix6Like>
    void calc_aba(JointDataDerived & data, const Eigen::MatrixBase<Matrix6Like> & I, const bool update_I) const
571
    {
572
573
      data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) * axis;
      data.Dinv[0] = (Scalar)(1)/axis.dot(data.U.template segment<3>(Motion::ANGULAR));
574
      data.UDinv.noalias() = data.U * data.Dinv;
575
576
      
      if (update_I)
gabrielebndn's avatar
gabrielebndn committed
577
        PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
578
    }
579
    
580
581
    static std::string classname() { return std::string("JointModelRevoluteUnaligned"); }
    std::string shortname() const { return classname(); }
582
583
584
585
586
587
588
589
590
591
    
    /// \returns An expression of *this with the Scalar type casted to NewScalar.
    template<typename NewScalar>
    JointModelRevoluteUnalignedTpl<NewScalar,Options> cast() const
    {
      typedef JointModelRevoluteUnalignedTpl<NewScalar,Options> ReturnType;
      ReturnType res(axis.template cast<NewScalar>());
      res.setIndexes(id(),idx_q(),idx_v());
      return res;
    }
592

593
594
595
596
597
    // data
    
    ///
    /// \brief 3d main axis of the joint.
    ///
598
599
    Vector3 axis;
  }; // struct JointModelRevoluteUnalignedTpl
600

601
} //namespace pinocchio
602

603
604
605
606
607
#include <boost/type_traits.hpp>

namespace boost
{
  template<typename Scalar, int Options>
608
  struct has_nothrow_constructor< ::pinocchio::JointModelRevoluteUnalignedTpl<Scalar,Options> >
609
610
611
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
612
  struct has_nothrow_copy< ::pinocchio::JointModelRevoluteUnalignedTpl<Scalar,Options> >
613
614
615
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
616
  struct has_nothrow_constructor< ::pinocchio::JointDataRevoluteUnalignedTpl<Scalar,Options> >
617
618
619
  : public integral_constant<bool,true> {};
  
  template<typename Scalar, int Options>
620
  struct has_nothrow_copy< ::pinocchio::JointDataRevoluteUnalignedTpl<Scalar,Options> >
621
622
623
  : public integral_constant<bool,true> {};
}

624

625
#endif // ifndef __pinocchio_joint_revolute_unaligned_hpp__