- 3.0.2 rigid body dynamics module.
inverse_dynamics.impl.h
Go to the documentation of this file.
1 
2 // Initialization of static-const data
3 template <typename TRAIT>
6 
7 template <typename TRAIT>
9  inertiaProps( & inertia ),
10  xm( & transforms ),
11  link1_I(inertiaProps->getTensor_link1() ),
12  link2_I(inertiaProps->getTensor_link2() ),
13  link3_I(inertiaProps->getTensor_link3() ),
14  link4_I(inertiaProps->getTensor_link4() ),
15  link5_I(inertiaProps->getTensor_link5() ),
16  link6_I(inertiaProps->getTensor_link6() )
17  {
18 #ifndef EIGEN_NO_DEBUG
19  std::cout << "Robot testirb4600, InverseDynamics<TRAIT>::InverseDynamics()" << std::endl;
20  std::cout << "Compiled with Eigen debug active" << std::endl;
21 #endif
22  link1_v.setZero();
23  link2_v.setZero();
24  link3_v.setZero();
25  link4_v.setZero();
26  link5_v.setZero();
27  link6_v.setZero();
28 
29  vcross.setZero();
30 }
31 
32 template <typename TRAIT>
34  JointState& jForces,
35  const JointState& qd, const JointState& qdd,
36  const ExtForces& fext)
37 {
38  firstPass(qd, qdd, fext);
39  secondPass(jForces);
40 }
41 
42 template <typename TRAIT>
44 {
45  // Link 'link1'
46  link1_a = (xm->fr_link1_X_fr_link0).col(iit::rbd::LZ) * SCALAR(iit::rbd::g);
47  link1_f = link1_I * link1_a;
48  // Link 'link2'
49  link2_a = (xm->fr_link2_X_fr_link1) * link1_a;
50  link2_f = link2_I * link2_a;
51  // Link 'link3'
52  link3_a = (xm->fr_link3_X_fr_link2) * link2_a;
53  link3_f = link3_I * link3_a;
54  // Link 'link4'
55  link4_a = (xm->fr_link4_X_fr_link3) * link3_a;
56  link4_f = link4_I * link4_a;
57  // Link 'link5'
58  link5_a = (xm->fr_link5_X_fr_link4) * link4_a;
59  link5_f = link5_I * link5_a;
60  // Link 'link6'
61  link6_a = (xm->fr_link6_X_fr_link5) * link5_a;
62  link6_f = link6_I * link6_a;
63 
64  secondPass(jForces);
65 }
66 
67 template <typename TRAIT>
69 {
70  // Link 'link1'
71  link1_v(iit::rbd::AZ) = qd(JA); // link1_v = vJ, for the first link of a fixed base robot
72 
73  link1_f = iit::rbd::vxIv(qd(JA), link1_I);
74 
75  // Link 'link2'
76  link2_v = ((xm->fr_link2_X_fr_link1) * link1_v);
77  link2_v(iit::rbd::AZ) += qd(JB);
78 
79  iit::rbd::motionCrossProductMx<SCALAR>(link2_v, vcross);
80 
81  link2_a = (vcross.col(iit::rbd::AZ) * qd(JB));
82 
83  link2_f = link2_I * link2_a + iit::rbd::vxIv(link2_v, link2_I);
84 
85  // Link 'link3'
86  link3_v = ((xm->fr_link3_X_fr_link2) * link2_v);
87  link3_v(iit::rbd::AZ) += qd(JC);
88 
89  iit::rbd::motionCrossProductMx<SCALAR>(link3_v, vcross);
90 
91  link3_a = (xm->fr_link3_X_fr_link2) * link2_a + vcross.col(iit::rbd::AZ) * qd(JC);
92 
93  link3_f = link3_I * link3_a + iit::rbd::vxIv(link3_v, link3_I);
94 
95  // Link 'link4'
96  link4_v = ((xm->fr_link4_X_fr_link3) * link3_v);
97  link4_v(iit::rbd::AZ) += qd(JD);
98 
99  iit::rbd::motionCrossProductMx<SCALAR>(link4_v, vcross);
100 
101  link4_a = (xm->fr_link4_X_fr_link3) * link3_a + vcross.col(iit::rbd::AZ) * qd(JD);
102 
103  link4_f = link4_I * link4_a + iit::rbd::vxIv(link4_v, link4_I);
104 
105  // Link 'link5'
106  link5_v = ((xm->fr_link5_X_fr_link4) * link4_v);
107  link5_v(iit::rbd::AZ) += qd(JE);
108 
109  iit::rbd::motionCrossProductMx<SCALAR>(link5_v, vcross);
110 
111  link5_a = (xm->fr_link5_X_fr_link4) * link4_a + vcross.col(iit::rbd::AZ) * qd(JE);
112 
113  link5_f = link5_I * link5_a + iit::rbd::vxIv(link5_v, link5_I);
114 
115  // Link 'link6'
116  link6_v = ((xm->fr_link6_X_fr_link5) * link5_v);
117  link6_v(iit::rbd::AZ) += qd(JF);
118 
119  iit::rbd::motionCrossProductMx<SCALAR>(link6_v, vcross);
120 
121  link6_a = (xm->fr_link6_X_fr_link5) * link5_a + vcross.col(iit::rbd::AZ) * qd(JF);
122 
123  link6_f = link6_I * link6_a + iit::rbd::vxIv(link6_v, link6_I);
124 
125 
126  secondPass(jForces);
127 }
128 
129 template <typename TRAIT>
131 {
132  // First pass, link 'link1'
133  link1_a = (xm->fr_link1_X_fr_link0).col(iit::rbd::LZ) * SCALAR(iit::rbd::g);
134  link1_a(iit::rbd::AZ) += qdd(JA);
135  link1_v(iit::rbd::AZ) = qd(JA); // link1_v = vJ, for the first link of a fixed base robot
136 
137  link1_f = link1_I * link1_a + iit::rbd::vxIv(qd(JA), link1_I) - fext[LINK1];
138 
139  // First pass, link 'link2'
140  link2_v = ((xm->fr_link2_X_fr_link1) * link1_v);
141  link2_v(iit::rbd::AZ) += qd(JB);
142 
143  iit::rbd::motionCrossProductMx<SCALAR>(link2_v, vcross);
144 
145  link2_a = (xm->fr_link2_X_fr_link1) * link1_a + vcross.col(iit::rbd::AZ) * qd(JB);
146  link2_a(iit::rbd::AZ) += qdd(JB);
147 
148  link2_f = link2_I * link2_a + iit::rbd::vxIv(link2_v, link2_I) - fext[LINK2];
149 
150  // First pass, link 'link3'
151  link3_v = ((xm->fr_link3_X_fr_link2) * link2_v);
152  link3_v(iit::rbd::AZ) += qd(JC);
153 
154  iit::rbd::motionCrossProductMx<SCALAR>(link3_v, vcross);
155 
156  link3_a = (xm->fr_link3_X_fr_link2) * link2_a + vcross.col(iit::rbd::AZ) * qd(JC);
157  link3_a(iit::rbd::AZ) += qdd(JC);
158 
159  link3_f = link3_I * link3_a + iit::rbd::vxIv(link3_v, link3_I) - fext[LINK3];
160 
161  // First pass, link 'link4'
162  link4_v = ((xm->fr_link4_X_fr_link3) * link3_v);
163  link4_v(iit::rbd::AZ) += qd(JD);
164 
165  iit::rbd::motionCrossProductMx<SCALAR>(link4_v, vcross);
166 
167  link4_a = (xm->fr_link4_X_fr_link3) * link3_a + vcross.col(iit::rbd::AZ) * qd(JD);
168  link4_a(iit::rbd::AZ) += qdd(JD);
169 
170  link4_f = link4_I * link4_a + iit::rbd::vxIv(link4_v, link4_I) - fext[LINK4];
171 
172  // First pass, link 'link5'
173  link5_v = ((xm->fr_link5_X_fr_link4) * link4_v);
174  link5_v(iit::rbd::AZ) += qd(JE);
175 
176  iit::rbd::motionCrossProductMx<SCALAR>(link5_v, vcross);
177 
178  link5_a = (xm->fr_link5_X_fr_link4) * link4_a + vcross.col(iit::rbd::AZ) * qd(JE);
179  link5_a(iit::rbd::AZ) += qdd(JE);
180 
181  link5_f = link5_I * link5_a + iit::rbd::vxIv(link5_v, link5_I) - fext[LINK5];
182 
183  // First pass, link 'link6'
184  link6_v = ((xm->fr_link6_X_fr_link5) * link5_v);
185  link6_v(iit::rbd::AZ) += qd(JF);
186 
187  iit::rbd::motionCrossProductMx<SCALAR>(link6_v, vcross);
188 
189  link6_a = (xm->fr_link6_X_fr_link5) * link5_a + vcross.col(iit::rbd::AZ) * qd(JF);
190  link6_a(iit::rbd::AZ) += qdd(JF);
191 
192  link6_f = link6_I * link6_a + iit::rbd::vxIv(link6_v, link6_I) - fext[LINK6];
193 
194 }
195 
196 template <typename TRAIT>
198 {
199  // Link 'link6'
200  jForces(JF) = link6_f(iit::rbd::AZ);
201  link5_f += xm->fr_link6_X_fr_link5.transpose() * link6_f;
202  // Link 'link5'
203  jForces(JE) = link5_f(iit::rbd::AZ);
204  link4_f += xm->fr_link5_X_fr_link4.transpose() * link5_f;
205  // Link 'link4'
206  jForces(JD) = link4_f(iit::rbd::AZ);
207  link3_f += xm->fr_link4_X_fr_link3.transpose() * link4_f;
208  // Link 'link3'
209  jForces(JC) = link3_f(iit::rbd::AZ);
210  link2_f += xm->fr_link3_X_fr_link2.transpose() * link3_f;
211  // Link 'link2'
212  jForces(JB) = link2_f(iit::rbd::AZ);
213  link1_f += xm->fr_link2_X_fr_link1.transpose() * link2_f;
214  // Link 'link1'
215  jForces(JA) = link1_f(iit::rbd::AZ);
216 }
InverseDynamics(IProperties &in, MTransforms &tr)
Definition: inverse_dynamics.impl.h:8
Definition: declarations.h:38
Definition: declarations.h:37
Definition: inverse_dynamics.h:42
iit::testirb4600::tpl::JointState< SCALAR > JointState
Definition: inverse_dynamics.h:55
void firstPass(const JointState &qd, const JointState &qdd, const ExtForces &fext)
Definition: inverse_dynamics.impl.h:130
Definition: declarations.h:27
Definition: declarations.h:31
Force< DScalar > vxIv(const Velocity< DScalar > &v, const MatrixBase< Derived > &I)
Definition: robcogen_commons.h:58
Definition: rbd.h:175
Definition: rbd.h:175
Definition: inertia_properties.h:25
Definition: declarations.h:40
void id(JointState &jForces, const JointState &q, const JointState &qd, const JointState &qdd, const ExtForces &fext=zeroExtForces)
Definition: inverse_dynamics.h:219
Definition: link_data_map.h:12
void G_terms(JointState &jForces, const JointState &q)
Definition: inverse_dynamics.h:205
iit::testirb4600::tpl::MotionTransforms< TRAIT > MTransforms
Definition: inverse_dynamics.h:57
Definition: declarations.h:36
Definition: declarations.h:30
Definition: declarations.h:26
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef TRAIT::Scalar SCALAR
Definition: inverse_dynamics.h:46
Definition: declarations.h:29
Definition: declarations.h:28
void C_terms(JointState &jForces, const JointState &q, const JointState &qd)
Definition: inverse_dynamics.h:212
Definition: declarations.h:41
Definition: declarations.h:39
void secondPass(JointState &jForces)
Definition: inverse_dynamics.impl.h:197