56 using namespace NEWMAT;
60 const ColumnVector & dqp,
61 ColumnVector & ltorque, ColumnVector & dtorque)
71 if(q.Ncols() != 1 || q.Nrows() != dof) error(
"q has wrong dimension");
72 if(qp.Ncols() != 1 || qp.Nrows() != dof) error(
"qp has wrong dimension");
73 if(dqp.Ncols() != 1 || qp.Nrows() != dof) error(
"dqp has wrong dimension");
74 ltorque = ColumnVector(dof);
75 dtorque = ColumnVector(dof);
80 z0(1) = 0.0; z0(2) = 0.0; z0(3) = 1.0;
86 for(i = 1; i <= dof; i++)
89 p[i] = ColumnVector(3);
90 p[i](1) = links[i].get_a();
91 p[i](2) = links[i].get_d() * Rt(2,3);
92 p[i](3) = links[i].get_d() * Rt(3,3);
93 if(links[i].get_joint_type() != 0)
95 dp[i] = ColumnVector(3);
100 if(links[i].get_joint_type() == 0)
102 w[i] = Rt*(w[i-1] + z0*qp(i));
103 dw[i] = Rt*(dw[i-1] + z0*dqp(i));
104 wp[i] = Rt*(wp[i-1] + CrossProduct(w[i-1],z0*qp(i)));
105 dwp[i] = Rt*(dwp[i-1]
106 + CrossProduct(dw[i-1],z0*qp(i))
107 + CrossProduct(w[i-1],z0*dqp(i)));
108 vp[i] = CrossProduct(wp[i],p[i])
109 + CrossProduct(w[i],CrossProduct(w[i],p[i]))
111 dvp[i] = CrossProduct(dwp[i],p[i])
112 + CrossProduct(dw[i],CrossProduct(w[i],p[i]))
113 + CrossProduct(w[i],CrossProduct(dw[i],p[i]))
121 dwp[i] = Rt*dwp[i-1];
123 + 2.0*CrossProduct(w[i],Rt*z0*qp(i)))
124 + CrossProduct(wp[i],p[i])
125 + CrossProduct(w[i],CrossProduct(w[i],p[i]));
126 dvp[i] = Rt*(dvp[i-1]
127 + 2.0*(CrossProduct(dw[i-1],z0*qp(i))
128 + CrossProduct(w[i-1],z0*dqp(i))))
129 + CrossProduct(dwp[i],p[i])
130 + CrossProduct(dw[i],CrossProduct(w[i],p[i]))
131 + CrossProduct(w[i],CrossProduct(dw[i],p[i]));
133 a[i] = CrossProduct(wp[i],links[i].r)
134 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
136 da[i] = CrossProduct(dwp[i],links[i].r)
137 + CrossProduct(dw[i],CrossProduct(w[i],links[i].r))
138 + CrossProduct(w[i],CrossProduct(dw[i],links[i].r))
142 for(i = dof; i >= 1; i--)
144 F[i] = a[i] * links[i].m;
145 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
146 dF[i] = da[i] * links[i].m;
147 dN[i] = links[i].I*dwp[i] + CrossProduct(dw[i],links[i].I*w[i])
148 + CrossProduct(w[i],links[i].I*dw[i]);
152 n[i] = CrossProduct(p[i],f[i])
153 + CrossProduct(links[i].r,F[i]) + N[i];
155 dn[i] = CrossProduct(p[i],df[i])
156 + CrossProduct(links[i].r,dF[i]) + dN[i];
160 f[i] = links[i+1].R*f[i+1] + F[i];
161 df[i] = links[i+1].R*df[i+1] + dF[i];
162 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i],f[i])
163 + CrossProduct(links[i].r,F[i]) + N[i];
164 dn[i] = links[i+1].R*dn[i+1] + CrossProduct(p[i],df[i])
165 + CrossProduct(links[i].r,dF[i]) + dN[i];
167 if(links[i].get_joint_type() == 0)
169 temp = ((z0.t()*links[i].R)*n[i]);
170 ltorque(i) = temp(1,1);
171 temp = ((z0.t()*links[i].R)*dn[i]);
172 dtorque(i) = temp(1,1);
176 temp = ((z0.t()*links[i].R)*f[i]);
177 ltorque(i) = temp(1,1);
178 temp = ((z0.t()*links[i].R)*df[i]);
179 dtorque(i) = temp(1,1);
185 const ColumnVector & dqp, ColumnVector & ltorque,
186 ColumnVector & dtorque)
196 if(q.Ncols() != 1 || q.Nrows() != dof) error(
"q has wrong dimension");
197 if(qp.Ncols() != 1 || qp.Nrows() != dof) error(
"qp has wrong dimension");
198 if(dqp.Ncols() != 1 || dqp.Nrows() != dof) error(
"dqp has wrong dimension");
199 ltorque = ColumnVector(dof);
200 dtorque = ColumnVector(dof);
205 z0(1) = 0.0; z0(2) = 0.0; z0(3) = 1.0;
210 for(i = 1; i <= dof; i++)
214 if(links[i].get_joint_type() != 0)
216 dp[i] = ColumnVector(3);
221 if(links[i].get_joint_type() == 0)
223 w[i] = Rt*w[i-1] + z0*qp(i);
224 dw[i] = Rt*dw[i-1] + z0*dqp(i);
225 wp[i] = Rt*wp[i-1] + CrossProduct(Rt*w[i-1],z0*qp(i));
226 dwp[i] = Rt*dwp[i-1] + CrossProduct(Rt*dw[i-1],z0*qp(i))
227 + CrossProduct(Rt*w[i-1],z0*dqp(i));
228 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
229 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
231 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
232 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
233 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1]);
240 dwp[i] = Rt*dwp[i-1];
241 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
242 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
243 + 2.0*CrossProduct(w[i],z0*qp(i));
244 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
245 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
246 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1])
247 + 2*(CrossProduct(dw[i],z0*qp(i)) + CrossProduct(w[i],z0*dqp(i)));
249 a[i] = CrossProduct(wp[i],links[i].r)
250 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
252 da[i] = CrossProduct(dwp[i],links[i].r)
253 + CrossProduct(dw[i],CrossProduct(w[i],links[i].r))
254 + CrossProduct(w[i],CrossProduct(dw[i],links[i].r))
258 for(i = dof; i >= 1; i--) {
259 F[i] = a[i] * links[i].m;
260 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
261 dF[i] = da[i] * links[i].m;
262 dN[i] = links[i].I*dwp[i] + CrossProduct(dw[i],links[i].I*w[i])
263 + CrossProduct(w[i],links[i].I*dw[i]);
269 n[i] = CrossProduct(links[i].r,F[i]) + N[i];
270 dn[i] = dN[i] + CrossProduct(links[i].r,dF[i]);
274 f[i] = links[i+1].R*f[i+1] + F[i];
275 df[i] = links[i+1].R*df[i+1] + dF[i];
276 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1])
277 + CrossProduct(links[i].r,F[i]) + N[i];
278 dn[i] = links[i+1].R*dn[i+1] + CrossProduct(p[i+1],links[i+1].R*df[i+1])
279 + CrossProduct(links[i].r,dF[i]) + dN[i];
282 if(links[i].get_joint_type() == 0)
285 ltorque(i) = temp(1,1);
287 dtorque(i) = temp(1,1);
292 ltorque(i) = temp(1,1);
294 dtorque(i) = temp(1,1);
300 const ColumnVector & dqp, ColumnVector & ltorque,
301 ColumnVector & dtorque)
311 if(q.Ncols() != 1 || q.Nrows() != dof) error(
"q has wrong dimension");
312 if(qp.Ncols() != 1 || qp.Nrows() != dof) error(
"qp has wrong dimension");
313 if(dqp.Ncols() != 1 || dqp.Nrows() != dof) error(
"dqp has wrong dimension");
314 ltorque = ColumnVector(dof);
315 dtorque = ColumnVector(dof);
320 z0(1) = 0.0; z0(2) = 0.0; z0(3) = 1.0;
325 for(i = 1; i <= dof; i++)
329 if(links[i].get_joint_type() != 0)
331 dp[i] = ColumnVector(3);
336 if(links[i].get_joint_type() == 0)
338 w[i] = Rt*w[i-1] + z0*qp(i);
339 dw[i] = Rt*dw[i-1] + z0*dqp(i);
340 wp[i] = Rt*wp[i-1] + CrossProduct(Rt*w[i-1],z0*qp(i));
341 dwp[i] = Rt*dwp[i-1] + CrossProduct(Rt*dw[i-1],z0*qp(i));
342 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
343 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
345 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
346 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
347 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1]);
354 dwp[i] = Rt*dwp[i-1];
355 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
356 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
357 + 2.0*CrossProduct(w[i],z0*qp(i));
358 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
359 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
360 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1])
361 + 2*(CrossProduct(dw[i],z0*qp(i)) + CrossProduct(w[i],z0*dqp(i)));
365 for(i = dof; i >= 1; i--) {
366 F[i] = vp[i]*links[i].m + CrossProduct(wp[i], links[i].mc) +
367 CrossProduct(w[i], CrossProduct(w[i], links[i].mc));
368 dF[i] = dvp[i]*links[i].m + CrossProduct(dwp[i],links[i].mc)
369 + CrossProduct(dw[i],CrossProduct(w[i],links[i].mc))
370 + CrossProduct(w[i],CrossProduct(dw[i],links[i].mc));
371 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i])
372 - CrossProduct(vp[i], links[i].mc);
373 dN[i] = links[i].I*dwp[i] + CrossProduct(dw[i],links[i].I*w[i])
374 + CrossProduct(w[i],links[i].I*dw[i])
375 - CrossProduct(dvp[i],links[i].mc);
386 f[i] = links[i+1].R*f[i+1] + F[i];
387 df[i] = links[i+1].R*df[i+1] + dF[i];
388 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1]) + N[i];
389 dn[i] = links[i+1].R*dn[i+1] + CrossProduct(p[i+1],links[i+1].R*df[i+1]) + dN[i];
392 if(links[i].get_joint_type() == 0)
395 ltorque(i) = temp(1,1);
397 dtorque(i) = temp(1,1);
402 ltorque(i) = temp(1,1);
404 dtorque(i) = temp(1,1);