MBSim

Project Page
rotational_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: rzander@users.berlios.de
00017  */
00018 
00019 #ifndef _ROTATIONALSPRINGDAMPER_H_
00020 #define _ROTATIONALSPRINGDAMPER_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 
00033   class RigidBody;
00038   class RelativeRotationalSpringDamper : public LinkMechanics {
00039     protected:
00040       Function2<double,double,double> *func;
00041       Frame *refFrame;
00042       RigidBody *body;
00043       fmatvec::Vec3 torqueDir, WtorqueDir;
00044 #ifdef HAVE_OPENMBVCPPINTERFACE
00045       OpenMBV::CoilSpring *coilspringOpenMBV;
00046 #endif
00047     public:
00048       RelativeRotationalSpringDamper(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       bool isActive() const { return true; }
00057       bool gActiveChanged() { return false; }
00058       virtual bool isSingleValued() const { return true; }
00059       std::string getType() const { return "RotationalSpringDamper"; }
00060       void init(InitStage stage);
00061 
00067       void setForceFunction(Function2<double,double,double> *func_) { func=func_; }
00068 
00076       void setRelativeBody(RigidBody* body_);
00077 
00078       void plot(double t, double dt=1);
00079       void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00080 
00081 #ifdef HAVE_OPENMBVCPPINTERFACE
00082 
00083       void setOpenMBVSpring(OpenMBV::CoilSpring *spring_) {coilspringOpenMBV=spring_;}
00084 
00086       void setOpenMBVForceArrow(OpenMBV::Arrow *arrow) {
00087         std::vector<bool> which; which.resize(2, true);
00088         LinkMechanics::setOpenMBVForceArrow(arrow, which);
00089       }
00090 #endif
00091     private:
00092       std::string saved_frameOfReference, saved_ref1, saved_ref2;
00093       fmatvec::Vec saved_direction;
00094   };
00095 
00096 }
00097 
00098 #endif /* _ROTATIONALSPRINGDAMPER_H_ */
00099