46 using namespace NEWMAT;
53 pc = ColumnVector(3); pc = 0;
66 const DiagonalMatrix & Dp_,
const DiagonalMatrix & Kp_,
67 const DiagonalMatrix & Mo_,
const DiagonalMatrix & Do_,
68 const DiagonalMatrix & Ko_)
78 pc = ColumnVector(3); pc = 0;
104 Mp = DiagonalMatrix(3); Mp = 1;
105 cerr <<
"Impedance::set_Mp: wrong size for input matrix Mp" << endl;
119 if( (i < 0) || (i > 3) )
121 cerr <<
"Impedance::set_Mp: index i out of bound" << endl;
137 Dp = DiagonalMatrix(3); Dp = 1;
138 cerr <<
"Impedance::set_Dp: input matrix Dp of wrong size" << endl;
152 if( (i < 0) || (i > 3) )
154 cerr <<
"Impedance::set_Dp: index i out of bound" << endl;
170 Kp = DiagonalMatrix(3); Kp = 1;
171 cerr <<
"Impedance::set_Kp: wrong size for input matrix Kp" << endl;
185 if( (i < 0) || (i > 3) )
187 cerr <<
"Impedance::set_Mp: index i out of bound" << endl;
203 Mo = DiagonalMatrix(3); Mo = 1;
204 cerr <<
"Impedance::set_Mo: wrong size input matrix Mo" << endl;
218 if( (i < 0) || (i > 3) )
220 cerr <<
"Impedance::set_Mo: index i out of bound" << endl;
234 if( Do_.Nrows() != 3)
236 Do = DiagonalMatrix(3); Do = 1;
237 cerr <<
"Impedance::set_Do: wrong size input matrix Do" << endl;
251 if( (i < 0) || (i > 3) )
253 cerr <<
"Impedance::set_Do: index i out of bound" << endl;
269 Ko = DiagonalMatrix(3); Ko = 1;
270 cerr <<
"Impedance::set_Ko: wrong size for input matrix Ko" << endl;
284 if( (i < 0) || (i > 3) )
286 cerr <<
"Impedance::set_Ko: index i out of bound" << endl;
295 const ColumnVector & pd,
const ColumnVector & wdp,
296 const ColumnVector & wd,
const Quaternion & qd,
297 const ColumnVector & f,
const ColumnVector & n,
327 cerr <<
"Impedance::control: wrong size for input vector pdpp" << endl;
332 cerr <<
"Impedance::control: wrong size for input vector pdp" << endl;
337 cerr <<
"Impedance::control: wrong size for input vector pd" << endl;
342 cerr <<
"Impedance::control: wrong size for input vector wdp" << endl;
347 cerr <<
"Impedance::control: wrong size for input vector wd" << endl;
352 cerr <<
"Impedance::control: wrong size for input vector f" << endl;
357 cerr <<
"Impedance::control: wrong size for input vector f" << endl;
361 static bool first=
true;
365 qcp = qc.
dot(wc, BASE_FRAME);
371 if(qc.dot_prod(qd) < 0)
382 pcpp = pdpp + Mp.
i()*(f - Dp*pcdp - Kp*pcd);
383 pcp = pcp_prev +
Integ_Trap(pcpp, pcpp_prev, dt);
388 Ko_prime = 2*qcd.E(BASE_FRAME)*Ko;
391 wcp = wdp + Mo.i()*(n - Do*wcd - Ko_prime*qcd.v());
393 qcp = qc.dot(wc, BASE_FRAME);
406 Kvp = Kpp = Kvo = Kpo = 0;
407 zero3 = ColumnVector(3); zero3 = 0;
413 qp = ColumnVector(dof); qp = 0;
417 quat_v_error = zero3;
418 a = ColumnVector(6); a = 0;
433 zero3 = ColumnVector(3); zero3 = 0;
434 qp = ColumnVector(robot.
get_dof()); qp = 0;
436 a = ColumnVector(6); a = 0;
439 quat_v_error = zero3;
468 const ColumnVector & pdp,
const ColumnVector & pd,
469 const ColumnVector & wdp,
const ColumnVector & wd,
470 const Quaternion & quatd,
const short link_pc,
484 robot.
kine_pd(Rot, p, pp, link_pc);
492 quat_v_error = quate.
s()*quat.v() - quat.s()*quate.
v() +
495 a.SubMatrix(1,3,1,1) = pdpp + Kvp*(pdp-pp) + Kpp*(pd-p);
496 a.SubMatrix(4,6,1,1) = wdp + Kvo*(wd-Rot*robot.w[robot.
get_dof()]) +
501 return robot.torque(robot.
get_q(),qp, qpp, zero3, zero3);
513 qpp = ColumnVector(dof); qpp = 0;
516 zero3 = ColumnVector(3); zero3 = 0;
520 const DiagonalMatrix & Kp,
521 const DiagonalMatrix & Kd)
527 qpp = ColumnVector(dof); qpp = 0;
530 zero3 = ColumnVector(3); zero3 = 0;
534 const ColumnVector & qd,
535 const ColumnVector & qpd,
536 const ColumnVector & qppd )
539 if(qd.Nrows() != dof)
541 ColumnVector tau(dof); tau = 0;
542 cerr <<
"Computed_torque_methode::torque_cmd: wrong size for input vector qd" << endl;
546 if(qpd.Nrows() != dof)
548 ColumnVector tau(dof); tau = 0;
549 cerr <<
"Computed_torque_methode::torque_cmd: wrong size for input vector qpd" << endl;
553 if(qppd.Nrows() != dof)
555 ColumnVector tau(dof); tau = 0;
556 cerr <<
"Computed_torque_methode::torque_cmd: wrong size for input vector qppd" << endl;
563 qpp = Kp*(qd-q) + Kd*(qpd-qp) + qppd;
564 return robot.torque(q, qp, qpp, zero3, zero3);
573 if(Kd_.Nrows() != dof)
575 Kd = DiagonalMatrix(dof); Kd = 0;
576 cerr <<
"Computed_torque_method::set_kd: wrong size for input matrix Kd." << endl;
590 if(Kp_.Nrows() != dof)
592 Kp = DiagonalMatrix(dof); Kp = 0;
593 cerr <<
"Computed_torque_method::set_kp: wrong size for input matrix Kp." << endl;
609 q = ColumnVector(dof); q = 0;
611 zero3 = ColumnVector(3); zero3 = 0;
615 const DiagonalMatrix & Kp,
616 const DiagonalMatrix & Kd)
622 q = ColumnVector(dof); q = 0;
624 tau = ColumnVector(dof); tau = 0;
625 zero3 = ColumnVector(3); zero3 = 0;
629 const ColumnVector & qd,
630 const ColumnVector & qpd)
633 if(qd.Nrows() != dof)
636 cerr <<
"Proportional_Derivative::torque_cmd: wrong size for input vector qd" << endl;
639 if(qpd.Nrows() != dof)
642 cerr <<
"Proportional_Derivative::torque_cmd: wrong size for input vector qpd" << endl;
648 tau = Kp*(qd-q) + Kd*(qpd-qp);
659 if(Kd_.Nrows() != dof)
661 Kd = DiagonalMatrix(dof); Kd = 0;
662 cerr <<
"Proportional_Derivative::set_kd: wrong size for input matrix Kd." << endl;
676 if(Kp_.Nrows() != dof)
678 Kp = DiagonalMatrix(dof); Kp = 0;
679 cerr <<
"Computed_torque_method::set_kp: wrong size for input matrix Kp." << endl;