MBSim

Project Page
spring_damper.h
00001 /* Copyright (C) 2004-2009 MBSim Development Team
00002  * This library is free software; you can redistribute it and/or 
00003  * modify it under the terms of the GNU Lesser General Public 
00004  * License as published by the Free Software Foundation; either 
00005  * version 2.1 of the License, or (at your option) any later version. 
00006  *  
00007  * This library is distributed in the hope that it will be useful, 
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00010  * Lesser General Public License for more details. 
00011  *  
00012  * You should have received a copy of the GNU Lesser General Public 
00013  * License along with this library; if not, write to the Free Software 
00014  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00015  *
00016  * Contact: martin.o.foerg@googlemail.com
00017  */
00018 
00019 #ifndef _SPRINGDAMPER_H_
00020 #define _SPRINGDAMPER_H_
00021 
00022 #include "mbsim/link_mechanics.h"
00023 #include "mbsim/utils/function.h"
00024 
00025 #ifdef HAVE_OPENMBVCPPINTERFACE
00026 namespace OpenMBV {
00027   class CoilSpring;
00028 }
00029 #endif
00030 
00031 namespace MBSim {
00032 
00037   class SpringDamper : public LinkMechanics {
00038     protected:
00039       double dist;
00040       fmatvec::Vec3 n;
00041       Function2<double,double,double> *func;
00042       Frame *refFrame;
00043       fmatvec::Vec3 forceDir, WforceDir;
00044 #ifdef HAVE_OPENMBVCPPINTERFACE
00045       OpenMBV::CoilSpring *coilspringOpenMBV;
00046 #endif
00047     public:
00048       SpringDamper(const std::string &name="");
00049       void updateh(double, int i=0);
00050       void updateg(double);
00051       void updategd(double);
00052 
00054       void connect(Frame *frame1, Frame* frame2);
00055 
00056       /*INHERITED INTERFACE OF LINK*/
00057       bool isActive() const { return true; }
00058       bool gActiveChanged() { return false; }
00059       bool isSingleValued() const { return true; }
00060       std::string getType() const { return "SpringDamper"; }
00061       void init(InitStage stage);
00062       /*****************************/
00063 
00069       void setForceFunction(Function2<double,double,double> *func_) { func=func_; }
00070 
00078       void setProjectionDirection(Frame *refFrame_, fmatvec::Vec dir) { refFrame=refFrame_; forceDir=dir; }
00079 
00080       void plot(double t, double dt=1);
00081       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00082 
00083 #ifdef HAVE_OPENMBVCPPINTERFACE
00084 
00085       void setOpenMBVSpring(OpenMBV::CoilSpring *spring_) {coilspringOpenMBV=spring_;}
00086 
00088       void setOpenMBVForceArrow(OpenMBV::Arrow *arrow) {
00089         std::vector<bool> which; which.resize(2, true);
00090         LinkMechanics::setOpenMBVForceArrow(arrow, which);
00091       }
00092 #endif
00093     private:
00094       std::string saved_frameOfReference, saved_ref1, saved_ref2;
00095       fmatvec::Vec saved_direction;
00096   };
00097 
00098 }
00099 
00100 #endif /* _SPRINGDAMPER_H_ */
00101