MBSim

Project Page
gear.h
00001 /* Copyright (C) 2004-2011 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: martin.o.foerg@gmail.com
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       fmatvec::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(fmatvec::Function<double(double,double)> *func_) { func=func_; }
00067 
00068       void plot(double t, double dt=1);
00069 
00070       void initializeUsingXML(xercesc::DOMElement * element);
00071 
00072 #ifdef HAVE_OPENMBVCPPINTERFACE
00073 
00074       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))) { 
00075         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00076         setOpenMBVForce(ombv.createOpenMBV());
00077       }
00078       void setOpenMBVForce(OpenMBV::Arrow *arrow) { FArrow[0]=arrow; }
00079 
00081       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))) { 
00082         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00083         setOpenMBVMoment(ombv.createOpenMBV());
00084       }
00085       void setOpenMBVMoment(OpenMBV::Arrow *arrow) { MArrow[0]=arrow; }
00086 #endif
00087 
00088     protected:
00089 #ifdef HAVE_OPENMBVCPPINTERFACE
00090       std::vector<OpenMBV::Arrow*> FArrow, MArrow;
00091 #endif
00092 
00093   };
00094 
00095 }
00096 
00097 #endif