00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00082
00083
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
00101
00102
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 }