00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef KDL_JACOBIANFRAMEVEL_H
00029 #define KDL_JACOBIANFRAMEVEL_H
00030
00031
00032
00033
00034 #include <kdl/jacobianexpr.hpp>
00035 #include <kdl/frames.hpp>
00036 #include <kdl/framevel.hpp>
00037 #include <kdl/stiffness.hpp>
00038
00039 namespace KDL {
00040
00041
00117 template <>
00118 class UnaryOp<OpInverse,FrameVel> {
00119 public:
00120 typedef FrameVel exprType;
00121 typedef Frame valueType;
00122 typedef TwistVel derivType;
00123 static INLINE2 Frame value(const Frame& F) {
00124 return F.Inverse();
00125 }
00126 static INLINE2 TwistVel deriv(const Frame& _a,const TwistVel& da) {
00127 FrameVel a(_a,da.value());
00128 return TwistVel( a.M.Inverse( da.rot*a.p-da.vel ), -a.M.Inverse( da.rot ) );
00129 }
00130 };
00131
00132 DEFUNARY_TYPE(Inverse,OpInverse,Ref<Jacobian<FrameVel> >);
00133
00143 template <>
00144 class BinaryOp<OpMult,FrameVel,FrameVel> {
00145 public:
00146 typedef FrameVel exprType;
00147 typedef Frame valueType;
00148 typedef TwistVel derivType;
00149 INLINE2 static Frame value(const Frame& a,const Frame& b) {
00150 return a*b;
00151 }
00152 INLINE2 static derivType derivVV(const Frame& _a,const TwistVel& da,const Frame& _b,const TwistVel& db) {
00153 FrameVel a(_a,da.value());
00154 FrameVel b(_b,db.value());
00155 return TwistVel(
00156 da.rot*(a.M*b.p)+a.M*db.vel+da.vel,
00157 da.rot + a.M * db.rot
00158 );
00159 }
00160 INLINE2 static derivType derivCV(const Frame& _a,const Frame& _b,const TwistVel& db) {
00161 FrameVel a(_a,Twist::Zero());
00162 FrameVel b(_b,db.value());
00163 return TwistVel(
00164 a.M*db.vel,
00165 a.M * db.rot
00166 );
00167 }
00168 INLINE2 static derivType derivVC(const Frame& _a,const TwistVel& da,const Frame& _b) {
00169 FrameVel a(_a,da.value());
00170 FrameVel b(_b,Twist::Zero());
00171 return TwistVel(
00172 da.rot*(a.M*b.p)+da.vel,
00173 da.rot
00174 );
00175 }
00176 };
00177
00178 DEFBINARY_RTYPE(operator*,OpMult,Ref<Jacobian<FrameVel> >)
00179 DEFBINARY_LTYPE(operator*,OpMult,Ref<Jacobian<FrameVel> >)
00180 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<FrameVel> >,Ref<Jacobian<FrameVel> >)
00181
00182
00183
00184
00185 template <>
00186 class BinaryOp<OpMult,FrameVel,VectorVel> {
00187 public:
00188 typedef VectorVel exprType;
00189 typedef Vector valueType;
00190 typedef VectorVel derivType;
00191
00192 INLINE2 static Vector value(const Frame& a,const Vector& b) {
00193 return a*b;
00194 }
00195
00196 INLINE2 static derivType derivVV(const Frame& _a,const TwistVel& da,const Vector& _b,const VectorVel& db) {
00197 FrameVel a(_a,da.value());
00198 VectorVel b(_b,db.value());
00199 return da.rot*(a.M*b)+a.M*db+da.vel;
00200 }
00201 INLINE2 static derivType derivCV(const Frame& _a,const Vector& ,const VectorVel& db) {
00202 FrameVel a(_a,Twist::Zero());
00203 return a.M*db;
00204 }
00205 INLINE2 static derivType derivVC(const Frame& _a,const TwistVel& da,const Vector& _b) {
00206 FrameVel a(_a,da.value());
00207 VectorVel b(_b,Vector::Zero());
00208 return da.rot*(a.M*b)+da.vel;
00209 }
00210 };
00211 DEFBINARY_RTYPE(operator*,OpMult,Ref<Jacobian<VectorVel> >)
00212 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<FrameVel> >,Ref<Jacobian<VectorVel> >)
00213
00214
00215
00216
00217 template <>
00218 class UnaryOp<OpInverse,RotationVel> {
00219 public:
00220 typedef RotationVel exprType;
00221 typedef Rotation valueType;
00222 typedef VectorVel derivType;
00223 static INLINE2 Rotation value(const Rotation& R) {
00224 return R.Inverse();
00225 }
00226 static INLINE2 VectorVel deriv(const Rotation& _a,const VectorVel& da) {
00227 RotationVel a(_a,da.value());
00228 return a.Inverse(-da);
00229 }
00230 };
00231
00232 DEFUNARY_TYPE(Inverse,OpInverse,Ref<Jacobian<RotationVel> >);
00233
00234
00235 template <>
00236 class BinaryOp<OpMult,RotationVel,RotationVel> {
00237 public:
00238 typedef RotationVel exprType;
00239 typedef Rotation valueType;
00240 typedef VectorVel derivType;
00241 INLINE2 static Rotation value(const Rotation& a,const Rotation& b) {
00242 return a*b;
00243 }
00244 INLINE2 static derivType derivVV(const Rotation& _a,const VectorVel& da,const Rotation& ,const VectorVel& db) {
00245 RotationVel a(_a,da.value());
00246 return a*db+da;
00247 }
00248 INLINE2 static derivType derivCV(const Rotation& a,const Rotation& ,const VectorVel& db) {
00249 return a*db;
00250 }
00251 INLINE2 static derivType derivVC(const Rotation& ,const VectorVel& da,const Rotation& ) {
00252 return da;
00253 }
00254 };
00255
00256 DEFBINARY_RTYPE(operator*,OpMult,Ref<Jacobian<RotationVel> >)
00257 DEFBINARY_LTYPE(operator*,OpMult,Ref<Jacobian<RotationVel> >)
00258 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<RotationVel> >,Ref<Jacobian<RotationVel> >)
00259
00260 template <>
00261 class BinaryOp<OpMult,RotationVel,VectorVel> {
00262 public:
00263 typedef VectorVel exprType;
00264 typedef Vector valueType;
00265 typedef VectorVel derivType;
00266 INLINE2 static Vector value(const Rotation& a,const Vector& b) {
00267 return a*b;
00268 }
00269 INLINE2 static derivType derivVV(const Rotation& _a,const VectorVel& da,const Vector& _b,const VectorVel& db) {
00270 RotationVel a(_a,da.value());
00271 VectorVel b(_b,db.value());
00272 return da*(a*b)+a*db;
00273 }
00274 INLINE2 static derivType derivCV(const Rotation& a,const Vector& ,const VectorVel& db) {
00275 return a*db;
00276 }
00277 INLINE2 static derivType derivVC(const Rotation& _a,const VectorVel& da,const Vector& b) {
00278 RotationVel a(_a,da.value());
00279 return da*(a*b);
00280 }
00281 };
00282
00283 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<RotationVel> >,Ref<Jacobian<VectorVel> >)
00284
00285
00286
00287
00291 template <>
00292 class BinaryOp<OpDiff,VectorVel,VectorVel> {
00293 public:
00294 typedef VectorVel exprType;
00295 typedef Vector valueType;
00296 typedef VectorVel derivType;
00297 INLINE2 static valueType value(const Vector& a,const Vector& b) {
00298 return diff(a,b);
00299 }
00300 INLINE2 static derivType derivVV(const Vector& ,const VectorVel& da,const Vector& ,const VectorVel& db) {
00301 return db-da;
00302 }
00303 INLINE2 static derivType derivCV(const Vector& ,const Vector& ,const VectorVel& db) {
00304 return db;
00305 }
00306 INLINE2 static derivType derivVC(const Vector& ,const VectorVel& da,const Vector& ) {
00307 return -da;
00308 }
00309 };
00310
00311 DEFBINARY_RTYPE(Diff,OpDiff,Ref<Jacobian<VectorVel> >)
00312 DEFBINARY_LTYPE(Diff,OpDiff,Ref<Jacobian<VectorVel> >)
00313 DEFBINARY_RLTYPE(Diff,OpDiff,Ref<Jacobian<VectorVel> >,Ref<Jacobian<VectorVel> >)
00314
00315
00316
00321 template <>
00322 class BinaryOp<OpDiff,RotationVel,RotationVel> {
00323 public:
00324 typedef VectorVel exprType;
00325 typedef Vector valueType;
00326 typedef VectorVel derivType;
00327 INLINE2 static valueType value(const Rotation& a,const Rotation& b) {
00328 return diff(a,b);
00329 }
00330 INLINE2 static derivType derivVV(const Rotation& ,const VectorVel& da,const Rotation& ,const VectorVel& db) {
00331 return db-da;
00332 }
00333 INLINE2 static derivType derivCV(const Rotation& ,const Rotation& ,const VectorVel& db) {
00334 return db;
00335 }
00336 INLINE2 static derivType derivVC(const Rotation& ,const VectorVel& da,const Rotation& ) {
00337 return -da;
00338 }
00339 };
00340
00341 DEFBINARY_RTYPE(Diff,OpDiff,Ref<Jacobian<RotationVel> >)
00342 DEFBINARY_LTYPE(Diff,OpDiff,Ref<Jacobian<RotationVel> >)
00343 DEFBINARY_RLTYPE(Diff,OpDiff,Ref<Jacobian<RotationVel> >,Ref<Jacobian<RotationVel> >)
00344
00345
00350 template <>
00351 class BinaryOp<OpDiff,FrameVel,FrameVel> {
00352 public:
00353 typedef TwistVel exprType;
00354 typedef Twist valueType;
00355 typedef TwistVel derivType;
00356 INLINE2 static valueType value(const Frame& a,const Frame& b) {
00357 return diff(a,b);
00358 }
00359 INLINE2 static derivType derivVV(const Frame& ,const TwistVel& da,const Frame& ,const TwistVel& db) {
00360 return db-da;
00361 }
00362 INLINE2 static derivType derivCV(const Frame& ,const Frame& ,const TwistVel& db) {
00363 return db;
00364 }
00365 INLINE2 static derivType derivVC(const Frame& ,const TwistVel& da,const Frame& ) {
00366 return -da;
00367 }
00368 };
00369
00370 DEFBINARY_RTYPE(Diff,OpDiff,Ref<Jacobian<FrameVel> >)
00371 DEFBINARY_LTYPE(Diff,OpDiff,Ref<Jacobian<FrameVel> >)
00372 DEFBINARY_RLTYPE(Diff,OpDiff,Ref<Jacobian<FrameVel> >,Ref<Jacobian<FrameVel> >)
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 template <>
00388 class BinaryOp<OpDot,VectorVel,VectorVel> {
00389 public:
00390 typedef double exprType;
00391 typedef double valueType;
00392 typedef doubleVel derivType;
00393
00394 INLINE2 static valueType value(const Vector& a,const Vector& b) {
00395 return dot(a,b);
00396 }
00397 INLINE2 static derivType derivVV(const Vector& _a,const VectorVel& da,const Vector& _b,const VectorVel& db) {
00398 VectorVel a(_a,da.p);
00399 VectorVel b(_b,db.p);
00400 return dot(a,db)+dot(da,b);
00401 }
00402 INLINE2 static derivType derivCV(const Vector& a,const Vector& _b,const VectorVel& db) {
00403 return dot(a,db);
00404 }
00405 INLINE2 static derivType derivVC(const Vector& a,const VectorVel& da,const Vector& b) {
00406 return dot(da,b);
00407 }
00408 };
00409
00410 DEFBINARY_RTYPE(dot,OpDot,Ref<Jacobian<VectorVel> >)
00411 DEFBINARY_LTYPE(dot,OpDot,Ref<Jacobian<VectorVel> >)
00412 DEFBINARY_RLTYPE(dot,OpDot,Ref<Jacobian<VectorVel> >,Ref<Jacobian<VectorVel> >)
00413
00414
00415 template <>
00416 class BinaryOp<OpMult,VectorVel,VectorVel> {
00417 public:
00418 typedef VectorVel exprType;
00419 typedef Vector valueType;
00420 typedef VectorVel derivType;
00421 INLINE2 static valueType value(const Vector& a,const Vector& b) {
00422 return a*b;
00423 }
00424 INLINE2 static derivType derivVV(const Vector& _a,const VectorVel& da,const Vector& _b,const VectorVel& db) {
00425 VectorVel a(_a,da.p);
00426 VectorVel b(_b,db.p);
00427 return a*db+da*b;
00428 }
00429 INLINE2 static derivType derivCV(const Vector& a,const Vector& ,const VectorVel& db) {
00430 return a*db;
00431 }
00432 INLINE2 static derivType derivVC(const Vector& ,const VectorVel& da,const Vector& b) {
00433 return da*b;
00434 }
00435 };
00436 DEFBINARY_LTYPE(operator*,OpMult,Ref<Jacobian<VectorVel> >)
00437 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<VectorVel> >,Ref<Jacobian<VectorVel> >)
00438
00439 template <>
00440 class BinaryOp<OpAdd,VectorVel,VectorVel> {
00441 public:
00442 typedef VectorVel exprType;
00443 typedef Vector valueType;
00444 typedef VectorVel derivType;
00445 INLINE2 static valueType value(const valueType& a,const valueType& b) {
00446 return a+b;
00447 }
00448 INLINE2 static derivType derivVV(const valueType& ,const derivType& da,const valueType& ,const derivType& db) {
00449 return da+db;
00450 }
00451 INLINE2 static derivType derivCV(const valueType& ,const valueType& ,const derivType& db) {
00452 return db;
00453 }
00454 INLINE2 static derivType derivVC(const valueType& ,const derivType& da,const valueType& ) {
00455 return da;
00456 }
00457 };
00458 DEFBINARY_RTYPE(operator+,OpAdd,Ref<Jacobian<VectorVel> >)
00459 DEFBINARY_LTYPE(operator+,OpAdd,Ref<Jacobian<VectorVel> >)
00460 DEFBINARY_RLTYPE(operator+,OpAdd,Ref<Jacobian<VectorVel> >,Ref<Jacobian<VectorVel> >)
00461
00462
00463
00464 template <>
00465 class BinaryOp<OpSub,VectorVel,VectorVel> {
00466 public:
00467 typedef VectorVel exprType;
00468 typedef Vector valueType;
00469 typedef VectorVel derivType;
00470 INLINE2 static valueType value(const valueType& a,const valueType& b) {
00471 return a-b;
00472 }
00473 INLINE2 static derivType derivVV(const valueType& ,const derivType& da,const valueType& ,const derivType& db) {
00474 return da-db;
00475 }
00476 INLINE2 static derivType derivCV(const valueType& ,const valueType& ,const derivType& db) {
00477 return -db;
00478 }
00479 INLINE2 static derivType derivVC(const valueType& ,const derivType& da,const valueType& ) {
00480 return da;
00481 }
00482 };
00483 DEFBINARY_RTYPE(operator-,OpSub,Ref<Jacobian<VectorVel> >)
00484 DEFBINARY_LTYPE(operator-,OpSub,Ref<Jacobian<VectorVel> >)
00485 DEFBINARY_RLTYPE(operator-,OpSub,Ref<Jacobian<VectorVel> >,Ref<Jacobian<VectorVel> >)
00486
00487 template <>
00488 class UnaryOp<OpNegate,VectorVel> {
00489 public:
00490 typedef VectorVel exprType;
00491 typedef Vector valueType;
00492 typedef VectorVel derivType;
00493 static INLINE2 valueType value(const Vector& F) {
00494 return -F;
00495 }
00496 static INLINE2 derivType deriv(const Vector& ,const VectorVel& da) {
00497 return -da;
00498 }
00499 };
00500 DEFUNARY_TYPE(operator-,OpNegate,Ref< Jacobian<VectorVel> >)
00501
00502
00503 template <>
00504 class UnaryOp<OpNorm,VectorVel> {
00505 public:
00506 typedef doubleVel exprType;
00507 typedef double valueType;
00508 typedef doubleVel derivType;
00509 static INLINE2 valueType value(const Vector& a) {
00510 return a.Norm();
00511 }
00512 static INLINE2 derivType deriv(const Vector& _a,const VectorVel& da) {
00513
00514 VectorVel a(_a,da.p);
00515 return dot(a,da)/a.Norm();
00516 }
00517 };
00518 DEFUNARY_TYPE(norm,OpNorm,Ref< Jacobian<VectorVel> >)
00519
00520
00521
00522
00523 template <>
00524 class BinaryOp<OpMult,VectorVel,doubleVel> {
00525 public:
00526 typedef VectorVel exprType;
00527 typedef Vector valueType;
00528 typedef VectorVel derivType;
00529 INLINE2 static valueType value(const Vector& a,double b) {
00530 return a*b;
00531 }
00532 INLINE2 static derivType derivVV(const Vector& _a,const VectorVel& da,double _b,const doubleVel& db) {
00533 VectorVel a(_a,da.value());
00534 doubleVel b(_b,db.value());
00535 return a*db+da*b;
00536 }
00537 INLINE2 static derivType derivCV(const Vector& _a,double ,const doubleVel& db) {
00538 VectorVel a(_a,Vector::Zero());
00539 return a*db;
00540 }
00541 INLINE2 static derivType derivVC(const Vector& ,const VectorVel& da,double b) {
00542 return da*b;
00543 }
00544 };
00545
00546
00547
00548 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<VectorVel> >,Ref<Jacobian<doubleVel> >)
00549
00550 template <>
00551 class BinaryOp<OpMult,doubleVel,VectorVel> {
00552 public:
00553 typedef VectorVel exprType;
00554 typedef Vector valueType;
00555 typedef VectorVel derivType;
00556 INLINE2 static valueType value(const double& a,const Vector& b) {
00557 return a*b;
00558 }
00559 INLINE2 static derivType derivVV(double _a,const doubleVel& da,const Vector& _b,const VectorVel& db) {
00560 doubleVel a(_a,da.value());
00561 VectorVel b(_b,db.value());
00562 return a*db+da*b;
00563 }
00564 INLINE2 static derivType derivCV(double a,const Vector& ,const VectorVel& db) {
00565 return a*db;
00566 }
00567 INLINE2 static derivType derivVC(double ,const doubleVel& da,const Vector& _b) {
00568 VectorVel b(_b);
00569 return da*b;
00570 }
00571 };
00572
00573
00574
00575 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<doubleVel> >,Ref<Jacobian<VectorVel> >)
00576
00577
00578
00579
00580
00581
00582
00583
00584 template <>
00585 class UnaryOp<OpRotation,FrameVel> {
00586 public:
00587 typedef RotationVel exprType;
00588 typedef Rotation valueType;
00589 typedef VectorVel derivType;
00590
00591 static INLINE2 Rotation value(const Frame& F) {
00592 return F.M;
00593 }
00594
00595 static INLINE2 VectorVel deriv(const Frame& ,const TwistVel& da) {
00596 return da.rot;
00597 }
00598 };
00599
00600 DEFUNARY_TYPE(RotMat,OpRotation,Ref<Jacobian<FrameVel> >);
00601
00602
00603
00604 template <>
00605 class UnaryOp<OpOrigin,FrameVel> {
00606 public:
00607 typedef VectorVel exprType;
00608 typedef Vector valueType;
00609 typedef VectorVel derivType;
00610
00611 static INLINE2 Vector value(const Frame& F) {
00612 return F.p;
00613 }
00614 static INLINE2 VectorVel deriv(const Frame& ,const TwistVel& da) {
00615 return da.vel;
00616 }
00617 };
00618
00619 DEFUNARY_TYPE(Origin,OpOrigin,Ref<Jacobian<FrameVel> >);
00620
00621
00622 template <>
00623 class UnaryOp<OpUnitX,RotationVel> {
00624 public:
00625 typedef VectorVel exprType;
00626 typedef Vector valueType;
00627 typedef VectorVel derivType;
00628
00629 static INLINE2 Vector value(const Rotation& R) {
00630 return R.UnitX();
00631 }
00632 static INLINE2 VectorVel deriv(const Rotation& _a,const VectorVel& da) {
00633 RotationVel a(_a,da.value());
00634 return da * a.UnitX();
00635 }
00636 };
00637
00638 DEFUNARY_TYPE(UnitX,OpUnitX,Ref<Jacobian<RotationVel> >);
00639
00640 template <>
00641 class UnaryOp<OpUnitY,RotationVel> {
00642 public:
00643 typedef VectorVel exprType;
00644 typedef Vector valueType;
00645 typedef VectorVel derivType;
00646 static INLINE2 Vector value(const Rotation& R) {
00647 return R.UnitY();
00648 }
00649 static INLINE2 VectorVel deriv(const Rotation& _a,const VectorVel& da) {
00650 RotationVel a(_a,da.value());
00651 return da * a.UnitY();
00652 }
00653 };
00654
00655 DEFUNARY_TYPE(UnitY,OpUnitY,Ref<Jacobian<RotationVel> >);
00656
00657
00658 template <>
00659 class UnaryOp<OpUnitZ,RotationVel> {
00660 public:
00661 typedef VectorVel exprType;
00662 typedef Vector valueType;
00663 typedef VectorVel derivType;
00664 static INLINE2 Vector value(const Rotation& R) {
00665 return R.UnitZ();
00666 }
00667 static INLINE2 VectorVel deriv(const Rotation& _a,const VectorVel& da) {
00668 RotationVel a(_a,da.value());
00669 return da * a.UnitZ();
00670 }
00671 };
00672
00673 DEFUNARY_TYPE(UnitZ,OpUnitZ,Ref<Jacobian<RotationVel> >);
00674
00675 template <>
00676 class UnaryOp<OpCoordX,VectorVel> {
00677 public:
00678 typedef doubleVel exprType;
00679 typedef double valueType;
00680 typedef doubleVel derivType;
00681 static INLINE2 double value(const Vector& a) {
00682 return a[0];
00683 }
00684 static INLINE2 doubleVel deriv(const Vector& ,const VectorVel& da) {
00685 return doubleVel(da.p[0],da.v[0]);
00686 }
00687 };
00688
00689 DEFUNARY_TYPE(CoordX,OpCoordX,Ref<Jacobian<VectorVel> >);
00690
00691 template <>
00692 class UnaryOp<OpCoordY,VectorVel> {
00693 public:
00694 typedef doubleVel exprType;
00695 typedef double valueType;
00696 typedef doubleVel derivType;
00697 static INLINE2 double value(const Vector& a) {
00698 return a[1];
00699 }
00700 static INLINE2 doubleVel deriv(const Vector& ,const VectorVel& da) {
00701 return doubleVel(da.p[1],da.v[1]);
00702 }
00703 };
00704
00705 DEFUNARY_TYPE(CoordY,OpCoordY,Ref<Jacobian<VectorVel> >);
00706
00707 template <>
00708 class UnaryOp<OpCoordZ,VectorVel> {
00709 public:
00710 typedef doubleVel exprType;
00711 typedef double valueType;
00712 typedef doubleVel derivType;
00713 static INLINE2 double value(const Vector& a) {
00714 return a[2];
00715 }
00716 static INLINE2 doubleVel deriv(const Vector& ,const VectorVel& da) {
00717 return doubleVel(da.p[2],da.v[2]);
00718 }
00719 };
00720
00721 DEFUNARY_TYPE(CoordZ,OpCoordZ,Ref<Jacobian<VectorVel> >);
00722
00723 #if 0
00724
00725 template <>
00726 class UnaryOp<OpRotX,double> {
00727 public:
00728 typedef Rotation valueType;
00729 typedef Vector derivType;
00730 static INLINE2 Rotation value(double angle) {
00731 return Rotation::RotX(angle);
00732 }
00733 static INLINE2 Vector deriv(double ,double da) {
00734 return Vector(da,0,0);
00735 }
00736 };
00737 DEFUNARY_TYPE(RotX,OpRotX,Ref<Jacobian<double> >);
00738
00739 template <>
00740 class UnaryOp<OpRotY,double> {
00741 public:
00742 typedef Rotation valueType;
00743 typedef Vector derivType;
00744 static INLINE2 Rotation value(double angle) {
00745 return Rotation::RotY(angle);
00746 }
00747 static INLINE2 Vector deriv(double ,double da) {
00748 return Vector(0,da,0);
00749 }
00750 };
00751 DEFUNARY_TYPE(RotY,OpRotY,Ref<Jacobian<double> >);
00752
00753 template <>
00754 class UnaryOp<OpRotZ,double> {
00755 public:
00756 typedef Rotation valueType;
00757 typedef Vector derivType;
00758 static INLINE2 Rotation value(double angle) {
00759 return Rotation::RotZ(angle);
00760 }
00761 static INLINE2 Vector deriv(double ,double da) {
00762 return Vector(0,0,da);
00763 }
00764 };
00765 DEFUNARY_TYPE(RotZ,OpRotZ,Ref<Jacobian<double> >);
00766
00767
00768 #endif
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785 template <>
00786 class UnaryOp<OpNegate,TwistVel> {
00787 public:
00788 typedef TwistVel exprType;
00789 typedef Twist valueType;
00790 typedef TwistVel derivType;
00791 static INLINE2 valueType value(const Twist& F) {
00792 return -F;
00793 }
00794 static INLINE2 derivType deriv(const Twist& ,const TwistVel& da) {
00795 return -da;
00796 }
00797 };
00798
00799 DEFUNARY_TYPE(operator-,OpNegate,Ref< Jacobian<TwistVel> >)
00800
00801
00802
00803 template <>
00804 class BinaryOp<OpAdd,TwistVel,TwistVel> {
00805 public:
00806 typedef TwistVel exprType;
00807 typedef Twist valueType;
00808 typedef TwistVel derivType;
00809 INLINE2 static valueType value(const Twist& a,const Twist& b) {
00810 return a+b;
00811 }
00812
00813 INLINE2 static derivType derivVV(const Twist&,const TwistVel& da,const Twist&,const TwistVel& db) {
00814 return da+db;
00815 }
00816 INLINE2 static derivType derivCV(const Twist& ,const Twist& ,const TwistVel& db) {
00817 return db;
00818 }
00819 INLINE2 static derivType derivVC(const Twist& ,const TwistVel& da,const Twist& ) {
00820 return da;
00821 }
00822 };
00823 DEFBINARY_RTYPE(operator+,OpAdd,Ref<Jacobian<TwistVel> >)
00824 DEFBINARY_RLTYPE(operator+,OpAdd,Ref<Jacobian<TwistVel> >,Ref<Jacobian<TwistVel> >)
00825
00826
00827 template <>
00828 class BinaryOp<OpSub,TwistVel,TwistVel> {
00829 public:
00830 typedef TwistVel exprType;
00831 typedef Twist valueType;
00832 typedef TwistVel derivType;
00833 INLINE2 static valueType value(const Twist& a,const Twist& b) {
00834 return a-b;
00835 }
00836
00837 INLINE2 static derivType derivVV(const Twist&,const TwistVel& da,const Twist&,const TwistVel& db) {
00838 return da-db;
00839 }
00840 INLINE2 static derivType derivCV(const Twist& ,const Twist& ,const TwistVel& db) {
00841 return -db;
00842 }
00843 INLINE2 static derivType derivVC(const Twist& ,const TwistVel& da,const Twist& ) {
00844 return da;
00845 }
00846 };
00847 DEFBINARY_RTYPE(operator-,OpSub,Ref<Jacobian<TwistVel> >)
00848 DEFBINARY_RLTYPE(operator-,OpSub,Ref<Jacobian<TwistVel> >,Ref<Jacobian<TwistVel> >)
00849
00850 template <>
00851 class BinaryOp<OpMult,RotationVel,TwistVel> {
00852 public:
00853 typedef TwistVel exprType;
00854 typedef Twist valueType;
00855 typedef TwistVel derivType;
00856
00857 INLINE2 static valueType value(const Rotation& a,const Twist& b) {
00858 return a*b;
00859 }
00860
00861 INLINE2 static derivType derivVV(const Rotation& _a,const VectorVel& da,const Twist& _b,const TwistVel& db) {
00862 RotationVel a(_a,da.value());
00863 TwistVel b(_b,db.value());
00864 return TwistVel(
00865 a*db.vel+da*(a*b.vel),
00866 a*db.rot+da*(a*b.rot)
00867 );
00868 }
00869 INLINE2 static derivType derivCV(const Rotation& a,const Twist& ,const TwistVel& db) {
00870 return TwistVel(
00871 a*db.vel,
00872 a*db.rot
00873 );
00874 }
00875 INLINE2 static derivType derivVC(const Rotation& _a,const VectorVel& da,const Twist& b) {
00876 RotationVel a(_a,da.value());
00877 return TwistVel(
00878 da*(a*b.vel),
00879 da*(a*b.rot)
00880 );
00881
00882 }
00883 };
00884 DEFBINARY_RTYPE(operator*,OpMult,Ref<Jacobian<TwistVel> >)
00885 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<RotationVel> >,Ref<Jacobian<TwistVel> >)
00886
00887
00888 template <>
00889 class BinaryOp<OpMult,TwistVel,doubleVel> {
00890 public:
00891 typedef TwistVel exprType;
00892 typedef Twist valueType;
00893 typedef TwistVel derivType;
00894 INLINE2 static valueType value(const Twist& a,double b) {
00895 return a*b;
00896 }
00897
00898 INLINE2 static derivType derivVV(const Twist& _a,const TwistVel& da,double _b,doubleVel db) {
00899 TwistVel a(_a,da.value());
00900 doubleVel b(_b,db.value());
00901 return a*db+da*b;
00902 }
00903 INLINE2 static derivType derivCV(const Twist& a,double ,doubleVel db) {
00904 return a*db;
00905 }
00906 INLINE2 static derivType derivVC(const Twist& ,const TwistVel& da,double b) {
00907 return da*b;
00908 }
00909 };
00910
00911 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<TwistVel> >,Ref<Jacobian<doubleVel> >)
00912
00913
00914 template <>
00915 class BinaryOp<OpMult,doubleVel,TwistVel> {
00916 public:
00917 typedef TwistVel exprType;
00918 typedef Twist valueType;
00919 typedef TwistVel derivType;
00920 INLINE2 static valueType value(double a,const Twist& b) {
00921 return a*b;
00922 }
00923
00924 INLINE2 static derivType derivVV(double _a,const doubleVel& da,const Twist& _b,const TwistVel& db) {
00925 doubleVel a(_a,da.value());
00926 TwistVel b(_b,db.value());
00927 return a*db+da*b;
00928 }
00929 INLINE2 static derivType derivCV(double a,const Twist& ,const TwistVel& db) {
00930 return a*db;
00931 }
00932 INLINE2 static derivType derivVC(double ,const doubleVel& da,const Twist& b) {
00933 return da*b;
00934 }
00935 };
00936
00937 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<doubleVel> >,Ref<Jacobian<TwistVel> >)
00938
00939 template <>
00940 class BinaryOp<OpRefPoint,TwistVel,VectorVel> {
00941 public:
00942 typedef TwistVel exprType;
00943 typedef Twist valueType;
00944 typedef TwistVel derivType;
00945 INLINE2 static valueType value(const Twist& a,const Vector& b) {
00946
00947 return a.RefPoint(b);
00948 }
00949
00950 INLINE2 static derivType derivVV(
00951 const Twist& _a,const TwistVel& da,
00952 const Vector& _b,const VectorVel& db)
00953 {
00954 TwistVel a(_a,da.value());
00955 VectorVel b(_b,db.value());
00956 return TwistVel(
00957 da.vel + da.rot*b + a.rot*db,
00958 da.rot
00959 );
00960 }
00961 INLINE2 static derivType derivCV(const Twist& a,const Vector& ,const VectorVel& db) {
00962 return TwistVel(
00963 a.rot*db,
00964 VectorVel::Zero()
00965 );
00966 }
00967 INLINE2 static derivType derivVC(const Twist& ,const TwistVel& da,const Vector& b) {
00968 return TwistVel(
00969 da.vel + da.rot*b,
00970 da.rot
00971 );
00972 }
00973 };
00974
00975 DEFBINARY_LTYPE(RefPoint,OpRefPoint,Ref<Jacobian<TwistVel> >)
00976 DEFBINARY_RTYPE(RefPoint,OpRefPoint,Ref<Jacobian<VectorVel> >)
00977 DEFBINARY_RLTYPE(RefPoint,OpRefPoint,Ref<Jacobian<TwistVel> >,Ref<Jacobian<VectorVel> >)
00978
00979 #if 0
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990 template <>
00991 class UnaryOp<OpNegate,Wrench> {
00992 public:
00993 typedef Wrench valueType;
00994 typedef Wrench derivType;
00995 static INLINE2 valueType value(const Wrench& F) {
00996 return -F;
00997 }
00998 static INLINE2 derivType deriv(const Wrench& ,const Wrench& da) {
00999 return -da;
01000 }
01001 };
01002
01003 DEFUNARY_TYPE(operator-,OpNegate,Ref< Jacobian<Wrench> >)
01004
01005
01006
01007 template <>
01008 class BinaryOp<OpAdd,Wrench,Wrench> {
01009 public:
01010 typedef Wrench valueType;
01011 typedef Wrench derivType;
01012 INLINE2 static valueType value(const Wrench& a,const Wrench& b) {
01013 return a+b;
01014 }
01015
01016 INLINE2 static derivType derivVV(const Wrench&,const Wrench& da,const Wrench&,const Wrench& db) {
01017 return da+db;
01018 }
01019 INLINE2 static derivType derivCV(const Wrench& ,const Wrench& ,const Wrench& db) {
01020 return db;
01021 }
01022 INLINE2 static derivType derivVC(const Wrench& ,const Wrench& da,const Wrench& ) {
01023 return da;
01024 }
01025 };
01026 DEFBINARY_RTYPE(operator+,OpAdd,Ref<Jacobian<Wrench> >)
01027 DEFBINARY_RLTYPE(operator+,OpAdd,Ref<Jacobian<Wrench> >,Ref<Jacobian<Wrench> >)
01028
01029
01030 template <>
01031 class BinaryOp<OpSub,Wrench,Wrench> {
01032 public:
01033 typedef Wrench valueType;
01034 typedef Wrench derivType;
01035 INLINE2 static valueType value(const Wrench& a,const Wrench& b) {
01036 return a-b;
01037 }
01038
01039 INLINE2 static derivType derivVV(const Wrench&,const Wrench& da,const Wrench&,const Wrench& db) {
01040 return da-db;
01041 }
01042 INLINE2 static derivType derivCV(const Wrench& ,const Wrench& ,const Wrench& db) {
01043 return -db;
01044 }
01045 INLINE2 static derivType derivVC(const Wrench& ,const Wrench& da,const Wrench& ) {
01046 return da;
01047 }
01048 };
01049 DEFBINARY_RTYPE(operator-,OpSub,Ref<Jacobian<Wrench> >)
01050 DEFBINARY_RLTYPE(operator-,OpSub,Ref<Jacobian<Wrench> >,Ref<Jacobian<Wrench> >)
01051
01052 template <>
01053 class BinaryOp<OpMult,Rotation,Wrench> {
01054 public:
01055 typedef Wrench valueType;
01056 typedef Wrench derivType;
01057 INLINE2 static valueType value(const Rotation& a,const Wrench& b) {
01058 return a*b;
01059 }
01060
01061 INLINE2 static derivType derivVV(const Rotation& a,const Vector& da,const Wrench& b,const Wrench& db) {
01062 return Wrench(
01063 a*db.force+da*(a*b.force),
01064 a*db.torque+da*(a*b.torque)
01065 );
01066 }
01067 INLINE2 static derivType derivCV(const Rotation& a,const Wrench& ,const Wrench& db) {
01068 return Wrench(
01069 a*db.force,
01070 a*db.torque
01071 );
01072 }
01073 INLINE2 static derivType derivVC(const Rotation& a,const Vector& da,const Wrench& b) {
01074 return Wrench(
01075 da*(a*b.force),
01076 da*(a*b.torque)
01077 );
01078
01079 }
01080 };
01081 DEFBINARY_RTYPE(operator*,OpMult,Ref<Jacobian<Wrench> >)
01082 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<Rotation> >,Ref<Jacobian<Wrench> >)
01083
01084
01085 template <>
01086 class BinaryOp<OpMult,Wrench,double> {
01087 public:
01088 typedef Wrench valueType;
01089 typedef Wrench derivType;
01090 INLINE2 static valueType value(const Wrench& a,double b) {
01091 return a*b;
01092 }
01093
01094 INLINE2 static derivType derivVV(const Wrench& a,const Wrench& da,double b,double db) {
01095 return a*db+da*b;
01096 }
01097 INLINE2 static derivType derivCV(const Wrench& a,double ,double db) {
01098 return a*db;
01099 }
01100 INLINE2 static derivType derivVC(const Wrench& ,const Wrench& da,double b) {
01101 return da*b;
01102 }
01103 };
01104
01105 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<Wrench> >,Ref<Jacobian<double> >)
01106
01107
01108 template <>
01109 class BinaryOp<OpMult,double,Wrench> {
01110 public:
01111 typedef Wrench valueType;
01112 typedef Wrench derivType;
01113 INLINE2 static valueType value(double a,const Wrench& b) {
01114 return a*b;
01115 }
01116
01117 INLINE2 static derivType derivVV(double a,double da,const Wrench& b,const Wrench& db) {
01118 return a*db+da*b;
01119 }
01120 INLINE2 static derivType derivCV(double a,const Wrench& ,const Wrench& db) {
01121 return a*db;
01122 }
01123 INLINE2 static derivType derivVC(double ,double da,const Wrench& b) {
01124 return da*b;
01125 }
01126 };
01127
01128 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Jacobian<double> >,Ref<Jacobian<Wrench> >)
01129
01130 template <>
01131 class BinaryOp<OpRefPoint,Wrench,Vector> {
01132 public:
01133 typedef Wrench valueType;
01134 typedef Wrench derivType;
01135 INLINE2 static valueType value(const Wrench& a,const Vector& b) {
01136
01137 return a.RefPoint(b);
01138 }
01139
01140 INLINE2 static derivType derivVV(
01141 const Wrench& a,const Wrench& da,
01142 const Vector& b,const Vector& db)
01143 {
01144 return Wrench(
01145 da.force,
01146 da.torque + da.force*b + a.force*db
01147 );
01148 }
01149 INLINE2 static derivType derivCV(const Wrench& a,const Vector& ,const Vector& db) {
01150 return Wrench(
01151 Vector::Zero(),
01152 a.force*db
01153 );
01154 }
01155 INLINE2 static derivType derivVC(const Wrench& ,const Wrench& da,const Vector& b) {
01156 return Wrench(
01157 da.force,
01158 da.torque + da.force*b
01159 );
01160 }
01161 };
01162
01163 DEFBINARY_LTYPE(RefPoint,OpRefPoint,Ref<Jacobian<Wrench> >)
01164
01165 DEFBINARY_RLTYPE(RefPoint,OpRefPoint,Ref<Jacobian<Wrench> >,Ref<Jacobian<Vector> >)
01166
01167
01172 template <>
01173 class BinaryOp<OpMult,Stiffness,Twist> {
01174 public:
01175 typedef Wrench valueType;
01176 typedef Wrench derivType;
01177 INLINE2 static valueType value(const Stiffness& a,const Twist& b) {
01178
01179 return a*b;
01180 }
01181
01182 INLINE2 static derivType derivVV(
01183 const Stiffness& a,const Stiffness& da,
01184 const Twist& b,const Twist& db)
01185 {
01186
01187 return a*db+da*b;
01188 }
01189 INLINE2 static derivType derivCV(const Stiffness& a,const Twist& ,const Twist& db) {
01190 return a*db;
01191 }
01192 INLINE2 static derivType derivVC(const Stiffness& ,const Stiffness& da,const Twist& b) {
01193
01194 return da*b;
01195 }
01196 };
01197
01198 DEFBINARY_LTYPE(operator*,OpMult,Ref<Cnst<Stiffness> >)
01199
01200 DEFBINARY_RLTYPE(operator*,OpMult,Ref<Cnst<Stiffness> >,Ref<Jacobian<Twist> >)
01201
01202
01203
01204 template <>
01205 class BinaryOp<OpInverse,Stiffness,Wrench> {
01206 public:
01207 typedef Twist valueType;
01208 typedef Twist derivType;
01209 INLINE2 static valueType value(const Stiffness& a,const Wrench& b) {
01210
01211 return a.Inverse(b);
01212 }
01213
01214 INLINE2 static derivType derivVV(
01215 const Stiffness& ,const Stiffness& da,
01216 const Wrench& b,const Wrench& )
01217 {
01218
01219 return da.Inverse(b);
01220 }
01221 INLINE2 static derivType derivCV(const Stiffness& a,const Wrench& ,const Wrench& db) {
01222 return a.Inverse(db);
01223 }
01224 INLINE2 static derivType derivVC(const Stiffness& ,const Stiffness& da,const Wrench& b) {
01225
01226 return da.Inverse(b);
01227 }
01228 };
01229
01230
01231
01232 DEFBINARY_RLTYPE(Inverse,OpInverse,Ref<Cnst<Stiffness> >,Ref<Jacobian<Wrench> >)
01233
01234
01235
01236
01237
01245 int GetEulerZYX(const Jacobian<Rotation>& JR,
01246 Jacobian<double>& gamma,
01247 Jacobian<double>& beta,
01248 Jacobian<double>& alpha,
01249 double eps=epsilon);
01250
01251
01259 void SetEulerZYX(const Jacobian<double>& gamma,
01260 const Jacobian<double>& beta,
01261 const Jacobian<double>& alpha,
01262 Jacobian<Rotation>& JR);
01271 inline int GetRPY(const Jacobian<Rotation>& JR,
01272 Jacobian<double>& roll,
01273 Jacobian<double>& pitch,
01274 Jacobian<double>& yaw,
01275 double eps=epsilon) {
01276 return GetEulerZYX(JR,roll,pitch,yaw);
01277 }
01278
01279
01287 inline void SetRPY(const Jacobian<double>& roll,
01288 const Jacobian<double>& pitch,
01289 const Jacobian<double>& yaw,
01290 Jacobian<Rotation>& JR) {
01291 SetEulerZYX(roll,pitch,yaw,JR);
01292 }
01293
01294
01295
01296 #endif //#if 0 // not operational
01297
01298 }
01299 #endif
01300
01301
01302