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 namespace MBSim {
00028 
00029   class KinematicExcitation : public LinkMechanics {
00030     protected:
00031       Function2<fmatvec::VecV,fmatvec::VecV,fmatvec::VecV> *func;
00032       RigidBody* body;
00033       Frame C;
00034     public:
00035       KinematicExcitation(const std::string &name);
00036       void updateh(double, int i=0);
00037       void updateW(double, int i=0);
00038       void updateJacobians(double t, int j=0);
00039       void updatehRef(const fmatvec::Vec &hParent, int j=0);
00040       void updateWRef(const fmatvec::Mat &WParent, int j=0);
00041       void setDependentBody(RigidBody* body_) {body = body_;}
00042 
00043       bool isActive() const { return true; }
00044       bool gActiveChanged() { return false; }
00045       void init(InitStage stage);
00046       bool isSetValued() const;
00047       void calclaSize(int j);
00048       void calcgSize(int j);
00049       void calcgdSize(int j);
00050 
00051       void setForceFunction(Function2<fmatvec::VecV,fmatvec::VecV,fmatvec::VecV> *func_) { func=func_; }
00052 
00053       void plot(double t, double dt=1);
00054 
00055 #ifdef HAVE_OPENMBVCPPINTERFACE
00056 
00057       void setOpenMBVForceArrow(OpenMBV::Arrow *arrow) { FArrow = arrow; }
00058 
00060       void setOpenMBVMomentArrow(OpenMBV::Arrow *arrow) { MArrow = arrow; }
00061 #endif
00062 
00063     protected:
00064 #ifdef HAVE_OPENMBVCPPINTERFACE
00065       OpenMBV::Arrow *FArrow, *MArrow;
00066 #endif
00067 
00068   };
00069 
00070   class TimeDependentKinematicExcitation : public KinematicExcitation {
00071     protected:
00072       Function1<fmatvec::VecV,double> *f, *fd, *fdd;
00073       Function2<fmatvec::VecV,fmatvec::VecV,fmatvec::VecV> *func;
00074       RigidBody* body;
00075       Frame C;
00076     public:
00077       TimeDependentKinematicExcitation(const std::string &name) : KinematicExcitation(name) {}
00078 
00079       void calcxSize();
00080 
00081       void updatexd(double t);
00082       void updateg(double t);
00083       void updategd(double t);
00084       void updatewb(double t, int i=0);
00085 
00086       std::string getType() const { return "TimeDependentKinematicExcitation"; }
00087 
00088       void setGeneralizedPositionFunction(Function1<fmatvec::VecV,double>* f_) { f = f_;}
00089       void setFirstDerivativeOfGeneralizedPositionFunction(Function1<fmatvec::VecV,double>* fd_) { fd = fd_;}
00090       void setSecondDerivativeOfGeneralizedPositionFunction(Function1<fmatvec::VecV,double>* fdd_) { fdd = fdd_;}
00091   };
00092 
00093   class StateDependentKinematicExcitation : public KinematicExcitation {
00094     protected:
00095       Function1<fmatvec::VecV,fmatvec::Vec> *f;
00096       Function2<fmatvec::VecV,fmatvec::Vec,fmatvec::Vec> *fd; 
00097     public:
00098       StateDependentKinematicExcitation(const std::string &name) : KinematicExcitation(name) {}
00099 
00100       void calcxSize();
00101 
00102       void updatexd(double t);
00103       void updateg(double t);
00104       void updategd(double t);
00105       void updatewb(double t, int i=0);
00106 
00107       std::string getType() const { return "StateDependentKinematicExcitation"; }
00108 
00109       void setGeneralizedVelocityFunction(Function1<fmatvec::VecV,fmatvec::Vec>* f_) { f = f_;}
00110       void setFirstDerivativeOfGeneralizedVelocityFunction(Function2<fmatvec::VecV,fmatvec::Vec,fmatvec::Vec>* fd_) { fd = fd_;}
00111   };
00112 
00113 }
00114 
00115 #endif