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


orocos_kdl
Author(s): Ruben Smits, Erwin Aertbelien, Orocos Developers
autogenerated on Sat Dec 28 2013 17:17:25