00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _GEAR_H_
00021 #define _GEAR_H_
00022
00023 #include "mbsim/link_mechanics.h"
00024 #include "mbsim/rigid_body.h"
00025
00026 #ifdef HAVE_OPENMBVCPPINTERFACE
00027 #include "mbsim/utils/boost_parameters.h"
00028 #include "mbsim/utils/openmbv_utils.h"
00029 #endif
00030
00031 namespace MBSim {
00032
00033 class Transmission;
00034
00035 class Gear : public LinkMechanics {
00036 protected:
00037 Function<double(double,double)> *func;
00038 std::vector<RigidBody*> body;
00039 std::vector<double> ratio;
00040 std::vector<Frame> C;
00041 std::string saved_DependentBody;
00042 std::vector<std::string> saved_IndependentBody;
00043 public:
00044 Gear(const std::string &name="");
00045 void updateh(double, int i=0);
00046 void updateW(double, int i=0);
00047 void updateg(double);
00048 void updategd(double);
00049 void updateJacobians(double t, int j=0);
00050 void updatewb(double t, int i=0);
00051 void updatehRef(const fmatvec::Vec &hParent, int j=0);
00052 void updateWRef(const fmatvec::Mat &WParent, int j=0);
00053 void setDependentBody(RigidBody* body_) {body[0] = body_;}
00054 void addTransmission(const Transmission &transmission);
00055
00056 bool isActive() const { return true; }
00057 bool gActiveChanged() { return false; }
00058 std::string getType() const { return "Gear"; }
00059 void init(InitStage stage);
00060 bool isSetValued() const;
00061 bool isSingleValued() const { return not(isSetValued()); }
00062 virtual void calclaSize(int j);
00063 virtual void calcgSize(int j);
00064 virtual void calcgdSize(int j);
00065
00066 void setGeneralizedForceFunction(Function<double(double,double)> *func_) {
00067 func=func_;
00068 func->setParent(this);
00069 func->setName("GeneralizedForce");
00070 }
00071
00072 void plot(double t, double dt=1);
00073
00074 void initializeUsingXML(xercesc::DOMElement * element);
00075
00076 #ifdef HAVE_OPENMBVCPPINTERFACE
00077
00078 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))) {
00079 OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00080 setOpenMBVForce(ombv.createOpenMBV());
00081 }
00082 void setOpenMBVForce(const boost::shared_ptr<OpenMBV::Arrow> &arrow) { FArrow[0]=arrow; }
00083
00085 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))) {
00086 OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00087 setOpenMBVMoment(ombv.createOpenMBV());
00088 }
00089 void setOpenMBVMoment(const boost::shared_ptr<OpenMBV::Arrow> &arrow) { MArrow[0]=arrow; }
00090 #endif
00091
00092 protected:
00093 #ifdef HAVE_OPENMBVCPPINTERFACE
00094 std::vector<boost::shared_ptr<OpenMBV::Arrow> > FArrow, MArrow;
00095 #endif
00096
00097 };
00098
00099 }
00100
00101 #endif