All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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: martin.o.foerg@googlemail.com
17  */
18 
19 #ifndef _SPRINGDAMPER_H_
20 #define _SPRINGDAMPER_H_
21 
22 #include "mbsim/link_mechanics.h"
23 #include <mbsim/frame.h>
24 #include "mbsim/functions/function.h"
25 
26 #ifdef HAVE_OPENMBVCPPINTERFACE
27 #include "mbsim/utils/boost_parameters.h"
28 #include "mbsim/utils/openmbv_utils.h"
29 #endif
30 
31 namespace MBSim {
32 
33  class RigidBody;
34 
39  class SpringDamper : public LinkMechanics {
40  protected:
41  double dist;
42  fmatvec::Vec3 n;
43  Function<double(double,double)> *func;
44 #ifdef HAVE_OPENMBVCPPINTERFACE
45  boost::shared_ptr<OpenMBV::CoilSpring> coilspringOpenMBV;
46 #endif
47  public:
48  SpringDamper(const std::string &name="");
49  ~SpringDamper();
50  void updateh(double, int i=0);
51  void updateg(double);
52  void updategd(double);
53 
55  void connect(Frame *frame1, Frame* frame2);
56 
57  /*INHERITED INTERFACE OF LINK*/
58  bool isActive() const { return true; }
59  bool gActiveChanged() { return false; }
60  bool isSingleValued() const { return true; }
61  std::string getType() const { return "SpringDamper"; }
62  void init(InitStage stage);
63  /*****************************/
64 
70  void setForceFunction(Function<double(double,double)> *func_) {
71  func=func_;
72  func->setParent(this);
73  func->setName("Force");
74  }
75 
76  void plot(double t, double dt=1);
77  void initializeUsingXML(xercesc::DOMElement *element);
78 
79 #ifdef HAVE_OPENMBVCPPINTERFACE
80 
81  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVCoilSpring, tag, (optional (numberOfCoils,(int),3)(springRadius,(double),1)(crossSectionRadius,(double),-1)(nominalLength,(double),-1)(type,(OpenMBV::CoilSpring::Type),OpenMBV::CoilSpring::tube)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
82  OpenMBVCoilSpring ombv(springRadius,crossSectionRadius,1,numberOfCoils,nominalLength,type,diffuseColor,transparency);
83  coilspringOpenMBV=ombv.createOpenMBV();
84  }
85 
87  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVForce, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
88  OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
89  std::vector<bool> which; which.resize(2, true);
90  LinkMechanics::setOpenMBVForceArrow(ombv.createOpenMBV(), which);
91  }
92 #endif
93  private:
94  std::string saved_ref1, saved_ref2;
95  };
96 
102  protected:
103  double dist;
104  Function<double(double,double)> *func;
105  Frame *refFrame;
106  fmatvec::Vec3 forceDir, WforceDir, WrP0P1;
107  Frame C;
108 #ifdef HAVE_OPENMBVCPPINTERFACE
109  boost::shared_ptr<OpenMBV::CoilSpring> coilspringOpenMBV;
110 #endif
111  public:
112  DirectionalSpringDamper(const std::string &name="");
114  void updateh(double, int i=0);
115  void updateg(double);
116  void updategd(double);
117 
119  void connect(Frame *frame1, Frame* frame2);
120 
121  /*INHERITED INTERFACE OF LINK*/
122  bool isActive() const { return true; }
123  bool gActiveChanged() { return false; }
124  bool isSingleValued() const { return true; }
125  std::string getType() const { return "DirectionalSpringDamper"; }
126  void init(InitStage stage);
127  /*****************************/
128 
134  void setForceFunction(Function<double(double,double)> *func_) {
135  func=func_;
136  func->setParent(this);
137  func->setName("Force");
138  }
139 
143  void setForceDirection(const fmatvec::Vec3 &dir) { forceDir=dir/nrm2(dir); }
144 
145  void plot(double t, double dt=1);
146  void initializeUsingXML(xercesc::DOMElement *element);
147 
148 #ifdef HAVE_OPENMBVCPPINTERFACE
149  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVCoilSpring, tag, (optional (numberOfCoils,(int),3)(springRadius,(double),1)(crossSectionRadius,(double),-1)(nominalLength,(double),-1)(type,(OpenMBV::CoilSpring::Type),OpenMBV::CoilSpring::tube)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
150  OpenMBVCoilSpring ombv(springRadius,crossSectionRadius,1,numberOfCoils,nominalLength,type,diffuseColor,transparency);
151  coilspringOpenMBV=ombv.createOpenMBV();
152  }
153 
155  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVForce, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
156  OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
157  std::vector<bool> which; which.resize(2, true);
158  LinkMechanics::setOpenMBVForceArrow(ombv.createOpenMBV(), which);
159  }
160 #endif
161  private:
162  std::string saved_ref1, saved_ref2;
163  };
164 
166  protected:
167  Function<double(double,double)> *func;
168  std::vector<RigidBody*> body;
169 #ifdef HAVE_OPENMBVCPPINTERFACE
170  boost::shared_ptr<OpenMBV::CoilSpring> coilspringOpenMBV;
171 #endif
172  public:
173  GeneralizedSpringDamper(const std::string &name="");
175  void updateh(double, int i=0);
176  void updateg(double);
177  void updategd(double);
178 
179  bool isActive() const { return true; }
180  bool gActiveChanged() { return false; }
181  virtual bool isSingleValued() const { return true; }
182  std::string getType() const { return "GeneralizedSpringDamper"; }
183  void init(InitStage stage);
184 
186  void setGeneralizedForceFunction(Function<double(double,double)> *func_) {
187  func=func_;
188  func->setParent(this);
189  func->setName("GeneralizedFoce");
190  }
191 
192  void setRigidBodyFirstSide(RigidBody* body_) { body[0] = body_; }
193  void setRigidBodySecondSide(RigidBody* body_) { body[1] = body_; }
194 
195  void plot(double t, double dt=1);
196  void initializeUsingXML(xercesc::DOMElement *element);
197 
198  void updatehRef(const fmatvec::Vec &hParent, int j=0);
199 
200 #ifdef HAVE_OPENMBVCPPINTERFACE
201  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVCoilSpring, tag, (optional (numberOfCoils,(int),3)(springRadius,(double),1)(crossSectionRadius,(double),-1)(nominalLength,(double),-1)(type,(OpenMBV::CoilSpring::Type),OpenMBV::CoilSpring::tube)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
202  OpenMBVCoilSpring ombv(springRadius,crossSectionRadius,1,numberOfCoils,nominalLength,type,diffuseColor,transparency);
203  coilspringOpenMBV=ombv.createOpenMBV();
204  }
205 
207  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVForce, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
208  OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
209  std::vector<bool> which; which.resize(2, true);
210  LinkMechanics::setOpenMBVForceArrow(ombv.createOpenMBV(), which);
211  }
212 
214  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVMoment, tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) {
215  OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toDoubleHead,referencePoint,scaleLength,scaleSize);
216  std::vector<bool> which; which.resize(2, true);
217  LinkMechanics::setOpenMBVMomentArrow(ombv.createOpenMBV(), which);
218  }
219 #endif
220  private:
221  std::string saved_body1, saved_body2;
222  };
223 
224 }
225 
226 #endif /* _SPRINGDAMPER_H_ */
227 
std::string getType() const
Definition: spring_damper.h:125
bool gActiveChanged()
Definition: spring_damper.h:123
void init(InitStage stage)
plots time series header
Definition: spring_damper.cc:360
bool gActiveChanged()
Definition: spring_damper.h:59
void setGeneralizedForceFunction(Function< double(double, double)> *func_)
Set the function for the generalized force.
Definition: spring_damper.h:186
void connect(Frame *frame1, Frame *frame2)
Connect the SpringDamper to frame1 and frame2.
Definition: spring_damper.cc:203
std::string getType() const
Definition: spring_damper.h:182
A spring damper force law. This class connects two frames and applies a force in it, which depends in the distance and relative velocity between the two frames.
Definition: spring_damper.h:101
void setForceDirection(const fmatvec::Vec3 &dir)
Definition: spring_damper.h:143
void init(InitStage stage)
plots time series header
Definition: spring_damper.cc:208
void plot(double t, double dt=1)
plots time dependent data
Definition: spring_damper.cc:249
Definition: spring_damper.h:165
void setForceFunction(Function< double(double, double)> *func_)
Set function for the force calculation. The first input parameter to that function is the distance g ...
Definition: spring_damper.h:134
virtual bool isSingleValued() const
asks the link if it contains single valued force laws that contribute to the right-hand side vector h...
Definition: spring_damper.h:181
void plot(double t, double dt=1)
plots time dependent data
Definition: spring_damper.cc:112
void setForceFunction(Function< double(double, double)> *func_)
Set function for the force calculation. The first input parameter to that function is the distance g ...
Definition: spring_damper.h:70
bool isActive() const
Definition: spring_damper.h:179
bool isActive() const
Definition: spring_damper.h:122
void updatehRef(const fmatvec::Vec &hParent, int j=0)
references to complete and link smooth force vector of dynamic system parent
Definition: spring_damper.cc:317
void plot(double t, double dt=1)
plots time dependent data
Definition: spring_damper.cc:403
InitStage
The stages of the initialization.
Definition: element.h:97
bool isSingleValued() const
asks the link if it contains single valued force laws that contribute to the right-hand side vector h...
Definition: spring_damper.h:124
void connect(Frame *frame1, Frame *frame2)
Connect the SpringDamper to frame1 and frame2.
Definition: spring_damper.cc:74
std::string name
name of element
Definition: element.h:290
bool isActive() const
Definition: spring_damper.h:58
cartesian frame on bodies used for application of e.g. links and loads
Definition: frame.h:39
std::string getType() const
Definition: spring_damper.h:61
general link to one or more objects
Definition: link_mechanics.h:48
bool isSingleValued() const
asks the link if it contains single valued force laws that contribute to the right-hand side vector h...
Definition: spring_damper.h:60
void init(InitStage stage)
plots time series header
Definition: spring_damper.cc:79
bool gActiveChanged()
Definition: spring_damper.h:180
A spring damper force law. This class connects two frames and applies a force in it, which depends in the distance and relative velocity between the two frames.
Definition: spring_damper.h:39
rigid bodies with arbitrary kinematics
Definition: rigid_body.h:53

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML