- 3.0.2 models module.
forward_dynamics.impl.h
Go to the documentation of this file.
1 
2 
3 // Initialization of static-const data
4 template<typename TRAIT>
7 
8 template<typename TRAIT>
10  inertiaProps( & inertia ),
11  motionTransforms( & transforms )
12 {
13  link1_v.setZero();
14  link1_c.setZero();
15  link2_v.setZero();
16  link2_c.setZero();
17 
18  vcross.setZero();
19  Ia_r.setZero();
20 
21 }
22 
23 template <typename TRAIT>
25  JointState& qdd,
26  Acceleration& body_a,
27  const Velocity& body_v,
28  const Acceleration& g,
29  const JointState& qd,
30  const JointState& tau,
31  const ExtForces& fext/* = zeroExtForces */)
32 {
33 
34  body_AI = inertiaProps->getTensor_body();
35  body_p = - fext[BODY];
36  link1_AI = inertiaProps->getTensor_link1();
37  link1_p = - fext[LINK1];
38  link2_AI = inertiaProps->getTensor_link2();
39  link2_p = - fext[LINK2];
40  // ---------------------- FIRST PASS ---------------------- //
41  // Note that, during the first pass, the articulated inertias are really
42  // just the spatial inertia of the links (see assignments above).
43  // Afterwards things change, and articulated inertias shall not be used
44  // in functions which work specifically with spatial inertias.
45 
46  // + Link link1
47  // - The spatial velocity:
48  link1_v = (motionTransforms-> fr_link1_X_fr_body) * body_v;
49  link1_v(rbd::AZ) += qd(JA);
50 
51  // - The velocity-product acceleration term:
52  iit::rbd::motionCrossProductMx<SCALAR>(link1_v, vcross);
53  link1_c = vcross.col(rbd::AZ) * qd(JA);
54 
55  // - The bias force term:
56  link1_p += iit::rbd::vxIv(link1_v, link1_AI);
57 
58  // + Link link2
59  // - The spatial velocity:
60  link2_v = (motionTransforms-> fr_link2_X_fr_link1) * link1_v;
61  link2_v(rbd::AZ) += qd(JB);
62 
63  // - The velocity-product acceleration term:
64  iit::rbd::motionCrossProductMx<SCALAR>(link2_v, vcross);
65  link2_c = vcross.col(rbd::AZ) * qd(JB);
66 
67  // - The bias force term:
68  link2_p += iit::rbd::vxIv(link2_v, link2_AI);
69 
70  // + The floating base body
71  body_p += iit::rbd::vxIv(body_v, body_AI);
72 
73  // ---------------------- SECOND PASS ---------------------- //
74  Matrix66S IaB;
75  Force pa;
76 
77  // + Link link2
78  link2_u = tau(JB) - link2_p(rbd::AZ);
79  link2_U = link2_AI.col(rbd::AZ);
80  link2_D = link2_U(rbd::AZ);
81 
82  iit::rbd::compute_Ia_revolute(link2_AI, link2_U, link2_D, Ia_r); // same as: Ia_r = link2_AI - link2_U/link2_D * link2_U.transpose();
83  pa = link2_p + Ia_r * link2_c + link2_U * link2_u/link2_D;
84  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_link2_X_fr_link1, IaB);
85  link1_AI += IaB;
86  link1_p += (motionTransforms-> fr_link2_X_fr_link1).transpose() * pa;
87 
88  // + Link link1
89  link1_u = tau(JA) - link1_p(rbd::AZ);
90  link1_U = link1_AI.col(rbd::AZ);
91  link1_D = link1_U(rbd::AZ);
92 
93  iit::rbd::compute_Ia_revolute(link1_AI, link1_U, link1_D, Ia_r); // same as: Ia_r = link1_AI - link1_U/link1_D * link1_U.transpose();
94  pa = link1_p + Ia_r * link1_c + link1_U * link1_u/link1_D;
95  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_link1_X_fr_body, IaB);
96  body_AI += IaB;
97  body_p += (motionTransforms-> fr_link1_X_fr_body).transpose() * pa;
98 
99  // + The acceleration of the floating base body, without gravity
100  body_a = - TRAIT::solve(body_AI, body_p); // body_a = - IA^-1 * body_p
101 
102  // ---------------------- THIRD PASS ---------------------- //
103  link1_a = (motionTransforms-> fr_link1_X_fr_body) * body_a + link1_c;
104  qdd(JA) = (link1_u - link1_U.dot(link1_a)) / link1_D;
105  link1_a(rbd::AZ) += qdd(JA);
106 
107  link2_a = (motionTransforms-> fr_link2_X_fr_link1) * link1_a + link2_c;
108  qdd(JB) = (link2_u - link2_U.dot(link2_a)) / link2_D;
109  link2_a(rbd::AZ) += qdd(JB);
110 
111 
112  // + Add gravity to the acceleration of the floating base
113  body_a += g;
114 }
Definition: forward_dynamics.h:34
void compute_Ia_revolute(const MatrixBase< D1 > &IA, const Vec6< typename D1::Scalar > &U, const typename D1::Scalar &D, const MatrixBase< D2 > &Ia_const)
CoreS::Matrix66 Matrix66S
Definition: forward_dynamics.h:49
Definition: declarations.h:27
Definition: declarations.h:32
CoreS::ForceVector Force
Definition: forward_dynamics.h:44
Force< DScalar > vxIv(const Velocity< DScalar > &v, const MatrixBase< Derived > &I)
Definition: declarations.h:31
Definition: inertia_properties.h:25
ForwardDynamics(iit::ct_quadrotor::dyn::tpl::InertiaProperties< TRAIT > &in, MotionTransforms &tr)
Definition: forward_dynamics.impl.h:9
Definition: link_data_map.h:12
CoreS::VelocityVector Acceleration
Definition: forward_dynamics.h:46
CoreS::VelocityVector Velocity
Definition: forward_dynamics.h:45
iit::ct_quadrotor::tpl::JointState< SCALAR > JointState
Definition: forward_dynamics.h:48
void fd(JointState &qdd, Acceleration &body_a, const Velocity &body_v, const Acceleration &g, const JointState &q, const JointState &qd, const JointState &tau, const ExtForces &fext=zeroExtForces)
Definition: forward_dynamics.h:133
Definition: declarations.h:33
void ctransform_Ia_revolute(const MatrixBase< D1 > &Ia_A, const MatrixBase< D2 > &XM, const MatrixBase< D3 > &Ia_B_const)
Definition: declarations.h:26