00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00101