57 using namespace NEWMAT;
62 const ColumnVector & qpp,
const ColumnVector & dq,
63 const ColumnVector & dqp,
const ColumnVector & dqpp,
64 ColumnVector & ltorque, ColumnVector & dtorque)
155 if(q.Ncols() != 1 || q.Nrows() != dof) error(
"q has wrong dimension");
156 if(qp.Ncols() != 1 || qp.Nrows() != dof) error(
"qp has wrong dimension");
157 if(qpp.Ncols() != 1 || qpp.Nrows() != dof) error(
"qpp has wrong dimension");
158 if(dq.Ncols() != 1 || dq.Nrows() != dof) error(
"dq has wrong dimension");
159 if(dqp.Ncols() != 1 || dqp.Nrows() != dof) error(
"dqp has wrong dimension");
160 if(dqpp.Ncols() != 1 || dqpp.Nrows() != dof) error(
"dqpp has wrong dimension");
161 ltorque = ColumnVector(dof);
162 dtorque = ColumnVector(dof);
167 z0(1) = 0.0; z0(2) = 0.0; z0(3) = 1.0;
172 for(i = 1; i <= dof; i++)
175 p[i] = ColumnVector(3);
176 p[i](1) = links[i].get_a();
177 p[i](2) = links[i].get_d() * Rt(2,3);
178 p[i](3) = links[i].get_d() * Rt(3,3);
179 if(links[i].get_joint_type() != 0)
181 dp[i] = ColumnVector(3);
186 if(links[i].get_joint_type() == 0)
188 w[i] = Rt*(w[i-1] + z0*qp(i));
189 dw[i] = Rt*(dw[i-1] + z0*dqp(i)
190 - Q*(w[i-1] + z0*qp(i))*dq(i));
191 wp[i] = Rt*(wp[i-1] + z0*qpp(i)
192 + CrossProduct(w[i-1],z0*qp(i)));
193 dwp[i] = Rt*(dwp[i-1] + z0*dqpp(i)
194 + CrossProduct(dw[i-1],z0*qp(i))
195 + CrossProduct(w[i-1],z0*dqp(i))
196 - Q*(wp[i-1]+z0*qpp(i)+CrossProduct(w[i-1],z0*qp(i)))
198 vp[i] = CrossProduct(wp[i],p[i])
199 + CrossProduct(w[i],CrossProduct(w[i],p[i]))
201 dvp[i] = CrossProduct(dwp[i],p[i])
202 + CrossProduct(dw[i],CrossProduct(w[i],p[i]))
203 + CrossProduct(w[i],CrossProduct(dw[i],p[i]))
204 + Rt*(dvp[i-1] - Q*vp[i-1]*dq(i));
211 dwp[i] = Rt*dwp[i-1];
212 vp[i] = Rt*(vp[i-1] + z0*qpp(i)
213 + 2.0*CrossProduct(w[i-1],z0*qp(i)))
214 + CrossProduct(wp[i],p[i])
215 + CrossProduct(w[i],CrossProduct(w[i],p[i]));
216 dvp[i] = Rt*(dvp[i-1] + z0*dqpp(i)
217 + 2.0*(CrossProduct(dw[i-1],z0*qp(i))
218 + CrossProduct(w[i-1],z0*dqp(i))))
219 + CrossProduct(dwp[i],p[i])
220 + CrossProduct(dw[i],CrossProduct(w[i],p[i]))
221 + CrossProduct(w[i],CrossProduct(dw[i],p[i]))
222 + (CrossProduct(wp[i],dp[i])
223 + CrossProduct(w[i],CrossProduct(w[i],dp[i])))
226 a[i] = CrossProduct(wp[i],links[i].r)
227 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
229 da[i] = CrossProduct(dwp[i],links[i].r)
230 + CrossProduct(dw[i],CrossProduct(w[i],links[i].r))
231 + CrossProduct(w[i],CrossProduct(dw[i],links[i].r))
235 for(i = dof; i >= 1; i--)
237 F[i] = a[i] * links[i].m;
238 dF[i] = da[i] * links[i].m;
239 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
240 dN[i] = links[i].I*dwp[i] + CrossProduct(dw[i],links[i].I*w[i])
241 + CrossProduct(w[i],links[i].I*dw[i]);
246 n[i] = CrossProduct(p[i],f[i])
247 + CrossProduct(links[i].r,F[i]) + N[i];
248 dn[i] = CrossProduct(p[i],df[i])
249 + CrossProduct(links[i].r,dF[i]) + dN[i];
250 if(links[i].get_joint_type() != 0)
251 dn[i] += CrossProduct(dp[i],f[i])*dq(i);
255 f[i] = links[i+1].R*f[i+1] + F[i];
256 df[i] = links[i+1].R*df[i+1] + dF[i];
257 if(links[i].get_joint_type() == 0)
258 df[i] += Q*links[i+1].R*f[i+1]*dq(i+1);
259 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i],f[i])
260 + CrossProduct(links[i].r,F[i]) + N[i];
261 dn[i] = links[i+1].R*dn[i+1] + CrossProduct(p[i],df[i])
262 + CrossProduct(links[i].r,dF[i]) + dN[i];
263 if(links[i].get_joint_type() == 0)
264 dn[i] += Q*links[i+1].R*n[i+1]*dq(i+1);
266 dn[i] += CrossProduct(dp[i],f[i])*dq(i);
269 if(links[i].get_joint_type() == 0)
271 temp = ((z0.t()*links[i].R)*n[i]);
272 ltorque(i) = temp(1,1);
273 temp = ((z0.t()*links[i].R)*dn[i]);
274 dtorque(i) = temp(1,1);
278 temp = ((z0.t()*links[i].R)*f[i]);
279 ltorque(i) = temp(1,1);
280 temp = ((z0.t()*links[i].R)*df[i]);
281 dtorque(i) = temp(1,1);
288 const ColumnVector & qpp,
const ColumnVector & dq,
289 const ColumnVector & dqp,
const ColumnVector & dqpp,
290 ColumnVector & ltorque, ColumnVector & dtorque)
383 if(q.Ncols() != 1 || q.Nrows() != dof) error(
"q has wrong dimension");
384 if(qp.Ncols() != 1 || qp.Nrows() != dof) error(
"qp has wrong dimension");
385 if(qpp.Ncols() != 1 || qpp.Nrows() != dof) error(
"qpp has wrong dimension");
386 if(dq.Ncols() != 1 || dq.Nrows() != dof) error(
"dq has wrong dimension");
387 if(dqp.Ncols() != 1 || dqp.Nrows() != dof) error(
"dqp has wrong dimension");
388 if(dqpp.Ncols() != 1 || dqpp.Nrows() != dof) error(
"dqpp has wrong dimension");
389 ltorque = ColumnVector(dof);
390 dtorque = ColumnVector(dof);
395 z0(1) = 0.0; z0(2) = 0.0; z0(3) = 1.0;
400 for(i = 1; i <= dof; i++)
404 if(links[i].get_joint_type() != 0)
406 dp[i] = ColumnVector(3);
411 if(links[i].get_joint_type() == 0)
413 w[i] = Rt*w[i-1] + z0*qp(i);
414 dw[i] = Rt*dw[i-1] + z0*dqp(i)
416 wp[i] = Rt*wp[i-1] + CrossProduct(Rt*w[i-1],z0*qp(i))
418 dwp[i] = Rt*dwp[i-1] + CrossProduct(Rt*dw[i-1],z0*qp(i))
419 + CrossProduct(Rt*w[i-1],z0*dqp(i))
420 - (Q*Rt*wp[i-1] + CrossProduct(Q*Rt*w[i-1],z0*qp(i)))*dq(i)
422 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
423 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
425 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
426 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
427 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1])
428 - Q*Rt*(CrossProduct(wp[i-1],p[i])
429 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])) + vp[i-1])*dq(i);
436 dwp[i] = Rt*dwp[i-1];
437 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
438 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
439 + z0*qpp(i) + 2.0*CrossProduct(w[i],z0*qp(i));
441 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
442 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
443 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1]
444 + (CrossProduct(wp[i-1],dp[i])
445 + CrossProduct(w[i-1],CrossProduct(w[i-1],dp[i])))*dq(i))
446 + 2*(CrossProduct(dw[i],z0*qp(i)) + CrossProduct(w[i],z0*dqp(i)))
449 a[i] = CrossProduct(wp[i],links[i].r)
450 + CrossProduct(w[i],CrossProduct(w[i],links[i].r))
452 da[i] = CrossProduct(dwp[i],links[i].r)
453 + CrossProduct(dw[i],CrossProduct(w[i],links[i].r))
454 + CrossProduct(w[i],CrossProduct(dw[i],links[i].r))
458 for(i = dof; i >= 1; i--) {
459 F[i] = a[i] * links[i].m;
460 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i]);
461 dF[i] = da[i] * links[i].m;
462 dN[i] = links[i].I*dwp[i] + CrossProduct(dw[i],links[i].I*w[i])
463 + CrossProduct(w[i],links[i].I*dw[i]);
469 n[i] = CrossProduct(links[i].r,F[i]) + N[i];
470 dn[i] = dN[i] + CrossProduct(links[i].r,dF[i]);
474 f[i] = links[i+1].R*f[i+1] + F[i];
475 df[i] = links[i+1].R*df[i+1] + dF[i];
476 if(links[i+1].get_joint_type() == 0)
477 df[i] += links[i+1].R*Q*f[i+1]*dq(i+1);
479 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1])
480 + CrossProduct(links[i].r,F[i]) + N[i];
481 dn[i] = links[i+1].R*dn[i+1] + CrossProduct(p[i+1],links[i+1].R*df[i+1])
482 + CrossProduct(links[i].r,dF[i]) + dN[i];
483 if(links[i+1].get_joint_type() == 0)
484 dn[i] += (links[i+1].R*Q*n[i+1] +
485 CrossProduct(p[i+1],links[i+1].R*Q*f[i+1]))*dq(i+1);
487 dn[i] += CrossProduct(dp[i+1],links[i+1].R*f[i+1])*dq(i+1);
490 if(links[i].get_joint_type() == 0)
493 ltorque(i) = temp(1,1);
495 dtorque(i) = temp(1,1);
500 ltorque(i) = temp(1,1);
502 dtorque(i) = temp(1,1);
508 const ColumnVector & qpp,
const ColumnVector & dq,
509 const ColumnVector & dqp,
const ColumnVector & dqpp,
510 ColumnVector & ltorque, ColumnVector & dtorque)
519 if(q.Ncols() != 1 || q.Nrows() != dof) error(
"q has wrong dimension");
520 if(qp.Ncols() != 1 || qp.Nrows() != dof) error(
"qp has wrong dimension");
521 if(qpp.Ncols() != 1 || qpp.Nrows() != dof) error(
"qpp has wrong dimension");
522 if(dq.Ncols() != 1 || dq.Nrows() != dof) error(
"dq has wrong dimension");
523 if(dqp.Ncols() != 1 || dqp.Nrows() != dof) error(
"dqp has wrong dimension");
524 if(dqpp.Ncols() != 1 || dqpp.Nrows() != dof) error(
"dqpp has wrong dimension");
525 ltorque = ColumnVector(dof);
526 dtorque = ColumnVector(dof);
531 z0(1) = 0.0; z0(2) = 0.0; z0(3) = 1.0;
536 for(i = 1; i <= dof; i++)
540 if(links[i].get_joint_type() != 0)
542 dp[i] = ColumnVector(3);
547 if(links[i].get_joint_type() == 0)
549 w[i] = Rt*w[i-1] + z0*qp(i);
550 dw[i] = Rt*dw[i-1] + z0*dqp(i)
552 wp[i] = Rt*wp[i-1] + CrossProduct(Rt*w[i-1],z0*qp(i))
554 dwp[i] = Rt*dwp[i-1] + CrossProduct(Rt*dw[i-1],z0*qp(i))
555 + CrossProduct(Rt*w[i-1],z0*dqp(i))
556 - (Q*Rt*wp[i-1] + CrossProduct(Q*Rt*w[i-1],z0*qp(i)))*dq(i)
558 vp[i] = Rt*(CrossProduct(wp[i-1],p[i])
559 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i]))
561 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
562 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
563 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1])
564 - Q*Rt*(CrossProduct(wp[i-1],p[i])
565 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])) + vp[i-1])*dq(i);
572 dwp[i] = Rt*dwp[i-1];
573 vp[i] = Rt*(vp[i-1] + CrossProduct(wp[i-1],p[i])
574 + CrossProduct(w[i-1],CrossProduct(w[i-1],p[i])))
575 + z0*qpp(i)+ 2.0*CrossProduct(w[i],z0*qp(i));
576 dvp[i] = Rt*(CrossProduct(dwp[i-1],p[i])
577 + CrossProduct(dw[i-1],CrossProduct(w[i-1],p[i]))
578 + CrossProduct(w[i-1],CrossProduct(dw[i-1],p[i])) + dvp[i-1]
579 + (CrossProduct(wp[i-1],dp[i])
580 + CrossProduct(w[i-1],CrossProduct(w[i-1],dp[i])))*dq(i))
581 + 2*(CrossProduct(dw[i],z0*qp(i)) + CrossProduct(w[i],z0*dqp(i)))
586 for(i = dof; i >= 1; i--) {
587 F[i] = vp[i]*links[i].m + CrossProduct(wp[i], links[i].mc) +
588 CrossProduct(w[i], CrossProduct(w[i], links[i].mc));
589 dF[i] = dvp[i]*links[i].m + CrossProduct(dwp[i],links[i].mc)
590 + CrossProduct(dw[i],CrossProduct(w[i],links[i].mc))
591 + CrossProduct(w[i],CrossProduct(dw[i],links[i].mc));
592 N[i] = links[i].I*wp[i] + CrossProduct(w[i],links[i].I*w[i])
593 - CrossProduct(vp[i], links[i].mc);
594 dN[i] = links[i].I*dwp[i] + CrossProduct(dw[i],links[i].I*w[i])
595 + CrossProduct(w[i],links[i].I*dw[i])
596 - CrossProduct(dvp[i],links[i].mc);
607 f[i] = links[i+1].R*f[i+1] + F[i];
608 df[i] = links[i+1].R*df[i+1] + dF[i];
609 if(links[i+1].get_joint_type() == 0)
610 df[i] += links[i+1].R*Q*f[i+1]*dq(i+1);
612 n[i] = links[i+1].R*n[i+1] + CrossProduct(p[i+1],links[i+1].R*f[i+1])
614 dn[i] = links[i+1].R*dn[i+1] + CrossProduct(p[i+1],links[i+1].R*df[i+1])
616 if(links[i+1].get_joint_type() == 0)
617 dn[i] += (links[i+1].R*Q*n[i+1] +
618 CrossProduct(p[i+1],links[i+1].R*Q*f[i+1]))*dq(i+1);
620 dn[i] += CrossProduct(dp[i+1],links[i+1].R*f[i+1])*dq(i+1);
623 if(links[i].get_joint_type() == 0)
626 ltorque(i) = temp(1,1);
628 dtorque(i) = temp(1,1);
633 ltorque(i) = temp(1,1);
635 dtorque(i) = temp(1,1);