MBSim

Project Page
kinematic_excitation.h
00001 /* Copyright (C) 2004-2011 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: martin.o.foerg@gmail.com
00018  */
00019 
00020 #ifndef _KINEMATIC_EXCITATION_H_
00021 #define _KINEMATIC_EXCITATION_H_
00022 
00023 #include "mbsim/link_mechanics.h"
00024 #include "mbsim/rigid_body.h"
00025 #include "mbsim/frame.h"
00026 
00027 #ifdef HAVE_OPENMBVCPPINTERFACE
00028 #include "mbsim/utils/boost_parameters.h"
00029 #include "mbsim/utils/openmbv_utils.h"
00030 #endif
00031 
00032 namespace MBSim {
00033 
00034   class KinematicExcitation : public LinkMechanics {
00035     protected:
00036       fmatvec::Function<fmatvec::VecV(fmatvec::VecV,fmatvec::VecV)> *func;
00037       RigidBody* body;
00038       Frame C;
00039     public:
00040       KinematicExcitation(const std::string &name);
00041       void updateh(double, int i=0);
00042       void updateW(double, int i=0);
00043       void updateJacobians(double t, int j=0);
00044       void updatehRef(const fmatvec::Vec &hParent, int j=0);
00045       void updateWRef(const fmatvec::Mat &WParent, int j=0);
00046       void setDependentBody(RigidBody* body_) {body = body_;}
00047 
00048       bool isActive() const { return true; }
00049       bool gActiveChanged() { return false; }
00050       void init(InitStage stage);
00051       bool isSetValued() const;
00052       void calclaSize(int j);
00053       void calcgSize(int j);
00054       void calcgdSize(int j);
00055 
00056       void setForceFunction(fmatvec::Function<fmatvec::VecV(fmatvec::VecV,fmatvec::VecV)> *func_) { func=func_; }
00057 
00058       void plot(double t, double dt=1);
00059 
00060 #ifdef HAVE_OPENMBVCPPINTERFACE
00061 
00062       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVForce, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00063         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00064         FArrow=ombv.createOpenMBV(); 
00065       }
00066       void setOpenMBVForce(OpenMBV::Arrow *arrow) { FArrow=arrow; }
00067 
00069       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVMoment, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00070         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00071         MArrow=ombv.createOpenMBV(); 
00072       }
00073       void setOpenMBVMoment(OpenMBV::Arrow *arrow) { MArrow=arrow; }
00074 #endif
00075 
00076     protected:
00077 #ifdef HAVE_OPENMBVCPPINTERFACE
00078       OpenMBV::Arrow *FArrow, *MArrow;
00079 #endif
00080 
00081   };
00082 
00083   class GeneralizedPositionExcitation : public KinematicExcitation {
00084     protected:
00085       fmatvec::Function<fmatvec::VecV(double)> *f;
00086     public:
00087       GeneralizedPositionExcitation(const std::string &name) : KinematicExcitation(name) {}
00088 
00089       void calcxSize();
00090 
00091       void updatexd(double t);
00092       void updateg(double t);
00093       void updategd(double t);
00094       void updatewb(double t, int i=0);
00095 
00096       std::string getType() const { return "GeneralizedPositionExcitation"; }
00097 
00098       void setExcitationFunction(fmatvec::Function<fmatvec::VecV(double)>* f_) { f = f_;}
00099   };
00100 
00101   class GeneralizedVelocityExcitation : public KinematicExcitation {
00102     protected:
00103       fmatvec::Function<fmatvec::VecV(fmatvec::VecV,double)> *f;
00104     public:
00105       GeneralizedVelocityExcitation(const std::string &name) : KinematicExcitation(name) {}
00106 
00107       void calcxSize();
00108 
00109       void updatexd(double t);
00110       void updateg(double t);
00111       void updategd(double t);
00112       void updatewb(double t, int i=0);
00113 
00114       std::string getType() const { return "GeneralizedVelocityExcitation"; }
00115 
00116       void setExcitationFunction(fmatvec::Function<fmatvec::VecV(fmatvec::VecV,double)>* f_) { f = f_;}
00117       void setExcitationFunction(fmatvec::Function<fmatvec::VecV(fmatvec::VecV)>* f_) { f = new StateDependentFunction<fmatvec::VecV>(f_);}
00118       void setExcitationFunction(fmatvec::Function<fmatvec::VecV(double)>* f_) { f = new TimeDependentFunction<fmatvec::VecV>(f_);}
00119   };
00120 
00121   class GeneralizedAccelerationExcitation : public KinematicExcitation {
00122     protected:
00123       fmatvec::Function<fmatvec::VecV(fmatvec::VecV,double)> *f;
00124     public:
00125       GeneralizedAccelerationExcitation(const std::string &name) : KinematicExcitation(name) {}
00126 
00127       void calcxSize();
00128 
00129       void updatexd(double t);
00130       void updateg(double t);
00131       void updategd(double t);
00132       void updatewb(double t, int i=0);
00133 
00134       std::string getType() const { return "GeneralizedAccelerationExcitation"; }
00135 
00136       void setExcitationFunction(fmatvec::Function<fmatvec::VecV(fmatvec::VecV,double)>* f_) { f = f_;}
00137       void setExcitationFunction(fmatvec::Function<fmatvec::VecV(fmatvec::VecV)>* f_) { f = new StateDependentFunction<fmatvec::VecV>(f_);}
00138       void setExcitationFunction(fmatvec::Function<fmatvec::VecV(double)>* f_) { f = new TimeDependentFunction<fmatvec::VecV>(f_);}
00139   };
00140 
00141 }
00142 
00143 #endif