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       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(Function<fmatvec::VecV(fmatvec::VecV,fmatvec::VecV)> *func_) {
00057         func=func_;
00058         func->setParent(this);
00059         func->setName("Force");
00060       }
00061 
00062       void plot(double t, double dt=1);
00063 
00064 #ifdef HAVE_OPENMBVCPPINTERFACE
00065 
00066       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))) { 
00067         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00068         FArrow=ombv.createOpenMBV(); 
00069       }
00070       void setOpenMBVForce(OpenMBV::Arrow *arrow) { FArrow=arrow; }
00071 
00073       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))) { 
00074         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00075         MArrow=ombv.createOpenMBV(); 
00076       }
00077       void setOpenMBVMoment(OpenMBV::Arrow *arrow) { MArrow=arrow; }
00078 #endif
00079 
00080     protected:
00081 #ifdef HAVE_OPENMBVCPPINTERFACE
00082       OpenMBV::Arrow *FArrow, *MArrow;
00083 #endif
00084 
00085   };
00086 
00087   class GeneralizedPositionExcitation : public KinematicExcitation {
00088     protected:
00089       Function<fmatvec::VecV(double)> *f;
00090     public:
00091       GeneralizedPositionExcitation(const std::string &name) : KinematicExcitation(name) {}
00092 
00093       void calcxSize();
00094 
00095       void updatexd(double t);
00096       void updateg(double t);
00097       void updategd(double t);
00098       void updatewb(double t, int i=0);
00099 
00100       std::string getType() const { return "GeneralizedPositionExcitation"; }
00101 
00102       void setExcitationFunction(Function<fmatvec::VecV(double)>* f_) {
00103         f = f_;
00104         f->setParent(this);
00105         f->setName("Excitation");
00106       }
00107       void init(Element::InitStage stage) {
00108         KinematicExcitation::init(stage);
00109         f->init(stage);
00110       }
00111   };
00112 
00113   class GeneralizedVelocityExcitation : public KinematicExcitation {
00114     protected:
00115       Function<fmatvec::VecV(fmatvec::VecV,double)> *f;
00116     public:
00117       GeneralizedVelocityExcitation(const std::string &name) : KinematicExcitation(name) {}
00118 
00119       void calcxSize();
00120 
00121       void updatexd(double t);
00122       void updateg(double t);
00123       void updategd(double t);
00124       void updatewb(double t, int i=0);
00125 
00126       std::string getType() const { return "GeneralizedVelocityExcitation"; }
00127 
00128       void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV,double)>* f_) { f = f_;}
00129       void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV)>* f_) { f = new StateDependentFunction<fmatvec::VecV>(f_);}
00130       void setExcitationFunction(Function<fmatvec::VecV(double)>* f_) { f = new TimeDependentFunction<fmatvec::VecV>(f_);}
00131   };
00132 
00133   class GeneralizedAccelerationExcitation : public KinematicExcitation {
00134     protected:
00135       Function<fmatvec::VecV(fmatvec::VecV,double)> *f;
00136     public:
00137       GeneralizedAccelerationExcitation(const std::string &name) : KinematicExcitation(name) {}
00138 
00139       void calcxSize();
00140 
00141       void updatexd(double t);
00142       void updateg(double t);
00143       void updategd(double t);
00144       void updatewb(double t, int i=0);
00145 
00146       std::string getType() const { return "GeneralizedAccelerationExcitation"; }
00147 
00148       void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV,double)>* f_) { f = f_;}
00149       void setExcitationFunction(Function<fmatvec::VecV(fmatvec::VecV)>* f_) { f = new StateDependentFunction<fmatvec::VecV>(f_);}
00150       void setExcitationFunction(Function<fmatvec::VecV(double)>* f_) { f = new TimeDependentFunction<fmatvec::VecV>(f_);}
00151   };
00152 
00153 }
00154 
00155 #endif