MBSim

Project Page
rotational_spring_damper.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * Contact: rzander@users.berlios.de
17  */
18 
19 #ifndef _ROTATIONALSPRINGDAMPER_H_
20 #define _ROTATIONALSPRINGDAMPER_H_
21 
22 #include "mbsim/link_mechanics.h"
23 #include "mbsim/utils/function.h"
24 
25 #ifdef HAVE_OPENMBVCPPINTERFACE
26 namespace OpenMBV {
27  class CoilSpring;
28 }
29 #endif
30 
31 namespace MBSim {
32 
33  class RigidBody;
39  protected:
41  Frame *refFrame;
42  RigidBody *body;
43  fmatvec::Vec torqueDir, WtorqueDir;
44 #ifdef HAVE_OPENMBVCPPINTERFACE
45  OpenMBV::CoilSpring *coilspringOpenMBV;
46 #endif
47  public:
48  RelativeRotationalSpringDamper(const std::string &name);
49  void updateh(double, int i=0);
50  void updateg(double);
51  void updategd(double);
52 
54  void connect(Frame *frame1, Frame* frame2);
55 
56  bool isActive() const { return true; }
57  bool gActiveChanged() { return false; }
58  std::string getType() const { return "RotationalSpringDamper"; }
59  void init(InitStage stage);
60 
67 
75  void setRelativeBody(RigidBody* body_);
76 
77  void plot(double t, double dt=1);
78  void initializeUsingXML(TiXmlElement *element);
79 
80 #ifdef HAVE_OPENMBVCPPINTERFACE
81 
82  void setOpenMBVSpring(OpenMBV::CoilSpring *spring_) {coilspringOpenMBV=spring_;}
83 
85  void setOpenMBVForceArrow(OpenMBV::Arrow *arrow) {
86  std::vector<bool> which; which.resize(2, true);
87  LinkMechanics::setOpenMBVForceArrow(arrow, which);
88  }
89 #endif
90  private:
91  std::string saved_frameOfReference, saved_ref1, saved_ref2;
92  fmatvec::Vec saved_direction;
93  };
94 
95 }
96 
97 #endif /* _ROTATIONALSPRINGDAMPER_H_ */
98