- 3.0.2 models 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  ,
14  body_I( inertiaProps->getTensor_body() ),
15  link2_Ic(link2_I)
16 {
17 #ifndef EIGEN_NO_DEBUG
18  std::cout << "Robot ct_quadrotor, InverseDynamics<TRAIT>::InverseDynamics()" << std::endl;
19  std::cout << "Compiled with Eigen debug active" << std::endl;
20 #endif
21  link1_v.setZero();
22  link2_v.setZero();
23 
24  vcross.setZero();
25 }
26 
27 template <typename TRAIT>
29  JointState& jForces, Acceleration& body_a,
30  const Acceleration& g, const Velocity& body_v,
31  const JointState& qd, const JointState& qdd,
32  const ExtForces& fext)
33 {
34  body_Ic = body_I;
35  link1_Ic = link1_I;
36 
37  // First pass, link 'link1'
38  link1_v = ((xm->fr_link1_X_fr_body) * body_v);
39  link1_v(iit::rbd::AZ) += qd(JA);
40 
41  iit::rbd::motionCrossProductMx<SCALAR>(link1_v, vcross);
42 
43  link1_a = (vcross.col(iit::rbd::AZ) * qd(JA));
44  link1_a(iit::rbd::AZ) += qdd(JA);
45 
46  link1_f = link1_I * link1_a + iit::rbd::vxIv(link1_v, link1_I);
47 
48  // First pass, link 'link2'
49  link2_v = ((xm->fr_link2_X_fr_link1) * link1_v);
50  link2_v(iit::rbd::AZ) += qd(JB);
51 
52  iit::rbd::motionCrossProductMx<SCALAR>(link2_v, vcross);
53 
54  link2_a = (xm->fr_link2_X_fr_link1) * link1_a + vcross.col(iit::rbd::AZ) * qd(JB);
55  link2_a(iit::rbd::AZ) += qdd(JB);
56 
57  link2_f = link2_I * link2_a + iit::rbd::vxIv(link2_v, link2_I);
58 
59  // The force exerted on the floating base by the links
60  body_f = iit::rbd::vxIv(body_v, body_I);
61 
62 
63  // Add the external forces:
64  body_f -= fext[BODY];
65  link1_f -= fext[LINK1];
66  link2_f -= fext[LINK2];
67 
68  link1_Ic = link1_Ic + (xm->fr_link2_X_fr_link1).transpose() * link2_Ic * (xm->fr_link2_X_fr_link1);
69  link1_f = link1_f + (xm->fr_link2_X_fr_link1).transpose() * link2_f;
70 
71  body_Ic = body_Ic + (xm->fr_link1_X_fr_body).transpose() * link1_Ic * (xm->fr_link1_X_fr_body);
72  body_f = body_f + (xm->fr_link1_X_fr_body).transpose() * link1_f;
73 
74 
75  // The base acceleration due to the force due to the movement of the links
76  body_a = - body_Ic.inverse() * body_f;
77 
78  link1_a = xm->fr_link1_X_fr_body * body_a;
79  jForces(JA) = (link1_Ic.row(iit::rbd::AZ) * link1_a + link1_f(iit::rbd::AZ));
80 
81  link2_a = xm->fr_link2_X_fr_link1 * link1_a;
82  jForces(JB) = (link2_Ic.row(iit::rbd::AZ) * link2_a + link2_f(iit::rbd::AZ));
83 
84 
85  body_a += g;
86 }
87 
88 template <typename TRAIT>
90  Force& baseWrench, JointState& jForces,
91  const Acceleration& g)
92 {
93  const Acceleration& body_a = -g;
94 
95  // Link 'link1'
96  link1_a = (xm->fr_link1_X_fr_body) * body_a;
97  link1_f = link1_I * link1_a;
98  // Link 'link2'
99  link2_a = (xm->fr_link2_X_fr_link1) * link1_a;
100  link2_f = link2_I * link2_a;
101 
102  body_f = body_I * body_a;
103 
104  secondPass_fullyActuated(jForces);
105 
106  baseWrench = body_f;
107 }
108 
109 template <typename TRAIT>
111  Force& baseWrench, JointState& jForces,
112  const Velocity& body_v, const JointState& qd)
113 {
114  // Link 'link1'
115  link1_v = ((xm->fr_link1_X_fr_body) * body_v);
116  link1_v(iit::rbd::AZ) += qd(JA);
117  iit::rbd::motionCrossProductMx<SCALAR>(link1_v, vcross);
118  link1_a = (vcross.col(iit::rbd::AZ) * qd(JA));
119  link1_f = link1_I * link1_a + iit::rbd::vxIv(link1_v, link1_I);
120 
121  // Link 'link2'
122  link2_v = ((xm->fr_link2_X_fr_link1) * link1_v);
123  link2_v(iit::rbd::AZ) += qd(JB);
124  iit::rbd::motionCrossProductMx<SCALAR>(link2_v, vcross);
125  link2_a = (xm->fr_link2_X_fr_link1) * link1_a + vcross.col(iit::rbd::AZ) * qd(JB);
126  link2_f = link2_I * link2_a + iit::rbd::vxIv(link2_v, link2_I);
127 
128 
129  body_f = iit::rbd::vxIv(body_v, body_I);
130 
131  secondPass_fullyActuated(jForces);
132 
133  baseWrench = body_f;
134 }
135 
136 template <typename TRAIT>
138  Force& baseWrench, JointState& jForces,
139  const Acceleration& g, const Velocity& body_v, const Acceleration& baseAccel,
140  const JointState& qd, const JointState& qdd, const ExtForces& fext)
141 {
142  Acceleration body_a = baseAccel -g;
143 
144  // First pass, link 'link1'
145  link1_v = ((xm->fr_link1_X_fr_body) * body_v);
146  link1_v(iit::rbd::AZ) += qd(JA);
147 
148  iit::rbd::motionCrossProductMx<SCALAR>(link1_v, vcross);
149 
150  link1_a = (xm->fr_link1_X_fr_body) * body_a + vcross.col(iit::rbd::AZ) * qd(JA);
151  link1_a(iit::rbd::AZ) += qdd(JA);
152 
153  link1_f = link1_I * link1_a + iit::rbd::vxIv(link1_v, link1_I) - fext[LINK1];
154 
155  // First pass, link 'link2'
156  link2_v = ((xm->fr_link2_X_fr_link1) * link1_v);
157  link2_v(iit::rbd::AZ) += qd(JB);
158 
159  iit::rbd::motionCrossProductMx<SCALAR>(link2_v, vcross);
160 
161  link2_a = (xm->fr_link2_X_fr_link1) * link1_a + vcross.col(iit::rbd::AZ) * qd(JB);
162  link2_a(iit::rbd::AZ) += qdd(JB);
163 
164  link2_f = link2_I * link2_a + iit::rbd::vxIv(link2_v, link2_I) - fext[LINK2];
165 
166 
167  // The base
168  body_f = body_I * body_a + iit::rbd::vxIv(body_v, body_I) - fext[BODY];
169 
170  secondPass_fullyActuated(jForces);
171 
172  baseWrench = body_f;
173 }
174 
175 template <typename TRAIT>
177 {
178  // Link 'link2'
179  jForces(JB) = link2_f(iit::rbd::AZ);
180  link1_f += xm->fr_link2_X_fr_link1.transpose() * link2_f;
181  // Link 'link1'
182  jForces(JA) = link1_f(iit::rbd::AZ);
183  body_f += xm->fr_link1_X_fr_body.transpose() * link1_f;
184 }
185 
186 
CoreS::VelocityVector Velocity
Definition: inverse_dynamics.h:52
Definition: declarations.h:27
Definition: declarations.h:32
void C_terms_fully_actuated(Force &baseWrench, JointState &jForces, const Velocity &body_v, const JointState &q, const JointState &qd)
Definition: inverse_dynamics.h:244
CoreS::ForceVector Force
Definition: inverse_dynamics.h:50
Force< DScalar > vxIv(const Velocity< DScalar > &v, const MatrixBase< Derived > &I)
Definition: inverse_dynamics.h:42
iit::ct_quadrotor::tpl::MotionTransforms< TRAIT > MTransforms
Definition: inverse_dynamics.h:57
void G_terms_fully_actuated(Force &baseWrench, JointState &jForces, const Acceleration &g, const JointState &q)
Definition: inverse_dynamics.h:235
void id_fully_actuated(Force &baseWrench, JointState &jForces, const Acceleration &g, const Velocity &body_v, const Acceleration &baseAccel, const JointState &q, const JointState &qd, const JointState &qdd, const ExtForces &fext=zeroExtForces)
Definition: inverse_dynamics.h:253
Definition: declarations.h:31
Definition: inertia_properties.h:25
void id(JointState &jForces, Acceleration &body_a, const Acceleration &g, const Velocity &body_v, const JointState &q, const JointState &qd, const JointState &qdd, const ExtForces &fext=zeroExtForces)
Definition: inverse_dynamics.h:223
iit::ct_quadrotor::tpl::JointState< SCALAR > JointState
Definition: inverse_dynamics.h:55
Definition: link_data_map.h:12
InverseDynamics(IProperties &in, MTransforms &tr)
Definition: inverse_dynamics.impl.h:8
CoreS::VelocityVector Acceleration
Definition: inverse_dynamics.h:53
Definition: declarations.h:33
void secondPass_fullyActuated(JointState &jForces)
Definition: inverse_dynamics.impl.h:176
Definition: declarations.h:26