- 3.0.2 rigid body dynamics 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  link3_v.setZero();
18  link3_c.setZero();
19  link4_v.setZero();
20  link4_c.setZero();
21  link5_v.setZero();
22  link5_c.setZero();
23  link6_v.setZero();
24  link6_c.setZero();
25 
26  vcross.setZero();
27  Ia_r.setZero();
28 
29 }
30 
31 template <typename TRAIT>
33  JointState& qdd,
34  const JointState& qd,
35  const JointState& tau,
36  const ExtForces& fext/* = zeroExtForces */)
37 {
38 
39  link1_AI = inertiaProps->getTensor_link1();
40  link1_p = - fext[LINK1];
41  link2_AI = inertiaProps->getTensor_link2();
42  link2_p = - fext[LINK2];
43  link3_AI = inertiaProps->getTensor_link3();
44  link3_p = - fext[LINK3];
45  link4_AI = inertiaProps->getTensor_link4();
46  link4_p = - fext[LINK4];
47  link5_AI = inertiaProps->getTensor_link5();
48  link5_p = - fext[LINK5];
49  link6_AI = inertiaProps->getTensor_link6();
50  link6_p = - fext[LINK6];
51  // ---------------------- FIRST PASS ---------------------- //
52  // Note that, during the first pass, the articulated inertias are really
53  // just the spatial inertia of the links (see assignments above).
54  // Afterwards things change, and articulated inertias shall not be used
55  // in functions which work specifically with spatial inertias.
56 
57  // + Link link1
58  // - The spatial velocity:
59  link1_v(rbd::AZ) = qd(JA);
60 
61  // - The bias force term:
62  link1_p += iit::rbd::vxIv(qd(JA), link1_AI);
63 
64  // + Link link2
65  // - The spatial velocity:
66  link2_v = (motionTransforms-> fr_link2_X_fr_link1) * link1_v;
67  link2_v(rbd::AZ) += qd(JB);
68 
69  // - The velocity-product acceleration term:
70  iit::rbd::motionCrossProductMx<SCALAR>(link2_v, vcross);
71  link2_c = vcross.col(rbd::AZ) * qd(JB);
72 
73  // - The bias force term:
74  link2_p += iit::rbd::vxIv(link2_v, link2_AI);
75 
76  // + Link link3
77  // - The spatial velocity:
78  link3_v = (motionTransforms-> fr_link3_X_fr_link2) * link2_v;
79  link3_v(rbd::AZ) += qd(JC);
80 
81  // - The velocity-product acceleration term:
82  iit::rbd::motionCrossProductMx<SCALAR>(link3_v, vcross);
83  link3_c = vcross.col(rbd::AZ) * qd(JC);
84 
85  // - The bias force term:
86  link3_p += iit::rbd::vxIv(link3_v, link3_AI);
87 
88  // + Link link4
89  // - The spatial velocity:
90  link4_v = (motionTransforms-> fr_link4_X_fr_link3) * link3_v;
91  link4_v(rbd::AZ) += qd(JD);
92 
93  // - The velocity-product acceleration term:
94  iit::rbd::motionCrossProductMx<SCALAR>(link4_v, vcross);
95  link4_c = vcross.col(rbd::AZ) * qd(JD);
96 
97  // - The bias force term:
98  link4_p += iit::rbd::vxIv(link4_v, link4_AI);
99 
100  // + Link link5
101  // - The spatial velocity:
102  link5_v = (motionTransforms-> fr_link5_X_fr_link4) * link4_v;
103  link5_v(rbd::AZ) += qd(JE);
104 
105  // - The velocity-product acceleration term:
106  iit::rbd::motionCrossProductMx<SCALAR>(link5_v, vcross);
107  link5_c = vcross.col(rbd::AZ) * qd(JE);
108 
109  // - The bias force term:
110  link5_p += iit::rbd::vxIv(link5_v, link5_AI);
111 
112  // + Link link6
113  // - The spatial velocity:
114  link6_v = (motionTransforms-> fr_link6_X_fr_link5) * link5_v;
115  link6_v(rbd::AZ) += qd(JF);
116 
117  // - The velocity-product acceleration term:
118  iit::rbd::motionCrossProductMx<SCALAR>(link6_v, vcross);
119  link6_c = vcross.col(rbd::AZ) * qd(JF);
120 
121  // - The bias force term:
122  link6_p += iit::rbd::vxIv(link6_v, link6_AI);
123 
124 
125  // ---------------------- SECOND PASS ---------------------- //
126  Matrix66S IaB;
127  Force pa;
128 
129  // + Link link6
130  link6_u = tau(JF) - link6_p(rbd::AZ);
131  link6_U = link6_AI.col(rbd::AZ);
132  link6_D = link6_U(rbd::AZ);
133 
134  iit::rbd::compute_Ia_revolute(link6_AI, link6_U, link6_D, Ia_r); // same as: Ia_r = link6_AI - link6_U/link6_D * link6_U.transpose();
135  pa = link6_p + Ia_r * link6_c + link6_U * link6_u/link6_D;
136  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_link6_X_fr_link5, IaB);
137  link5_AI += IaB;
138  link5_p += (motionTransforms-> fr_link6_X_fr_link5).transpose() * pa;
139 
140  // + Link link5
141  link5_u = tau(JE) - link5_p(rbd::AZ);
142  link5_U = link5_AI.col(rbd::AZ);
143  link5_D = link5_U(rbd::AZ);
144 
145  iit::rbd::compute_Ia_revolute(link5_AI, link5_U, link5_D, Ia_r); // same as: Ia_r = link5_AI - link5_U/link5_D * link5_U.transpose();
146  pa = link5_p + Ia_r * link5_c + link5_U * link5_u/link5_D;
147  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_link5_X_fr_link4, IaB);
148  link4_AI += IaB;
149  link4_p += (motionTransforms-> fr_link5_X_fr_link4).transpose() * pa;
150 
151  // + Link link4
152  link4_u = tau(JD) - link4_p(rbd::AZ);
153  link4_U = link4_AI.col(rbd::AZ);
154  link4_D = link4_U(rbd::AZ);
155 
156  iit::rbd::compute_Ia_revolute(link4_AI, link4_U, link4_D, Ia_r); // same as: Ia_r = link4_AI - link4_U/link4_D * link4_U.transpose();
157  pa = link4_p + Ia_r * link4_c + link4_U * link4_u/link4_D;
158  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_link4_X_fr_link3, IaB);
159  link3_AI += IaB;
160  link3_p += (motionTransforms-> fr_link4_X_fr_link3).transpose() * pa;
161 
162  // + Link link3
163  link3_u = tau(JC) - link3_p(rbd::AZ);
164  link3_U = link3_AI.col(rbd::AZ);
165  link3_D = link3_U(rbd::AZ);
166 
167  iit::rbd::compute_Ia_revolute(link3_AI, link3_U, link3_D, Ia_r); // same as: Ia_r = link3_AI - link3_U/link3_D * link3_U.transpose();
168  pa = link3_p + Ia_r * link3_c + link3_U * link3_u/link3_D;
169  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_link3_X_fr_link2, IaB);
170  link2_AI += IaB;
171  link2_p += (motionTransforms-> fr_link3_X_fr_link2).transpose() * pa;
172 
173  // + Link link2
174  link2_u = tau(JB) - link2_p(rbd::AZ);
175  link2_U = link2_AI.col(rbd::AZ);
176  link2_D = link2_U(rbd::AZ);
177 
178  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();
179  pa = link2_p + Ia_r * link2_c + link2_U * link2_u/link2_D;
180  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_link2_X_fr_link1, IaB);
181  link1_AI += IaB;
182  link1_p += (motionTransforms-> fr_link2_X_fr_link1).transpose() * pa;
183 
184  // + Link link1
185  link1_u = tau(JA) - link1_p(rbd::AZ);
186  link1_U = link1_AI.col(rbd::AZ);
187  link1_D = link1_U(rbd::AZ);
188 
189 
190 
191  // ---------------------- THIRD PASS ---------------------- //
192  link1_a = (motionTransforms-> fr_link1_X_fr_link0).col(rbd::LZ) * SCALAR(iit::rbd::g);
193  qdd(JA) = (link1_u - link1_U.dot(link1_a)) / link1_D;
194  link1_a(rbd::AZ) += qdd(JA);
195 
196  link2_a = (motionTransforms-> fr_link2_X_fr_link1) * link1_a + link2_c;
197  qdd(JB) = (link2_u - link2_U.dot(link2_a)) / link2_D;
198  link2_a(rbd::AZ) += qdd(JB);
199 
200  link3_a = (motionTransforms-> fr_link3_X_fr_link2) * link2_a + link3_c;
201  qdd(JC) = (link3_u - link3_U.dot(link3_a)) / link3_D;
202  link3_a(rbd::AZ) += qdd(JC);
203 
204  link4_a = (motionTransforms-> fr_link4_X_fr_link3) * link3_a + link4_c;
205  qdd(JD) = (link4_u - link4_U.dot(link4_a)) / link4_D;
206  link4_a(rbd::AZ) += qdd(JD);
207 
208  link5_a = (motionTransforms-> fr_link5_X_fr_link4) * link4_a + link5_c;
209  qdd(JE) = (link5_u - link5_U.dot(link5_a)) / link5_D;
210  link5_a(rbd::AZ) += qdd(JE);
211 
212  link6_a = (motionTransforms-> fr_link6_X_fr_link5) * link5_a + link6_c;
213  qdd(JF) = (link6_u - link6_U.dot(link6_a)) / link6_D;
214  link6_a(rbd::AZ) += qdd(JF);
215 
216 
217 }
CoreS::Matrix66 Matrix66S
Definition: forward_dynamics.h:49
Definition: declarations.h:38
void compute_Ia_revolute(const MatrixBase< D1 > &IA, const Vec6< typename D1::Scalar > &U, const typename D1::Scalar &D, const MatrixBase< D2 > &Ia_const)
Definition: robcogen_commons.h:595
Definition: declarations.h:37
iit::testirb4600::tpl::MotionTransforms< TRAIT > MTransforms
Definition: forward_dynamics.h:52
CoreS::ForceVector Force
Definition: forward_dynamics.h:44
iit::testirb4600::tpl::JointState< SCALAR > JointState
Definition: forward_dynamics.h:48
Definition: declarations.h:27
Definition: declarations.h:31
ForwardDynamics(iit::testirb4600::dyn::tpl::InertiaProperties< TRAIT > &in, MTransforms &tr)
Definition: forward_dynamics.impl.h:9
Force< DScalar > vxIv(const Velocity< DScalar > &v, const MatrixBase< Derived > &I)
Definition: robcogen_commons.h:58
Definition: rbd.h:175
void fd(JointState &qdd, const JointState &q, const JointState &qd, const JointState &tau, const ExtForces &fext=zeroExtForces)
Definition: forward_dynamics.h:168
Definition: rbd.h:175
Definition: inertia_properties.h:25
Definition: declarations.h:40
Definition: link_data_map.h:12
Definition: declarations.h:36
Definition: declarations.h:30
Definition: declarations.h:26
Definition: declarations.h:29
Definition: declarations.h:28
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef TRAIT::Scalar SCALAR
Definition: forward_dynamics.h:39
Definition: declarations.h:41
Definition: declarations.h:39
void ctransform_Ia_revolute(const MatrixBase< D1 > &Ia_A, const MatrixBase< D2 > &XM, const MatrixBase< D3 > &Ia_B_const)
Definition: robcogen_commons.h:315
Definition: forward_dynamics.h:34