- 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::ct_HyA::dyn::tpl::JSIM<TRAIT>::JSIM(IProperties& inertiaProperties, FTransforms& forceTransforms) :
6  linkInertias(inertiaProperties),
7  frcTransf( &forceTransforms ),
8  Wrist_FE_Ic(linkInertias.getTensor_Wrist_FE())
9 {
10  //Initialize the matrix itself
11  this->setZero();
12 }
13 
14 #define DATA tpl::JSIM<TRAIT>::operator()
15 
16 template <typename TRAIT>
18  ForceVector F;
19 
20  // Precomputes only once the coordinate transforms:
21  frcTransf -> fr_Wrist_R_X_fr_Wrist_FE(state);
22  frcTransf -> fr_Elbow_FE_X_fr_Wrist_R(state);
23  frcTransf -> fr_Humerus_R_X_fr_Elbow_FE(state);
24  frcTransf -> fr_Shoulder_FE_X_fr_Humerus_R(state);
25  frcTransf -> fr_Shoulder_AA_X_fr_Shoulder_FE(state);
26 
27  // Initializes the composite inertia tensors
28  Shoulder_AA_Ic = linkInertias.getTensor_Shoulder_AA();
29  Shoulder_FE_Ic = linkInertias.getTensor_Shoulder_FE();
30  Humerus_R_Ic = linkInertias.getTensor_Humerus_R();
31  Elbow_FE_Ic = linkInertias.getTensor_Elbow_FE();
32  Wrist_R_Ic = linkInertias.getTensor_Wrist_R();
33 
34  // "Bottom-up" loop to update the inertia-composite property of each link, for the current configuration
35 
36  // Link Wrist_FE:
37  iit::rbd::transformInertia(Wrist_FE_Ic, frcTransf -> fr_Wrist_R_X_fr_Wrist_FE, Ic_spare);
38  Wrist_R_Ic += Ic_spare;
39 
40  F = Wrist_FE_Ic.col(iit::rbd::AZ);
41  DATA(WFE, WFE) = F(iit::rbd::AZ);
42 
43  F = frcTransf -> fr_Wrist_R_X_fr_Wrist_FE * F;
44  DATA(WFE, WR) = F(iit::rbd::AZ);
45  DATA(WR, WFE) = DATA(WFE, WR);
46  F = frcTransf -> fr_Elbow_FE_X_fr_Wrist_R * F;
47  DATA(WFE, EFE) = F(iit::rbd::AZ);
48  DATA(EFE, WFE) = DATA(WFE, EFE);
49  F = frcTransf -> fr_Humerus_R_X_fr_Elbow_FE * F;
50  DATA(WFE, HR) = F(iit::rbd::AZ);
51  DATA(HR, WFE) = DATA(WFE, HR);
52  F = frcTransf -> fr_Shoulder_FE_X_fr_Humerus_R * F;
53  DATA(WFE, SFE) = F(iit::rbd::AZ);
54  DATA(SFE, WFE) = DATA(WFE, SFE);
55  F = frcTransf -> fr_Shoulder_AA_X_fr_Shoulder_FE * F;
56  DATA(WFE, SAA) = F(iit::rbd::AZ);
57  DATA(SAA, WFE) = DATA(WFE, SAA);
58 
59  // Link Wrist_R:
60  iit::rbd::transformInertia(Wrist_R_Ic, frcTransf -> fr_Elbow_FE_X_fr_Wrist_R, Ic_spare);
61  Elbow_FE_Ic += Ic_spare;
62 
63  F = Wrist_R_Ic.col(iit::rbd::AZ);
64  DATA(WR, WR) = F(iit::rbd::AZ);
65 
66  F = frcTransf -> fr_Elbow_FE_X_fr_Wrist_R * F;
67  DATA(WR, EFE) = F(iit::rbd::AZ);
68  DATA(EFE, WR) = DATA(WR, EFE);
69  F = frcTransf -> fr_Humerus_R_X_fr_Elbow_FE * F;
70  DATA(WR, HR) = F(iit::rbd::AZ);
71  DATA(HR, WR) = DATA(WR, HR);
72  F = frcTransf -> fr_Shoulder_FE_X_fr_Humerus_R * F;
73  DATA(WR, SFE) = F(iit::rbd::AZ);
74  DATA(SFE, WR) = DATA(WR, SFE);
75  F = frcTransf -> fr_Shoulder_AA_X_fr_Shoulder_FE * F;
76  DATA(WR, SAA) = F(iit::rbd::AZ);
77  DATA(SAA, WR) = DATA(WR, SAA);
78 
79  // Link Elbow_FE:
80  iit::rbd::transformInertia(Elbow_FE_Ic, frcTransf -> fr_Humerus_R_X_fr_Elbow_FE, Ic_spare);
81  Humerus_R_Ic += Ic_spare;
82 
83  F = Elbow_FE_Ic.col(iit::rbd::AZ);
84  DATA(EFE, EFE) = F(iit::rbd::AZ);
85 
86  F = frcTransf -> fr_Humerus_R_X_fr_Elbow_FE * F;
87  DATA(EFE, HR) = F(iit::rbd::AZ);
88  DATA(HR, EFE) = DATA(EFE, HR);
89  F = frcTransf -> fr_Shoulder_FE_X_fr_Humerus_R * F;
90  DATA(EFE, SFE) = F(iit::rbd::AZ);
91  DATA(SFE, EFE) = DATA(EFE, SFE);
92  F = frcTransf -> fr_Shoulder_AA_X_fr_Shoulder_FE * F;
93  DATA(EFE, SAA) = F(iit::rbd::AZ);
94  DATA(SAA, EFE) = DATA(EFE, SAA);
95 
96  // Link Humerus_R:
97  iit::rbd::transformInertia(Humerus_R_Ic, frcTransf -> fr_Shoulder_FE_X_fr_Humerus_R, Ic_spare);
98  Shoulder_FE_Ic += Ic_spare;
99 
100  F = Humerus_R_Ic.col(iit::rbd::AZ);
101  DATA(HR, HR) = F(iit::rbd::AZ);
102 
103  F = frcTransf -> fr_Shoulder_FE_X_fr_Humerus_R * F;
104  DATA(HR, SFE) = F(iit::rbd::AZ);
105  DATA(SFE, HR) = DATA(HR, SFE);
106  F = frcTransf -> fr_Shoulder_AA_X_fr_Shoulder_FE * F;
107  DATA(HR, SAA) = F(iit::rbd::AZ);
108  DATA(SAA, HR) = DATA(HR, SAA);
109 
110  // Link Shoulder_FE:
111  iit::rbd::transformInertia(Shoulder_FE_Ic, frcTransf -> fr_Shoulder_AA_X_fr_Shoulder_FE, Ic_spare);
112  Shoulder_AA_Ic += Ic_spare;
113 
114  F = Shoulder_FE_Ic.col(iit::rbd::AZ);
115  DATA(SFE, SFE) = F(iit::rbd::AZ);
116 
117  F = frcTransf -> fr_Shoulder_AA_X_fr_Shoulder_FE * F;
118  DATA(SFE, SAA) = F(iit::rbd::AZ);
119  DATA(SAA, SFE) = DATA(SFE, SAA);
120 
121  // Link Shoulder_AA:
122 
123  F = Shoulder_AA_Ic.col(iit::rbd::AZ);
124  DATA(SAA, SAA) = F(iit::rbd::AZ);
125 
126 
127  return *this;
128 }
129 
130 #undef DATA
131 #undef F
132 
133 template <typename TRAIT>
135  L = this -> template triangularView<Eigen::Lower>();
136  // Joint WFE, index 5 :
137  L(5, 5) = std::sqrt(L(5, 5));
138  L(5, 4) = L(5, 4) / L(5, 5);
139  L(5, 3) = L(5, 3) / L(5, 5);
140  L(5, 2) = L(5, 2) / L(5, 5);
141  L(5, 1) = L(5, 1) / L(5, 5);
142  L(5, 0) = L(5, 0) / L(5, 5);
143  L(4, 4) = L(4, 4) - L(5, 4) * L(5, 4);
144  L(4, 3) = L(4, 3) - L(5, 4) * L(5, 3);
145  L(4, 2) = L(4, 2) - L(5, 4) * L(5, 2);
146  L(4, 1) = L(4, 1) - L(5, 4) * L(5, 1);
147  L(4, 0) = L(4, 0) - L(5, 4) * L(5, 0);
148  L(3, 3) = L(3, 3) - L(5, 3) * L(5, 3);
149  L(3, 2) = L(3, 2) - L(5, 3) * L(5, 2);
150  L(3, 1) = L(3, 1) - L(5, 3) * L(5, 1);
151  L(3, 0) = L(3, 0) - L(5, 3) * L(5, 0);
152  L(2, 2) = L(2, 2) - L(5, 2) * L(5, 2);
153  L(2, 1) = L(2, 1) - L(5, 2) * L(5, 1);
154  L(2, 0) = L(2, 0) - L(5, 2) * L(5, 0);
155  L(1, 1) = L(1, 1) - L(5, 1) * L(5, 1);
156  L(1, 0) = L(1, 0) - L(5, 1) * L(5, 0);
157  L(0, 0) = L(0, 0) - L(5, 0) * L(5, 0);
158 
159  // Joint WR, index 4 :
160  L(4, 4) = std::sqrt(L(4, 4));
161  L(4, 3) = L(4, 3) / L(4, 4);
162  L(4, 2) = L(4, 2) / L(4, 4);
163  L(4, 1) = L(4, 1) / L(4, 4);
164  L(4, 0) = L(4, 0) / L(4, 4);
165  L(3, 3) = L(3, 3) - L(4, 3) * L(4, 3);
166  L(3, 2) = L(3, 2) - L(4, 3) * L(4, 2);
167  L(3, 1) = L(3, 1) - L(4, 3) * L(4, 1);
168  L(3, 0) = L(3, 0) - L(4, 3) * L(4, 0);
169  L(2, 2) = L(2, 2) - L(4, 2) * L(4, 2);
170  L(2, 1) = L(2, 1) - L(4, 2) * L(4, 1);
171  L(2, 0) = L(2, 0) - L(4, 2) * L(4, 0);
172  L(1, 1) = L(1, 1) - L(4, 1) * L(4, 1);
173  L(1, 0) = L(1, 0) - L(4, 1) * L(4, 0);
174  L(0, 0) = L(0, 0) - L(4, 0) * L(4, 0);
175 
176  // Joint EFE, index 3 :
177  L(3, 3) = std::sqrt(L(3, 3));
178  L(3, 2) = L(3, 2) / L(3, 3);
179  L(3, 1) = L(3, 1) / L(3, 3);
180  L(3, 0) = L(3, 0) / L(3, 3);
181  L(2, 2) = L(2, 2) - L(3, 2) * L(3, 2);
182  L(2, 1) = L(2, 1) - L(3, 2) * L(3, 1);
183  L(2, 0) = L(2, 0) - L(3, 2) * L(3, 0);
184  L(1, 1) = L(1, 1) - L(3, 1) * L(3, 1);
185  L(1, 0) = L(1, 0) - L(3, 1) * L(3, 0);
186  L(0, 0) = L(0, 0) - L(3, 0) * L(3, 0);
187 
188  // Joint HR, index 2 :
189  L(2, 2) = std::sqrt(L(2, 2));
190  L(2, 1) = L(2, 1) / L(2, 2);
191  L(2, 0) = L(2, 0) / L(2, 2);
192  L(1, 1) = L(1, 1) - L(2, 1) * L(2, 1);
193  L(1, 0) = L(1, 0) - L(2, 1) * L(2, 0);
194  L(0, 0) = L(0, 0) - L(2, 0) * L(2, 0);
195 
196  // Joint SFE, index 1 :
197  L(1, 1) = std::sqrt(L(1, 1));
198  L(1, 0) = L(1, 0) / L(1, 1);
199  L(0, 0) = L(0, 0) - L(1, 0) * L(1, 0);
200 
201  // Joint SAA, index 0 :
202  L(0, 0) = std::sqrt(L(0, 0));
203 
204 }
205 
206 template <typename TRAIT>
208  computeLInverse();
209 
210  inverse(0, 0) = + (Linv(0, 0) * Linv(0, 0));
211  inverse(1, 1) = + (Linv(1, 0) * Linv(1, 0)) + (Linv(1, 1) * Linv(1, 1));
212  inverse(1, 0) = + (Linv(1, 0) * Linv(0, 0));
213  inverse(0, 1) = inverse(1, 0);
214  inverse(2, 2) = + (Linv(2, 0) * Linv(2, 0)) + (Linv(2, 1) * Linv(2, 1)) + (Linv(2, 2) * Linv(2, 2));
215  inverse(2, 1) = + (Linv(2, 0) * Linv(1, 0)) + (Linv(2, 1) * Linv(1, 1));
216  inverse(1, 2) = inverse(2, 1);
217  inverse(2, 0) = + (Linv(2, 0) * Linv(0, 0));
218  inverse(0, 2) = inverse(2, 0);
219  inverse(3, 3) = + (Linv(3, 0) * Linv(3, 0)) + (Linv(3, 1) * Linv(3, 1)) + (Linv(3, 2) * Linv(3, 2)) + (Linv(3, 3) * Linv(3, 3));
220  inverse(3, 2) = + (Linv(3, 0) * Linv(2, 0)) + (Linv(3, 1) * Linv(2, 1)) + (Linv(3, 2) * Linv(2, 2));
221  inverse(2, 3) = inverse(3, 2);
222  inverse(3, 1) = + (Linv(3, 0) * Linv(1, 0)) + (Linv(3, 1) * Linv(1, 1));
223  inverse(1, 3) = inverse(3, 1);
224  inverse(3, 0) = + (Linv(3, 0) * Linv(0, 0));
225  inverse(0, 3) = inverse(3, 0);
226  inverse(4, 4) = + (Linv(4, 0) * Linv(4, 0)) + (Linv(4, 1) * Linv(4, 1)) + (Linv(4, 2) * Linv(4, 2)) + (Linv(4, 3) * Linv(4, 3)) + (Linv(4, 4) * Linv(4, 4));
227  inverse(4, 3) = + (Linv(4, 0) * Linv(3, 0)) + (Linv(4, 1) * Linv(3, 1)) + (Linv(4, 2) * Linv(3, 2)) + (Linv(4, 3) * Linv(3, 3));
228  inverse(3, 4) = inverse(4, 3);
229  inverse(4, 2) = + (Linv(4, 0) * Linv(2, 0)) + (Linv(4, 1) * Linv(2, 1)) + (Linv(4, 2) * Linv(2, 2));
230  inverse(2, 4) = inverse(4, 2);
231  inverse(4, 1) = + (Linv(4, 0) * Linv(1, 0)) + (Linv(4, 1) * Linv(1, 1));
232  inverse(1, 4) = inverse(4, 1);
233  inverse(4, 0) = + (Linv(4, 0) * Linv(0, 0));
234  inverse(0, 4) = inverse(4, 0);
235  inverse(5, 5) = + (Linv(5, 0) * Linv(5, 0)) + (Linv(5, 1) * Linv(5, 1)) + (Linv(5, 2) * Linv(5, 2)) + (Linv(5, 3) * Linv(5, 3)) + (Linv(5, 4) * Linv(5, 4)) + (Linv(5, 5) * Linv(5, 5));
236  inverse(5, 4) = + (Linv(5, 0) * Linv(4, 0)) + (Linv(5, 1) * Linv(4, 1)) + (Linv(5, 2) * Linv(4, 2)) + (Linv(5, 3) * Linv(4, 3)) + (Linv(5, 4) * Linv(4, 4));
237  inverse(4, 5) = inverse(5, 4);
238  inverse(5, 3) = + (Linv(5, 0) * Linv(3, 0)) + (Linv(5, 1) * Linv(3, 1)) + (Linv(5, 2) * Linv(3, 2)) + (Linv(5, 3) * Linv(3, 3));
239  inverse(3, 5) = inverse(5, 3);
240  inverse(5, 2) = + (Linv(5, 0) * Linv(2, 0)) + (Linv(5, 1) * Linv(2, 1)) + (Linv(5, 2) * Linv(2, 2));
241  inverse(2, 5) = inverse(5, 2);
242  inverse(5, 1) = + (Linv(5, 0) * Linv(1, 0)) + (Linv(5, 1) * Linv(1, 1));
243  inverse(1, 5) = inverse(5, 1);
244  inverse(5, 0) = + (Linv(5, 0) * Linv(0, 0));
245  inverse(0, 5) = inverse(5, 0);
246 }
247 
248 template <typename TRAIT>
250  //assumes L has been computed already
251  Linv(0, 0) = 1 / L(0, 0);
252  Linv(1, 1) = 1 / L(1, 1);
253  Linv(2, 2) = 1 / L(2, 2);
254  Linv(3, 3) = 1 / L(3, 3);
255  Linv(4, 4) = 1 / L(4, 4);
256  Linv(5, 5) = 1 / L(5, 5);
257  Linv(1, 0) = - Linv(0, 0) * ((Linv(1, 1) * L(1, 0)) + 0);
258  Linv(2, 1) = - Linv(1, 1) * ((Linv(2, 2) * L(2, 1)) + 0);
259  Linv(2, 0) = - Linv(0, 0) * ((Linv(2, 1) * L(1, 0)) + (Linv(2, 2) * L(2, 0)) + 0);
260  Linv(3, 2) = - Linv(2, 2) * ((Linv(3, 3) * L(3, 2)) + 0);
261  Linv(3, 1) = - Linv(1, 1) * ((Linv(3, 2) * L(2, 1)) + (Linv(3, 3) * L(3, 1)) + 0);
262  Linv(3, 0) = - Linv(0, 0) * ((Linv(3, 1) * L(1, 0)) + (Linv(3, 2) * L(2, 0)) + (Linv(3, 3) * L(3, 0)) + 0);
263  Linv(4, 3) = - Linv(3, 3) * ((Linv(4, 4) * L(4, 3)) + 0);
264  Linv(4, 2) = - Linv(2, 2) * ((Linv(4, 3) * L(3, 2)) + (Linv(4, 4) * L(4, 2)) + 0);
265  Linv(4, 1) = - Linv(1, 1) * ((Linv(4, 2) * L(2, 1)) + (Linv(4, 3) * L(3, 1)) + (Linv(4, 4) * L(4, 1)) + 0);
266  Linv(4, 0) = - Linv(0, 0) * ((Linv(4, 1) * L(1, 0)) + (Linv(4, 2) * L(2, 0)) + (Linv(4, 3) * L(3, 0)) + (Linv(4, 4) * L(4, 0)) + 0);
267  Linv(5, 4) = - Linv(4, 4) * ((Linv(5, 5) * L(5, 4)) + 0);
268  Linv(5, 3) = - Linv(3, 3) * ((Linv(5, 4) * L(4, 3)) + (Linv(5, 5) * L(5, 3)) + 0);
269  Linv(5, 2) = - Linv(2, 2) * ((Linv(5, 3) * L(3, 2)) + (Linv(5, 4) * L(4, 2)) + (Linv(5, 5) * L(5, 2)) + 0);
270  Linv(5, 1) = - Linv(1, 1) * ((Linv(5, 2) * L(2, 1)) + (Linv(5, 3) * L(3, 1)) + (Linv(5, 4) * L(4, 1)) + (Linv(5, 5) * L(5, 1)) + 0);
271  Linv(5, 0) = - Linv(0, 0) * ((Linv(5, 1) * L(1, 0)) + (Linv(5, 2) * L(2, 0)) + (Linv(5, 3) * L(3, 0)) + (Linv(5, 4) * L(4, 0)) + (Linv(5, 5) * L(5, 0)) + 0);
272 }
273 
const IMatrix & getTensor_Wrist_R() const
Definition: inertia_properties.h:93
iit::ct_HyA::tpl::ForceTransforms< TRAIT > FTransforms
Definition: jsim.h:35
void computeLInverse()
Definition: jsim.impl.h:249
Definition: declarations.h:27
void computeInverse()
Definition: jsim.impl.h:207
Definition: jsim.h:24
Definition: declarations.h:30
const IMatrix & getTensor_Elbow_FE() const
Definition: inertia_properties.h:89
const IMatrix & getTensor_Shoulder_FE() const
Definition: inertia_properties.h:81
#define F(i, j)
Definition: jsim.impl.h:19
const JSIM & update(const JointState &)
Definition: jsim.impl.h:17
const IMatrix & getTensor_Humerus_R() const
Definition: inertia_properties.h:85
JSIM(IProperties &, FTransforms &)
Definition: jsim.impl.h:5
Definition: declarations.h:29
#define DATA
Definition: jsim.impl.h:14
void transformInertia(const InertiaMat< Scalar > &I_A, const Mat66< Scalar > &XF, InertiaMat< Scalar > &I_B)
Definition: declarations.h:31
iit::ct_HyA::tpl::JointState< SCALAR > JointState
Definition: jsim.h:37
Definition: declarations.h:28
void computeL()
Definition: jsim.impl.h:134
Definition: declarations.h:32
const IMatrix & getTensor_Shoulder_AA() const
Definition: inertia_properties.h:77
iit::rbd::Core< SCALAR >::ForceVector ForceVector
Definition: jsim.h:38
Definition: inertia_properties.h:26