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 "mbsim/functions/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       //Function<double(double,double)> *func;
00039       FrictionForceLaw *func;
00040       Function<double(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(Function<double(double,double)> *func_) { func=func_; }
00057       void setGeneralizedFrictionForceLaw(FrictionForceLaw *func_);
00058       void setGeneralizedNormalForceFunction(Function<double(double)> *laN_) { 
00059         laN = laN_; 
00060         laN->setParent(this);
00061       }
00062 
00063       void setRigidBodyFirstSide(RigidBody* body_) { body[0] = body_; }
00064       void setRigidBodySecondSide(RigidBody* body_) { body[1] = body_; }
00065 
00066       void plot(double t, double dt=1);
00067       void initializeUsingXML(xercesc::DOMElement *element);
00068 
00069       void updatehRef(const fmatvec::Vec &hParent, int j=0);
00070 
00071 #ifdef HAVE_OPENMBVCPPINTERFACE
00072 
00073       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))) { 
00074         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00075         std::vector<bool> which; which.resize(2, true);
00076         LinkMechanics::setOpenMBVForceArrow(ombv.createOpenMBV(), which);
00077       }
00078 
00080       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))) { 
00081         OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toDoubleHead,referencePoint,scaleLength,scaleSize);
00082         std::vector<bool> which; which.resize(2, true);
00083         LinkMechanics::setOpenMBVMomentArrow(ombv.createOpenMBV(), which);
00084       }
00085 #endif
00086     private:
00087       std::string saved_body1, saved_body2;
00088   };
00089 
00090 }
00091 
00092 #endif 
00093