- 3.0.2 models module.
jsim.impl.h
Go to the documentation of this file.
1 
2 
3 //Implementation of default constructor
4 template <typename TRAIT>
5 iit::HyQ::dyn::tpl::JSIM<TRAIT>::JSIM(IProperties& inertiaProperties, FTransforms& forceTransforms) :
6  linkInertias(inertiaProperties),
7  frcTransf( &forceTransforms ),
8  LF_lowerleg_Ic(linkInertias.getTensor_LF_lowerleg()),
9  RF_lowerleg_Ic(linkInertias.getTensor_RF_lowerleg()),
10  LH_lowerleg_Ic(linkInertias.getTensor_LH_lowerleg()),
11  RH_lowerleg_Ic(linkInertias.getTensor_RH_lowerleg())
12 {
13  //Initialize the matrix itself
14  this->setZero();
15 }
16 
17 #define DATA tpl::JSIM<TRAIT>::operator()
18 #define Fcol(j) (tpl::JSIM<TRAIT>:: template block<6,1>(0,(j)+6))
19 #define F(i,j) DATA((i),(j)+6)
20 
21 template <typename TRAIT>
23 
24  // Precomputes only once the coordinate transforms:
25  frcTransf -> fr_RH_upperleg_X_fr_RH_lowerleg(state);
26  frcTransf -> fr_RH_hipassembly_X_fr_RH_upperleg(state);
27  frcTransf -> fr_trunk_X_fr_RH_hipassembly(state);
28  frcTransf -> fr_LH_upperleg_X_fr_LH_lowerleg(state);
29  frcTransf -> fr_LH_hipassembly_X_fr_LH_upperleg(state);
30  frcTransf -> fr_trunk_X_fr_LH_hipassembly(state);
31  frcTransf -> fr_RF_upperleg_X_fr_RF_lowerleg(state);
32  frcTransf -> fr_RF_hipassembly_X_fr_RF_upperleg(state);
33  frcTransf -> fr_trunk_X_fr_RF_hipassembly(state);
34  frcTransf -> fr_LF_upperleg_X_fr_LF_lowerleg(state);
35  frcTransf -> fr_LF_hipassembly_X_fr_LF_upperleg(state);
36  frcTransf -> fr_trunk_X_fr_LF_hipassembly(state);
37 
38  // Initializes the composite inertia tensors
39  trunk_Ic = linkInertias.getTensor_trunk();
40  LF_hipassembly_Ic = linkInertias.getTensor_LF_hipassembly();
41  LF_upperleg_Ic = linkInertias.getTensor_LF_upperleg();
42  RF_hipassembly_Ic = linkInertias.getTensor_RF_hipassembly();
43  RF_upperleg_Ic = linkInertias.getTensor_RF_upperleg();
44  LH_hipassembly_Ic = linkInertias.getTensor_LH_hipassembly();
45  LH_upperleg_Ic = linkInertias.getTensor_LH_upperleg();
46  RH_hipassembly_Ic = linkInertias.getTensor_RH_hipassembly();
47  RH_upperleg_Ic = linkInertias.getTensor_RH_upperleg();
48 
49  // "Bottom-up" loop to update the inertia-composite property of each link, for the current configuration
50 
51  // Link RH_lowerleg:
52  iit::rbd::transformInertia<Scalar>(RH_lowerleg_Ic, frcTransf -> fr_RH_upperleg_X_fr_RH_lowerleg, Ic_spare);
53  RH_upperleg_Ic += Ic_spare;
54 
55  Fcol(RH_KFE) = RH_lowerleg_Ic.col(iit::rbd::AZ);
57 
58  Fcol(RH_KFE) = frcTransf -> fr_RH_upperleg_X_fr_RH_lowerleg * Fcol(RH_KFE);
60  DATA(RH_HFE+6, RH_KFE+6) = DATA(RH_KFE+6, RH_HFE+6);
61  Fcol(RH_KFE) = frcTransf -> fr_RH_hipassembly_X_fr_RH_upperleg * Fcol(RH_KFE);
63  DATA(RH_HAA+6, RH_KFE+6) = DATA(RH_KFE+6, RH_HAA+6);
64  Fcol(RH_KFE) = frcTransf -> fr_trunk_X_fr_RH_hipassembly * Fcol(RH_KFE);
65 
66  // Link RH_upperleg:
67  iit::rbd::transformInertia<Scalar>(RH_upperleg_Ic, frcTransf -> fr_RH_hipassembly_X_fr_RH_upperleg, Ic_spare);
68  RH_hipassembly_Ic += Ic_spare;
69 
70  Fcol(RH_HFE) = RH_upperleg_Ic.col(iit::rbd::AZ);
72 
73  Fcol(RH_HFE) = frcTransf -> fr_RH_hipassembly_X_fr_RH_upperleg * Fcol(RH_HFE);
75  DATA(RH_HAA+6, RH_HFE+6) = DATA(RH_HFE+6, RH_HAA+6);
76  Fcol(RH_HFE) = frcTransf -> fr_trunk_X_fr_RH_hipassembly * Fcol(RH_HFE);
77 
78  // Link RH_hipassembly:
79  iit::rbd::transformInertia<Scalar>(RH_hipassembly_Ic, frcTransf -> fr_trunk_X_fr_RH_hipassembly, Ic_spare);
80  trunk_Ic += Ic_spare;
81 
82  Fcol(RH_HAA) = RH_hipassembly_Ic.col(iit::rbd::AZ);
84 
85  Fcol(RH_HAA) = frcTransf -> fr_trunk_X_fr_RH_hipassembly * Fcol(RH_HAA);
86 
87  // Link LH_lowerleg:
88  iit::rbd::transformInertia<Scalar>(LH_lowerleg_Ic, frcTransf -> fr_LH_upperleg_X_fr_LH_lowerleg, Ic_spare);
89  LH_upperleg_Ic += Ic_spare;
90 
91  Fcol(LH_KFE) = LH_lowerleg_Ic.col(iit::rbd::AZ);
93 
94  Fcol(LH_KFE) = frcTransf -> fr_LH_upperleg_X_fr_LH_lowerleg * Fcol(LH_KFE);
96  DATA(LH_HFE+6, LH_KFE+6) = DATA(LH_KFE+6, LH_HFE+6);
97  Fcol(LH_KFE) = frcTransf -> fr_LH_hipassembly_X_fr_LH_upperleg * Fcol(LH_KFE);
99  DATA(LH_HAA+6, LH_KFE+6) = DATA(LH_KFE+6, LH_HAA+6);
100  Fcol(LH_KFE) = frcTransf -> fr_trunk_X_fr_LH_hipassembly * Fcol(LH_KFE);
101 
102  // Link LH_upperleg:
103  iit::rbd::transformInertia<Scalar>(LH_upperleg_Ic, frcTransf -> fr_LH_hipassembly_X_fr_LH_upperleg, Ic_spare);
104  LH_hipassembly_Ic += Ic_spare;
105 
106  Fcol(LH_HFE) = LH_upperleg_Ic.col(iit::rbd::AZ);
108 
109  Fcol(LH_HFE) = frcTransf -> fr_LH_hipassembly_X_fr_LH_upperleg * Fcol(LH_HFE);
111  DATA(LH_HAA+6, LH_HFE+6) = DATA(LH_HFE+6, LH_HAA+6);
112  Fcol(LH_HFE) = frcTransf -> fr_trunk_X_fr_LH_hipassembly * Fcol(LH_HFE);
113 
114  // Link LH_hipassembly:
115  iit::rbd::transformInertia<Scalar>(LH_hipassembly_Ic, frcTransf -> fr_trunk_X_fr_LH_hipassembly, Ic_spare);
116  trunk_Ic += Ic_spare;
117 
118  Fcol(LH_HAA) = LH_hipassembly_Ic.col(iit::rbd::AZ);
120 
121  Fcol(LH_HAA) = frcTransf -> fr_trunk_X_fr_LH_hipassembly * Fcol(LH_HAA);
122 
123  // Link RF_lowerleg:
124  iit::rbd::transformInertia<Scalar>(RF_lowerleg_Ic, frcTransf -> fr_RF_upperleg_X_fr_RF_lowerleg, Ic_spare);
125  RF_upperleg_Ic += Ic_spare;
126 
127  Fcol(RF_KFE) = RF_lowerleg_Ic.col(iit::rbd::AZ);
129 
130  Fcol(RF_KFE) = frcTransf -> fr_RF_upperleg_X_fr_RF_lowerleg * Fcol(RF_KFE);
132  DATA(RF_HFE+6, RF_KFE+6) = DATA(RF_KFE+6, RF_HFE+6);
133  Fcol(RF_KFE) = frcTransf -> fr_RF_hipassembly_X_fr_RF_upperleg * Fcol(RF_KFE);
135  DATA(RF_HAA+6, RF_KFE+6) = DATA(RF_KFE+6, RF_HAA+6);
136  Fcol(RF_KFE) = frcTransf -> fr_trunk_X_fr_RF_hipassembly * Fcol(RF_KFE);
137 
138  // Link RF_upperleg:
139  iit::rbd::transformInertia<Scalar>(RF_upperleg_Ic, frcTransf -> fr_RF_hipassembly_X_fr_RF_upperleg, Ic_spare);
140  RF_hipassembly_Ic += Ic_spare;
141 
142  Fcol(RF_HFE) = RF_upperleg_Ic.col(iit::rbd::AZ);
144 
145  Fcol(RF_HFE) = frcTransf -> fr_RF_hipassembly_X_fr_RF_upperleg * Fcol(RF_HFE);
147  DATA(RF_HAA+6, RF_HFE+6) = DATA(RF_HFE+6, RF_HAA+6);
148  Fcol(RF_HFE) = frcTransf -> fr_trunk_X_fr_RF_hipassembly * Fcol(RF_HFE);
149 
150  // Link RF_hipassembly:
151  iit::rbd::transformInertia<Scalar>(RF_hipassembly_Ic, frcTransf -> fr_trunk_X_fr_RF_hipassembly, Ic_spare);
152  trunk_Ic += Ic_spare;
153 
154  Fcol(RF_HAA) = RF_hipassembly_Ic.col(iit::rbd::AZ);
156 
157  Fcol(RF_HAA) = frcTransf -> fr_trunk_X_fr_RF_hipassembly * Fcol(RF_HAA);
158 
159  // Link LF_lowerleg:
160  iit::rbd::transformInertia<Scalar>(LF_lowerleg_Ic, frcTransf -> fr_LF_upperleg_X_fr_LF_lowerleg, Ic_spare);
161  LF_upperleg_Ic += Ic_spare;
162 
163  Fcol(LF_KFE) = LF_lowerleg_Ic.col(iit::rbd::AZ);
165 
166  Fcol(LF_KFE) = frcTransf -> fr_LF_upperleg_X_fr_LF_lowerleg * Fcol(LF_KFE);
168  DATA(LF_HFE+6, LF_KFE+6) = DATA(LF_KFE+6, LF_HFE+6);
169  Fcol(LF_KFE) = frcTransf -> fr_LF_hipassembly_X_fr_LF_upperleg * Fcol(LF_KFE);
171  DATA(LF_HAA+6, LF_KFE+6) = DATA(LF_KFE+6, LF_HAA+6);
172  Fcol(LF_KFE) = frcTransf -> fr_trunk_X_fr_LF_hipassembly * Fcol(LF_KFE);
173 
174  // Link LF_upperleg:
175  iit::rbd::transformInertia<Scalar>(LF_upperleg_Ic, frcTransf -> fr_LF_hipassembly_X_fr_LF_upperleg, Ic_spare);
176  LF_hipassembly_Ic += Ic_spare;
177 
178  Fcol(LF_HFE) = LF_upperleg_Ic.col(iit::rbd::AZ);
180 
181  Fcol(LF_HFE) = frcTransf -> fr_LF_hipassembly_X_fr_LF_upperleg * Fcol(LF_HFE);
183  DATA(LF_HAA+6, LF_HFE+6) = DATA(LF_HFE+6, LF_HAA+6);
184  Fcol(LF_HFE) = frcTransf -> fr_trunk_X_fr_LF_hipassembly * Fcol(LF_HFE);
185 
186  // Link LF_hipassembly:
187  iit::rbd::transformInertia<Scalar>(LF_hipassembly_Ic, frcTransf -> fr_trunk_X_fr_LF_hipassembly, Ic_spare);
188  trunk_Ic += Ic_spare;
189 
190  Fcol(LF_HAA) = LF_hipassembly_Ic.col(iit::rbd::AZ);
192 
193  Fcol(LF_HAA) = frcTransf -> fr_trunk_X_fr_LF_hipassembly * Fcol(LF_HAA);
194 
195  // Copies the upper-right block into the lower-left block, after transposing
196  JSIM<TRAIT>:: template block<12, 6>(6,0) = (JSIM<TRAIT>:: template block<6, 12>(0,6)).transpose();
197  // The composite-inertia of the whole robot is the upper-left quadrant of the JSIM
198  JSIM<TRAIT>:: template block<6,6>(0,0) = trunk_Ic;
199  return *this;
200 }
201 
202 #undef DATA
203 #undef F
204 
205 template <typename TRAIT>
207  L = this -> template triangularView<Eigen::Lower>();
208  // Joint RH_KFE, index 11 :
209  L(11, 11) = std::sqrt(L(11, 11));
210  L(11, 10) = L(11, 10) / L(11, 11);
211  L(11, 9) = L(11, 9) / L(11, 11);
212  L(10, 10) = L(10, 10) - L(11, 10) * L(11, 10);
213  L(10, 9) = L(10, 9) - L(11, 10) * L(11, 9);
214  L(9, 9) = L(9, 9) - L(11, 9) * L(11, 9);
215 
216  // Joint RH_HFE, index 10 :
217  L(10, 10) = std::sqrt(L(10, 10));
218  L(10, 9) = L(10, 9) / L(10, 10);
219  L(9, 9) = L(9, 9) - L(10, 9) * L(10, 9);
220 
221  // Joint RH_HAA, index 9 :
222  L(9, 9) = std::sqrt(L(9, 9));
223 
224  // Joint LH_KFE, index 8 :
225  L(8, 8) = std::sqrt(L(8, 8));
226  L(8, 7) = L(8, 7) / L(8, 8);
227  L(8, 6) = L(8, 6) / L(8, 8);
228  L(7, 7) = L(7, 7) - L(8, 7) * L(8, 7);
229  L(7, 6) = L(7, 6) - L(8, 7) * L(8, 6);
230  L(6, 6) = L(6, 6) - L(8, 6) * L(8, 6);
231 
232  // Joint LH_HFE, index 7 :
233  L(7, 7) = std::sqrt(L(7, 7));
234  L(7, 6) = L(7, 6) / L(7, 7);
235  L(6, 6) = L(6, 6) - L(7, 6) * L(7, 6);
236 
237  // Joint LH_HAA, index 6 :
238  L(6, 6) = std::sqrt(L(6, 6));
239 
240  // Joint RF_KFE, index 5 :
241  L(5, 5) = std::sqrt(L(5, 5));
242  L(5, 4) = L(5, 4) / L(5, 5);
243  L(5, 3) = L(5, 3) / L(5, 5);
244  L(4, 4) = L(4, 4) - L(5, 4) * L(5, 4);
245  L(4, 3) = L(4, 3) - L(5, 4) * L(5, 3);
246  L(3, 3) = L(3, 3) - L(5, 3) * L(5, 3);
247 
248  // Joint RF_HFE, index 4 :
249  L(4, 4) = std::sqrt(L(4, 4));
250  L(4, 3) = L(4, 3) / L(4, 4);
251  L(3, 3) = L(3, 3) - L(4, 3) * L(4, 3);
252 
253  // Joint RF_HAA, index 3 :
254  L(3, 3) = std::sqrt(L(3, 3));
255 
256  // Joint LF_KFE, index 2 :
257  L(2, 2) = std::sqrt(L(2, 2));
258  L(2, 1) = L(2, 1) / L(2, 2);
259  L(2, 0) = L(2, 0) / L(2, 2);
260  L(1, 1) = L(1, 1) - L(2, 1) * L(2, 1);
261  L(1, 0) = L(1, 0) - L(2, 1) * L(2, 0);
262  L(0, 0) = L(0, 0) - L(2, 0) * L(2, 0);
263 
264  // Joint LF_HFE, index 1 :
265  L(1, 1) = std::sqrt(L(1, 1));
266  L(1, 0) = L(1, 0) / L(1, 1);
267  L(0, 0) = L(0, 0) - L(1, 0) * L(1, 0);
268 
269  // Joint LF_HAA, index 0 :
270  L(0, 0) = std::sqrt(L(0, 0));
271 
272 }
273 
274 template <typename TRAIT>
276  computeLInverse();
277 
278  inverse(0, 0) = + (Linv(0, 0) * Linv(0, 0));
279  inverse(1, 1) = + (Linv(1, 0) * Linv(1, 0)) + (Linv(1, 1) * Linv(1, 1));
280  inverse(1, 0) = + (Linv(1, 0) * Linv(0, 0));
281  inverse(0, 1) = inverse(1, 0);
282  inverse(2, 2) = + (Linv(2, 0) * Linv(2, 0)) + (Linv(2, 1) * Linv(2, 1)) + (Linv(2, 2) * Linv(2, 2));
283  inverse(2, 1) = + (Linv(2, 0) * Linv(1, 0)) + (Linv(2, 1) * Linv(1, 1));
284  inverse(1, 2) = inverse(2, 1);
285  inverse(2, 0) = + (Linv(2, 0) * Linv(0, 0));
286  inverse(0, 2) = inverse(2, 0);
287  inverse(3, 3) = + (Linv(3, 3) * Linv(3, 3));
288  inverse(4, 4) = + (Linv(4, 3) * Linv(4, 3)) + (Linv(4, 4) * Linv(4, 4));
289  inverse(4, 3) = + (Linv(4, 3) * Linv(3, 3));
290  inverse(3, 4) = inverse(4, 3);
291  inverse(5, 5) = + (Linv(5, 3) * Linv(5, 3)) + (Linv(5, 4) * Linv(5, 4)) + (Linv(5, 5) * Linv(5, 5));
292  inverse(5, 4) = + (Linv(5, 3) * Linv(4, 3)) + (Linv(5, 4) * Linv(4, 4));
293  inverse(4, 5) = inverse(5, 4);
294  inverse(5, 3) = + (Linv(5, 3) * Linv(3, 3));
295  inverse(3, 5) = inverse(5, 3);
296  inverse(6, 6) = + (Linv(6, 6) * Linv(6, 6));
297  inverse(7, 7) = + (Linv(7, 6) * Linv(7, 6)) + (Linv(7, 7) * Linv(7, 7));
298  inverse(7, 6) = + (Linv(7, 6) * Linv(6, 6));
299  inverse(6, 7) = inverse(7, 6);
300  inverse(8, 8) = + (Linv(8, 6) * Linv(8, 6)) + (Linv(8, 7) * Linv(8, 7)) + (Linv(8, 8) * Linv(8, 8));
301  inverse(8, 7) = + (Linv(8, 6) * Linv(7, 6)) + (Linv(8, 7) * Linv(7, 7));
302  inverse(7, 8) = inverse(8, 7);
303  inverse(8, 6) = + (Linv(8, 6) * Linv(6, 6));
304  inverse(6, 8) = inverse(8, 6);
305  inverse(9, 9) = + (Linv(9, 9) * Linv(9, 9));
306  inverse(10, 10) = + (Linv(10, 9) * Linv(10, 9)) + (Linv(10, 10) * Linv(10, 10));
307  inverse(10, 9) = + (Linv(10, 9) * Linv(9, 9));
308  inverse(9, 10) = inverse(10, 9);
309  inverse(11, 11) = + (Linv(11, 9) * Linv(11, 9)) + (Linv(11, 10) * Linv(11, 10)) + (Linv(11, 11) * Linv(11, 11));
310  inverse(11, 10) = + (Linv(11, 9) * Linv(10, 9)) + (Linv(11, 10) * Linv(10, 10));
311  inverse(10, 11) = inverse(11, 10);
312  inverse(11, 9) = + (Linv(11, 9) * Linv(9, 9));
313  inverse(9, 11) = inverse(11, 9);
314 }
315 
316 template <typename TRAIT>
318  //assumes L has been computed already
319  Linv(0, 0) = 1 / L(0, 0);
320  Linv(1, 1) = 1 / L(1, 1);
321  Linv(2, 2) = 1 / L(2, 2);
322  Linv(3, 3) = 1 / L(3, 3);
323  Linv(4, 4) = 1 / L(4, 4);
324  Linv(5, 5) = 1 / L(5, 5);
325  Linv(6, 6) = 1 / L(6, 6);
326  Linv(7, 7) = 1 / L(7, 7);
327  Linv(8, 8) = 1 / L(8, 8);
328  Linv(9, 9) = 1 / L(9, 9);
329  Linv(10, 10) = 1 / L(10, 10);
330  Linv(11, 11) = 1 / L(11, 11);
331  Linv(1, 0) = - Linv(0, 0) * ((Linv(1, 1) * L(1, 0)) + 0);
332  Linv(2, 1) = - Linv(1, 1) * ((Linv(2, 2) * L(2, 1)) + 0);
333  Linv(2, 0) = - Linv(0, 0) * ((Linv(2, 1) * L(1, 0)) + (Linv(2, 2) * L(2, 0)) + 0);
334  Linv(4, 3) = - Linv(3, 3) * ((Linv(4, 4) * L(4, 3)) + 0);
335  Linv(5, 4) = - Linv(4, 4) * ((Linv(5, 5) * L(5, 4)) + 0);
336  Linv(5, 3) = - Linv(3, 3) * ((Linv(5, 4) * L(4, 3)) + (Linv(5, 5) * L(5, 3)) + 0);
337  Linv(7, 6) = - Linv(6, 6) * ((Linv(7, 7) * L(7, 6)) + 0);
338  Linv(8, 7) = - Linv(7, 7) * ((Linv(8, 8) * L(8, 7)) + 0);
339  Linv(8, 6) = - Linv(6, 6) * ((Linv(8, 7) * L(7, 6)) + (Linv(8, 8) * L(8, 6)) + 0);
340  Linv(10, 9) = - Linv(9, 9) * ((Linv(10, 10) * L(10, 9)) + 0);
341  Linv(11, 10) = - Linv(10, 10) * ((Linv(11, 11) * L(11, 10)) + 0);
342  Linv(11, 9) = - Linv(9, 9) * ((Linv(11, 10) * L(10, 9)) + (Linv(11, 11) * L(11, 9)) + 0);
343 }
344 
Definition: declarations.h:31
#define Fcol(j)
Definition: jsim.impl.h:18
#define DATA
Definition: jsim.impl.h:17
iit::HyQ::tpl::ForceTransforms< TRAIT > FTransforms
Definition: jsim.h:41
const IMatrix & getTensor_RH_hipassembly() const
Definition: inertia_properties.h:152
Definition: declarations.h:36
Definition: declarations.h:29
const JSIM & update(const JointState &)
Definition: jsim.impl.h:22
Definition: jsim.h:24
#define F(i, j)
Definition: jsim.impl.h:19
JSIM(IProperties &, FTransforms &)
Definition: jsim.impl.h:5
Definition: declarations.h:34
Definition: declarations.h:37
Definition: declarations.h:28
Definition: declarations.h:38
void computeL()
Definition: jsim.impl.h:206
void computeInverse()
Definition: jsim.impl.h:275
Definition: declarations.h:35
iit::HyQ::tpl::JointState< Scalar > JointState
Definition: jsim.h:32
Definition: inertia_properties.h:26
Definition: declarations.h:27
const IMatrix & getTensor_trunk() const
Definition: inertia_properties.h:112
const IMatrix & getTensor_LF_upperleg() const
Definition: inertia_properties.h:120
Definition: declarations.h:33
const IMatrix & getTensor_RH_upperleg() const
Definition: inertia_properties.h:156
const IMatrix & getTensor_LH_upperleg() const
Definition: inertia_properties.h:144
Definition: declarations.h:32
const IMatrix & getTensor_RF_upperleg() const
Definition: inertia_properties.h:132
const IMatrix & getTensor_RF_hipassembly() const
Definition: inertia_properties.h:128
const IMatrix & getTensor_LF_hipassembly() const
Definition: inertia_properties.h:116
Definition: declarations.h:30
const IMatrix & getTensor_LH_hipassembly() const
Definition: inertia_properties.h:140
void computeLInverse()
Definition: jsim.impl.h:317