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