- 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  Shoulder_AA_v.setZero();
14  Shoulder_AA_c.setZero();
15  Shoulder_FE_v.setZero();
16  Shoulder_FE_c.setZero();
17  Humerus_R_v.setZero();
18  Humerus_R_c.setZero();
19  Elbow_FE_v.setZero();
20  Elbow_FE_c.setZero();
21  Wrist_R_v.setZero();
22  Wrist_R_c.setZero();
23  Wrist_FE_v.setZero();
24  Wrist_FE_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  Shoulder_AA_AI = inertiaProps->getTensor_Shoulder_AA();
40  Shoulder_AA_p = - fext[SHOULDER_AA];
41  Shoulder_FE_AI = inertiaProps->getTensor_Shoulder_FE();
42  Shoulder_FE_p = - fext[SHOULDER_FE];
43  Humerus_R_AI = inertiaProps->getTensor_Humerus_R();
44  Humerus_R_p = - fext[HUMERUS_R];
45  Elbow_FE_AI = inertiaProps->getTensor_Elbow_FE();
46  Elbow_FE_p = - fext[ELBOW_FE];
47  Wrist_R_AI = inertiaProps->getTensor_Wrist_R();
48  Wrist_R_p = - fext[WRIST_R];
49  Wrist_FE_AI = inertiaProps->getTensor_Wrist_FE();
50  Wrist_FE_p = - fext[WRIST_FE];
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 Shoulder_AA
58  // - The spatial velocity:
59  Shoulder_AA_v(rbd::AZ) = qd(SAA);
60 
61  // - The bias force term:
62  Shoulder_AA_p += iit::rbd::vxIv(qd(SAA), Shoulder_AA_AI);
63 
64  // + Link Shoulder_FE
65  // - The spatial velocity:
66  Shoulder_FE_v = (motionTransforms-> fr_Shoulder_FE_X_fr_Shoulder_AA) * Shoulder_AA_v;
67  Shoulder_FE_v(rbd::AZ) += qd(SFE);
68 
69  // - The velocity-product acceleration term:
70  iit::rbd::motionCrossProductMx<SCALAR>(Shoulder_FE_v, vcross);
71  Shoulder_FE_c = vcross.col(rbd::AZ) * qd(SFE);
72 
73  // - The bias force term:
74  Shoulder_FE_p += iit::rbd::vxIv(Shoulder_FE_v, Shoulder_FE_AI);
75 
76  // + Link Humerus_R
77  // - The spatial velocity:
78  Humerus_R_v = (motionTransforms-> fr_Humerus_R_X_fr_Shoulder_FE) * Shoulder_FE_v;
79  Humerus_R_v(rbd::AZ) += qd(HR);
80 
81  // - The velocity-product acceleration term:
82  iit::rbd::motionCrossProductMx<SCALAR>(Humerus_R_v, vcross);
83  Humerus_R_c = vcross.col(rbd::AZ) * qd(HR);
84 
85  // - The bias force term:
86  Humerus_R_p += iit::rbd::vxIv(Humerus_R_v, Humerus_R_AI);
87 
88  // + Link Elbow_FE
89  // - The spatial velocity:
90  Elbow_FE_v = (motionTransforms-> fr_Elbow_FE_X_fr_Humerus_R) * Humerus_R_v;
91  Elbow_FE_v(rbd::AZ) += qd(EFE);
92 
93  // - The velocity-product acceleration term:
94  iit::rbd::motionCrossProductMx<SCALAR>(Elbow_FE_v, vcross);
95  Elbow_FE_c = vcross.col(rbd::AZ) * qd(EFE);
96 
97  // - The bias force term:
98  Elbow_FE_p += iit::rbd::vxIv(Elbow_FE_v, Elbow_FE_AI);
99 
100  // + Link Wrist_R
101  // - The spatial velocity:
102  Wrist_R_v = (motionTransforms-> fr_Wrist_R_X_fr_Elbow_FE) * Elbow_FE_v;
103  Wrist_R_v(rbd::AZ) += qd(WR);
104 
105  // - The velocity-product acceleration term:
106  iit::rbd::motionCrossProductMx<SCALAR>(Wrist_R_v, vcross);
107  Wrist_R_c = vcross.col(rbd::AZ) * qd(WR);
108 
109  // - The bias force term:
110  Wrist_R_p += iit::rbd::vxIv(Wrist_R_v, Wrist_R_AI);
111 
112  // + Link Wrist_FE
113  // - The spatial velocity:
114  Wrist_FE_v = (motionTransforms-> fr_Wrist_FE_X_fr_Wrist_R) * Wrist_R_v;
115  Wrist_FE_v(rbd::AZ) += qd(WFE);
116 
117  // - The velocity-product acceleration term:
118  iit::rbd::motionCrossProductMx<SCALAR>(Wrist_FE_v, vcross);
119  Wrist_FE_c = vcross.col(rbd::AZ) * qd(WFE);
120 
121  // - The bias force term:
122  Wrist_FE_p += iit::rbd::vxIv(Wrist_FE_v, Wrist_FE_AI);
123 
124 
125  // ---------------------- SECOND PASS ---------------------- //
126  Matrix66S IaB;
127  Force pa;
128 
129  // + Link Wrist_FE
130  Wrist_FE_u = tau(WFE) - Wrist_FE_p(rbd::AZ);
131  Wrist_FE_U = Wrist_FE_AI.col(rbd::AZ);
132  Wrist_FE_D = Wrist_FE_U(rbd::AZ);
133 
134  iit::rbd::compute_Ia_revolute(Wrist_FE_AI, Wrist_FE_U, Wrist_FE_D, Ia_r); // same as: Ia_r = Wrist_FE_AI - Wrist_FE_U/Wrist_FE_D * Wrist_FE_U.transpose();
135  pa = Wrist_FE_p + Ia_r * Wrist_FE_c + Wrist_FE_U * Wrist_FE_u/Wrist_FE_D;
136  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_Wrist_FE_X_fr_Wrist_R, IaB);
137  Wrist_R_AI += IaB;
138  Wrist_R_p += (motionTransforms-> fr_Wrist_FE_X_fr_Wrist_R).transpose() * pa;
139 
140  // + Link Wrist_R
141  Wrist_R_u = tau(WR) - Wrist_R_p(rbd::AZ);
142  Wrist_R_U = Wrist_R_AI.col(rbd::AZ);
143  Wrist_R_D = Wrist_R_U(rbd::AZ);
144 
145  iit::rbd::compute_Ia_revolute(Wrist_R_AI, Wrist_R_U, Wrist_R_D, Ia_r); // same as: Ia_r = Wrist_R_AI - Wrist_R_U/Wrist_R_D * Wrist_R_U.transpose();
146  pa = Wrist_R_p + Ia_r * Wrist_R_c + Wrist_R_U * Wrist_R_u/Wrist_R_D;
147  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_Wrist_R_X_fr_Elbow_FE, IaB);
148  Elbow_FE_AI += IaB;
149  Elbow_FE_p += (motionTransforms-> fr_Wrist_R_X_fr_Elbow_FE).transpose() * pa;
150 
151  // + Link Elbow_FE
152  Elbow_FE_u = tau(EFE) - Elbow_FE_p(rbd::AZ);
153  Elbow_FE_U = Elbow_FE_AI.col(rbd::AZ);
154  Elbow_FE_D = Elbow_FE_U(rbd::AZ);
155 
156  iit::rbd::compute_Ia_revolute(Elbow_FE_AI, Elbow_FE_U, Elbow_FE_D, Ia_r); // same as: Ia_r = Elbow_FE_AI - Elbow_FE_U/Elbow_FE_D * Elbow_FE_U.transpose();
157  pa = Elbow_FE_p + Ia_r * Elbow_FE_c + Elbow_FE_U * Elbow_FE_u/Elbow_FE_D;
158  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_Elbow_FE_X_fr_Humerus_R, IaB);
159  Humerus_R_AI += IaB;
160  Humerus_R_p += (motionTransforms-> fr_Elbow_FE_X_fr_Humerus_R).transpose() * pa;
161 
162  // + Link Humerus_R
163  Humerus_R_u = tau(HR) - Humerus_R_p(rbd::AZ);
164  Humerus_R_U = Humerus_R_AI.col(rbd::AZ);
165  Humerus_R_D = Humerus_R_U(rbd::AZ);
166 
167  iit::rbd::compute_Ia_revolute(Humerus_R_AI, Humerus_R_U, Humerus_R_D, Ia_r); // same as: Ia_r = Humerus_R_AI - Humerus_R_U/Humerus_R_D * Humerus_R_U.transpose();
168  pa = Humerus_R_p + Ia_r * Humerus_R_c + Humerus_R_U * Humerus_R_u/Humerus_R_D;
169  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_Humerus_R_X_fr_Shoulder_FE, IaB);
170  Shoulder_FE_AI += IaB;
171  Shoulder_FE_p += (motionTransforms-> fr_Humerus_R_X_fr_Shoulder_FE).transpose() * pa;
172 
173  // + Link Shoulder_FE
174  Shoulder_FE_u = tau(SFE) - Shoulder_FE_p(rbd::AZ);
175  Shoulder_FE_U = Shoulder_FE_AI.col(rbd::AZ);
176  Shoulder_FE_D = Shoulder_FE_U(rbd::AZ);
177 
178  iit::rbd::compute_Ia_revolute(Shoulder_FE_AI, Shoulder_FE_U, Shoulder_FE_D, Ia_r); // same as: Ia_r = Shoulder_FE_AI - Shoulder_FE_U/Shoulder_FE_D * Shoulder_FE_U.transpose();
179  pa = Shoulder_FE_p + Ia_r * Shoulder_FE_c + Shoulder_FE_U * Shoulder_FE_u/Shoulder_FE_D;
180  ctransform_Ia_revolute(Ia_r, motionTransforms-> fr_Shoulder_FE_X_fr_Shoulder_AA, IaB);
181  Shoulder_AA_AI += IaB;
182  Shoulder_AA_p += (motionTransforms-> fr_Shoulder_FE_X_fr_Shoulder_AA).transpose() * pa;
183 
184  // + Link Shoulder_AA
185  Shoulder_AA_u = tau(SAA) - Shoulder_AA_p(rbd::AZ);
186  Shoulder_AA_U = Shoulder_AA_AI.col(rbd::AZ);
187  Shoulder_AA_D = Shoulder_AA_U(rbd::AZ);
188 
189 
190 
191  // ---------------------- THIRD PASS ---------------------- //
192  Shoulder_AA_a = (motionTransforms-> fr_Shoulder_AA_X_fr_HyABase).col(rbd::LZ) * SCALAR(iit::rbd::g);
193  qdd(SAA) = (Shoulder_AA_u - Shoulder_AA_U.dot(Shoulder_AA_a)) / Shoulder_AA_D;
194  Shoulder_AA_a(rbd::AZ) += qdd(SAA);
195 
196  Shoulder_FE_a = (motionTransforms-> fr_Shoulder_FE_X_fr_Shoulder_AA) * Shoulder_AA_a + Shoulder_FE_c;
197  qdd(SFE) = (Shoulder_FE_u - Shoulder_FE_U.dot(Shoulder_FE_a)) / Shoulder_FE_D;
198  Shoulder_FE_a(rbd::AZ) += qdd(SFE);
199 
200  Humerus_R_a = (motionTransforms-> fr_Humerus_R_X_fr_Shoulder_FE) * Shoulder_FE_a + Humerus_R_c;
201  qdd(HR) = (Humerus_R_u - Humerus_R_U.dot(Humerus_R_a)) / Humerus_R_D;
202  Humerus_R_a(rbd::AZ) += qdd(HR);
203 
204  Elbow_FE_a = (motionTransforms-> fr_Elbow_FE_X_fr_Humerus_R) * Humerus_R_a + Elbow_FE_c;
205  qdd(EFE) = (Elbow_FE_u - Elbow_FE_U.dot(Elbow_FE_a)) / Elbow_FE_D;
206  Elbow_FE_a(rbd::AZ) += qdd(EFE);
207 
208  Wrist_R_a = (motionTransforms-> fr_Wrist_R_X_fr_Elbow_FE) * Elbow_FE_a + Wrist_R_c;
209  qdd(WR) = (Wrist_R_u - Wrist_R_U.dot(Wrist_R_a)) / Wrist_R_D;
210  Wrist_R_a(rbd::AZ) += qdd(WR);
211 
212  Wrist_FE_a = (motionTransforms-> fr_Wrist_FE_X_fr_Wrist_R) * Wrist_R_a + Wrist_FE_c;
213  qdd(WFE) = (Wrist_FE_u - Wrist_FE_U.dot(Wrist_FE_a)) / Wrist_FE_D;
214  Wrist_FE_a(rbd::AZ) += qdd(WFE);
215 
216 
217 }
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: declarations.h:27
Definition: declarations.h:30
iit::ct_HyA::tpl::JointState< SCALAR > JointState
Definition: forward_dynamics.h:49
CoreS::ForceVector Force
Definition: forward_dynamics.h:45
ForwardDynamics(iit::ct_HyA::dyn::tpl::InertiaProperties< TRAIT > &in, MTransforms &tr)
Definition: forward_dynamics.impl.h:9
Definition: declarations.h:39
Force< DScalar > vxIv(const Velocity< DScalar > &v, const MatrixBase< Derived > &I)
Definition: declarations.h:29
Definition: forward_dynamics.h:35
Definition: declarations.h:42
Definition: link_data_map.h:12
Definition: declarations.h:41
Definition: declarations.h:38
iit::ct_HyA::tpl::MotionTransforms< TRAIT > MTransforms
Definition: forward_dynamics.h:53
Definition: declarations.h:31
Definition: declarations.h:28
Definition: declarations.h:37
Definition: declarations.h:32
Definition: declarations.h:40
void fd(JointState &qdd, const JointState &q, const JointState &qd, const JointState &tau, const ExtForces &fext=zeroExtForces)
Definition: forward_dynamics.h:169
void ctransform_Ia_revolute(const MatrixBase< D1 > &Ia_A, const MatrixBase< D2 > &XM, const MatrixBase< D3 > &Ia_B_const)
CoreS::Matrix66 Matrix66S
Definition: forward_dynamics.h:50
Definition: inertia_properties.h:26
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef TRAIT::Scalar SCALAR
Definition: forward_dynamics.h:40