articulatedbodyinertia.cpp
Go to the documentation of this file.
00001 // Copyright  (C)  2007  Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00002 
00003 // Version: 1.0
00004 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00005 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00006 // URL: http://www.orocos.org/kdl
00007 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Lesser General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2.1 of the License, or (at your option) any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Lesser General Public License for more details.
00017 
00018 // You should have received a copy of the GNU Lesser General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 
00022 #include "articulatedbodyinertia.hpp"
00023 
00024 #include <Eigen/Core>
00025 
00026 using namespace Eigen;
00027 
00028 namespace KDL{
00029     
00030   ArticulatedBodyInertia::ArticulatedBodyInertia(const RigidBodyInertia& rbi):
00031     M(Matrix3d::Zero()),I(Matrix3d::Zero()),H(Matrix3d::Zero())
00032     {
00033         this->M=Matrix3d::Identity()*rbi.m;
00034         this->I=Map<const Matrix3d>(rbi.I.data);
00035         this->H << 0,-rbi.h[2],rbi.h[1],
00036             rbi.h[2],0,-rbi.h[0],
00037             -rbi.h[1],rbi.h[0],0;
00038     }
00039     
00040     ArticulatedBodyInertia::ArticulatedBodyInertia(double m, const Vector& c, const RotationalInertia& Ic)
00041     {
00042         *this = RigidBodyInertia(m,c,Ic);
00043     }
00044 
00045   ArticulatedBodyInertia::ArticulatedBodyInertia(const Matrix3d& M, const Matrix3d& H, const Matrix3d& I):
00046     M(Matrix3d::Zero()),I(Matrix3d::Zero()),H(Matrix3d::Zero())
00047     {
00048         this->M=M;
00049         this->I=I;
00050         this->H=H;
00051     }
00052     
00053     ArticulatedBodyInertia operator*(double a,const ArticulatedBodyInertia& I){
00054         return ArticulatedBodyInertia(a*I.M,a*I.H,a*I.I);
00055     }
00056     
00057     ArticulatedBodyInertia operator+(const ArticulatedBodyInertia& Ia, const ArticulatedBodyInertia& Ib){
00058         return ArticulatedBodyInertia(Ia.M+Ib.M,Ia.H+Ib.H,Ia.I+Ib.I);
00059     }
00060 
00061     ArticulatedBodyInertia operator+(const RigidBodyInertia& Ia, const ArticulatedBodyInertia& Ib){
00062         return ArticulatedBodyInertia(Ia)+Ib;
00063     }
00064     ArticulatedBodyInertia operator-(const ArticulatedBodyInertia& Ia, const ArticulatedBodyInertia& Ib){
00065         return ArticulatedBodyInertia(Ia.M-Ib.M,Ia.H-Ib.H,Ia.I-Ib.I);
00066     }
00067 
00068     ArticulatedBodyInertia operator-(const RigidBodyInertia& Ia, const ArticulatedBodyInertia& Ib){
00069         return ArticulatedBodyInertia(Ia)-Ib;
00070     }
00071     
00072     Wrench operator*(const ArticulatedBodyInertia& I,const Twist& t){
00073         Wrench result;
00074         Vector3d::Map(result.force.data)=I.M*Vector3d::Map(t.vel.data)+I.H.transpose()*Vector3d::Map(t.rot.data);
00075         Vector3d::Map(result.torque.data)=I.I*Vector3d::Map(t.rot.data)+I.H*Vector3d::Map(t.vel.data);
00076         return result;
00077     }
00078 
00079     ArticulatedBodyInertia operator*(const Frame& T,const ArticulatedBodyInertia& I){
00080         Frame X=T.Inverse();
00081         //mb=ma
00082         //hb=R*(h-m*r)
00083         //Ib = R(Ia+r x h x + (h-m*r) x r x)R'
00084         Map<Matrix3d> E(X.M.data);
00085         Matrix3d rcross;
00086         rcross << 0,-X.p[2],X.p[1],
00087             X.p[2],0,-X.p[0],
00088             -X.p[1],X.p[0],0;
00089         
00090         Matrix3d HrM=I.H-rcross*I.M;
00091         return ArticulatedBodyInertia(E*I.M*E.transpose(),E*HrM*E.transpose(),E*(I.I-rcross*I.H.transpose()+HrM*rcross)*E.transpose());
00092     }
00093 
00094     ArticulatedBodyInertia operator*(const Rotation& M,const ArticulatedBodyInertia& I){
00095         Map<const Matrix3d> E(M.data);
00096         return ArticulatedBodyInertia(E.transpose()*I.M*E,E.transpose()*I.H*E,E.transpose()*I.I*E);
00097     }
00098 
00099     ArticulatedBodyInertia ArticulatedBodyInertia::RefPoint(const Vector& p){
00100         //mb=ma
00101         //hb=R*(h-m*r)
00102         //Ib = R(Ia+r x h x + (h-m*r) x r x)R'
00103         Matrix3d rcross;
00104         rcross << 0,-p[2],p[1],
00105             p[2],0,-p[0],
00106             -p[1],p[0],0;
00107         
00108         Matrix3d HrM=this->H-rcross*this->M;
00109         return ArticulatedBodyInertia(this->M,HrM,this->I-rcross*this->H.transpose()+HrM*rcross);
00110     }
00111 }//namespace


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