MBSim

Project Page
friction.h
00001 /* Copyright (C) 2004-2009 MBSim Development Team
00002  * This library is free software; you can redistribute it and/or 
00003  * modify it under the terms of the GNU Lesser General Public 
00004  * License as published by the Free Software Foundation; either 
00005  * version 2.1 of the License, or (at your option) any later version. 
00006  *  
00007  * This library is distributed in the hope that it will be useful, 
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00010  * Lesser General Public License for more details. 
00011  *  
00012  * You should have received a copy of the GNU Lesser General Public 
00013  * License along with this library; if not, write to the Free Software 
00014  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00015  *
00016  * Contact: martin.o.foerg@googlemail.com
00017  */
00018 
00019 #ifndef _FRICTION_H_
00020 #define _FRICTION_H_
00021 
00022 #include "mbsim/link_mechanics.h"
00023 #include <mbsim/frame.h>
00024 #include "fmatvec/function.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 RigidBody;
00034   class FrictionForceLaw;
00035 
00036   class GeneralizedFriction : public LinkMechanics {
00037     protected:
00038       //fmatvec::Function<double(double,double)> *func;
00039       FrictionForceLaw *func;
00040       double laN;
00041       std::vector<RigidBody*> body;
00042     public:
00043       GeneralizedFriction(const std::string &name="");
00044       ~GeneralizedFriction();
00045       void updateh(double, int i=0);
00046       void updateg(double) { }
00047       void updategd(double);
00048 
00049       bool isActive() const { return true; }
00050       bool gActiveChanged() { return false; }
00051       virtual bool isSingleValued() const { return true; }
00052       std::string getType() const { return "GeneralizedFriction"; }
00053       void init(InitStage stage);
00054 
00056       //void setGeneralizedForceFunction(fmatvec::Function<double(double,double)> *func_) { func=func_; }
00057       void setGeneralizedFrictionForceLaw(FrictionForceLaw *func_) { func = func_; }
00058       void setGeneralizedNormalForce(double laN_) { laN = laN_; }
00059 
00060       void setRigidBodyFirstSide(RigidBody* body_) { body[0] = body_; }
00061       void setRigidBodySecondSide(RigidBody* body_) { body[1] = body_; }
00062 
00063       void plot(double t, double dt=1);
00064       void initializeUsingXML(xercesc::DOMElement *element);
00065 
00066       void updatehRef(const fmatvec::Vec &hParent, int j=0);
00067 
00068 #ifdef HAVE_OPENMBVCPPINTERFACE
00069 
00070       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))) { 
00071         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00072         std::vector<bool> which; which.resize(2, true);
00073         LinkMechanics::setOpenMBVForceArrow(ombv.createOpenMBV(), which);
00074       }
00075 
00077       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))) { 
00078         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toDoubleHead,referencePoint,scaleLength,scaleSize);
00079         std::vector<bool> which; which.resize(2, true);
00080         LinkMechanics::setOpenMBVMomentArrow(ombv.createOpenMBV(), which);
00081       }
00082 #endif
00083     private:
00084       std::string saved_body1, saved_body2;
00085   };
00086 
00087 }
00088 
00089 #endif 
00090