btSliderConstraint.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose,
00008 including commercial applications, and to alter it and redistribute it freely,
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 /*
00017 Added by Roman Ponomarev (rponom@gmail.com)
00018 April 04, 2008
00019 
00020 TODO:
00021  - add clamping od accumulated impulse to improve stability
00022  - add conversion for ODE constraint solver
00023 */
00024 
00025 #ifndef BT_SLIDER_CONSTRAINT_H
00026 #define BT_SLIDER_CONSTRAINT_H
00027 
00028 
00029 
00030 #include "LinearMath/btVector3.h"
00031 #include "btJacobianEntry.h"
00032 #include "btTypedConstraint.h"
00033 
00034 
00035 
00036 class btRigidBody;
00037 
00038 
00039 
00040 #define SLIDER_CONSTRAINT_DEF_SOFTNESS          (btScalar(1.0))
00041 #define SLIDER_CONSTRAINT_DEF_DAMPING           (btScalar(1.0))
00042 #define SLIDER_CONSTRAINT_DEF_RESTITUTION       (btScalar(0.7))
00043 #define SLIDER_CONSTRAINT_DEF_CFM                       (btScalar(0.f))
00044 
00045 
00046 enum btSliderFlags
00047 {
00048         BT_SLIDER_FLAGS_CFM_DIRLIN = (1 << 0),
00049         BT_SLIDER_FLAGS_ERP_DIRLIN = (1 << 1),
00050         BT_SLIDER_FLAGS_CFM_DIRANG = (1 << 2),
00051         BT_SLIDER_FLAGS_ERP_DIRANG = (1 << 3),
00052         BT_SLIDER_FLAGS_CFM_ORTLIN = (1 << 4),
00053         BT_SLIDER_FLAGS_ERP_ORTLIN = (1 << 5),
00054         BT_SLIDER_FLAGS_CFM_ORTANG = (1 << 6),
00055         BT_SLIDER_FLAGS_ERP_ORTANG = (1 << 7),
00056         BT_SLIDER_FLAGS_CFM_LIMLIN = (1 << 8),
00057         BT_SLIDER_FLAGS_ERP_LIMLIN = (1 << 9),
00058         BT_SLIDER_FLAGS_CFM_LIMANG = (1 << 10),
00059         BT_SLIDER_FLAGS_ERP_LIMANG = (1 << 11)
00060 };
00061 
00062 
00063 class btSliderConstraint : public btTypedConstraint
00064 {
00065 protected:
00067         bool            m_useSolveConstraintObsolete;
00068         bool            m_useOffsetForConstraintFrame;
00069         btTransform     m_frameInA;
00070     btTransform m_frameInB;
00071         // use frameA fo define limits, if true
00072         bool m_useLinearReferenceFrameA;
00073         // linear limits
00074         btScalar m_lowerLinLimit;
00075         btScalar m_upperLinLimit;
00076         // angular limits
00077         btScalar m_lowerAngLimit;
00078         btScalar m_upperAngLimit;
00079         // softness, restitution and damping for different cases
00080         // DirLin - moving inside linear limits
00081         // LimLin - hitting linear limit
00082         // DirAng - moving inside angular limits
00083         // LimAng - hitting angular limit
00084         // OrthoLin, OrthoAng - against constraint axis
00085         btScalar m_softnessDirLin;
00086         btScalar m_restitutionDirLin;
00087         btScalar m_dampingDirLin;
00088         btScalar m_cfmDirLin;
00089 
00090         btScalar m_softnessDirAng;
00091         btScalar m_restitutionDirAng;
00092         btScalar m_dampingDirAng;
00093         btScalar m_cfmDirAng;
00094 
00095         btScalar m_softnessLimLin;
00096         btScalar m_restitutionLimLin;
00097         btScalar m_dampingLimLin;
00098         btScalar m_cfmLimLin;
00099 
00100         btScalar m_softnessLimAng;
00101         btScalar m_restitutionLimAng;
00102         btScalar m_dampingLimAng;
00103         btScalar m_cfmLimAng;
00104 
00105         btScalar m_softnessOrthoLin;
00106         btScalar m_restitutionOrthoLin;
00107         btScalar m_dampingOrthoLin;
00108         btScalar m_cfmOrthoLin;
00109 
00110         btScalar m_softnessOrthoAng;
00111         btScalar m_restitutionOrthoAng;
00112         btScalar m_dampingOrthoAng;
00113         btScalar m_cfmOrthoAng;
00114         
00115         // for interlal use
00116         bool m_solveLinLim;
00117         bool m_solveAngLim;
00118 
00119         int m_flags;
00120 
00121         btJacobianEntry m_jacLin[3];
00122         btScalar                m_jacLinDiagABInv[3];
00123 
00124     btJacobianEntry     m_jacAng[3];
00125 
00126         btScalar m_timeStep;
00127     btTransform m_calculatedTransformA;
00128     btTransform m_calculatedTransformB;
00129 
00130         btVector3 m_sliderAxis;
00131         btVector3 m_realPivotAInW;
00132         btVector3 m_realPivotBInW;
00133         btVector3 m_projPivotInW;
00134         btVector3 m_delta;
00135         btVector3 m_depth;
00136         btVector3 m_relPosA;
00137         btVector3 m_relPosB;
00138 
00139         btScalar m_linPos;
00140         btScalar m_angPos;
00141 
00142         btScalar m_angDepth;
00143         btScalar m_kAngle;
00144 
00145         bool     m_poweredLinMotor;
00146     btScalar m_targetLinMotorVelocity;
00147     btScalar m_maxLinMotorForce;
00148     btScalar m_accumulatedLinMotorImpulse;
00149         
00150         bool     m_poweredAngMotor;
00151     btScalar m_targetAngMotorVelocity;
00152     btScalar m_maxAngMotorForce;
00153     btScalar m_accumulatedAngMotorImpulse;
00154 
00155         //------------------------    
00156         void initParams();
00157 public:
00158         // constructors
00159     btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
00160     btSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA);
00161 
00162         // overrides
00163 
00164     virtual void getInfo1 (btConstraintInfo1* info);
00165 
00166         void getInfo1NonVirtual(btConstraintInfo1* info);
00167         
00168         virtual void getInfo2 (btConstraintInfo2* info);
00169 
00170         void getInfo2NonVirtual(btConstraintInfo2* info, const btTransform& transA, const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB, btScalar rbAinvMass,btScalar rbBinvMass);
00171 
00172 
00173         // access
00174     const btRigidBody& getRigidBodyA() const { return m_rbA; }
00175     const btRigidBody& getRigidBodyB() const { return m_rbB; }
00176     const btTransform & getCalculatedTransformA() const { return m_calculatedTransformA; }
00177     const btTransform & getCalculatedTransformB() const { return m_calculatedTransformB; }
00178     const btTransform & getFrameOffsetA() const { return m_frameInA; }
00179     const btTransform & getFrameOffsetB() const { return m_frameInB; }
00180     btTransform & getFrameOffsetA() { return m_frameInA; }
00181     btTransform & getFrameOffsetB() { return m_frameInB; }
00182     btScalar getLowerLinLimit() { return m_lowerLinLimit; }
00183     void setLowerLinLimit(btScalar lowerLimit) { m_lowerLinLimit = lowerLimit; }
00184     btScalar getUpperLinLimit() { return m_upperLinLimit; }
00185     void setUpperLinLimit(btScalar upperLimit) { m_upperLinLimit = upperLimit; }
00186     btScalar getLowerAngLimit() { return m_lowerAngLimit; }
00187     void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = btNormalizeAngle(lowerLimit); }
00188     btScalar getUpperAngLimit() { return m_upperAngLimit; }
00189     void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = btNormalizeAngle(upperLimit); }
00190         bool getUseLinearReferenceFrameA() { return m_useLinearReferenceFrameA; }
00191         btScalar getSoftnessDirLin() { return m_softnessDirLin; }
00192         btScalar getRestitutionDirLin() { return m_restitutionDirLin; }
00193         btScalar getDampingDirLin() { return m_dampingDirLin ; }
00194         btScalar getSoftnessDirAng() { return m_softnessDirAng; }
00195         btScalar getRestitutionDirAng() { return m_restitutionDirAng; }
00196         btScalar getDampingDirAng() { return m_dampingDirAng; }
00197         btScalar getSoftnessLimLin() { return m_softnessLimLin; }
00198         btScalar getRestitutionLimLin() { return m_restitutionLimLin; }
00199         btScalar getDampingLimLin() { return m_dampingLimLin; }
00200         btScalar getSoftnessLimAng() { return m_softnessLimAng; }
00201         btScalar getRestitutionLimAng() { return m_restitutionLimAng; }
00202         btScalar getDampingLimAng() { return m_dampingLimAng; }
00203         btScalar getSoftnessOrthoLin() { return m_softnessOrthoLin; }
00204         btScalar getRestitutionOrthoLin() { return m_restitutionOrthoLin; }
00205         btScalar getDampingOrthoLin() { return m_dampingOrthoLin; }
00206         btScalar getSoftnessOrthoAng() { return m_softnessOrthoAng; }
00207         btScalar getRestitutionOrthoAng() { return m_restitutionOrthoAng; }
00208         btScalar getDampingOrthoAng() { return m_dampingOrthoAng; }
00209         void setSoftnessDirLin(btScalar softnessDirLin) { m_softnessDirLin = softnessDirLin; }
00210         void setRestitutionDirLin(btScalar restitutionDirLin) { m_restitutionDirLin = restitutionDirLin; }
00211         void setDampingDirLin(btScalar dampingDirLin) { m_dampingDirLin = dampingDirLin; }
00212         void setSoftnessDirAng(btScalar softnessDirAng) { m_softnessDirAng = softnessDirAng; }
00213         void setRestitutionDirAng(btScalar restitutionDirAng) { m_restitutionDirAng = restitutionDirAng; }
00214         void setDampingDirAng(btScalar dampingDirAng) { m_dampingDirAng = dampingDirAng; }
00215         void setSoftnessLimLin(btScalar softnessLimLin) { m_softnessLimLin = softnessLimLin; }
00216         void setRestitutionLimLin(btScalar restitutionLimLin) { m_restitutionLimLin = restitutionLimLin; }
00217         void setDampingLimLin(btScalar dampingLimLin) { m_dampingLimLin = dampingLimLin; }
00218         void setSoftnessLimAng(btScalar softnessLimAng) { m_softnessLimAng = softnessLimAng; }
00219         void setRestitutionLimAng(btScalar restitutionLimAng) { m_restitutionLimAng = restitutionLimAng; }
00220         void setDampingLimAng(btScalar dampingLimAng) { m_dampingLimAng = dampingLimAng; }
00221         void setSoftnessOrthoLin(btScalar softnessOrthoLin) { m_softnessOrthoLin = softnessOrthoLin; }
00222         void setRestitutionOrthoLin(btScalar restitutionOrthoLin) { m_restitutionOrthoLin = restitutionOrthoLin; }
00223         void setDampingOrthoLin(btScalar dampingOrthoLin) { m_dampingOrthoLin = dampingOrthoLin; }
00224         void setSoftnessOrthoAng(btScalar softnessOrthoAng) { m_softnessOrthoAng = softnessOrthoAng; }
00225         void setRestitutionOrthoAng(btScalar restitutionOrthoAng) { m_restitutionOrthoAng = restitutionOrthoAng; }
00226         void setDampingOrthoAng(btScalar dampingOrthoAng) { m_dampingOrthoAng = dampingOrthoAng; }
00227         void setPoweredLinMotor(bool onOff) { m_poweredLinMotor = onOff; }
00228         bool getPoweredLinMotor() { return m_poweredLinMotor; }
00229         void setTargetLinMotorVelocity(btScalar targetLinMotorVelocity) { m_targetLinMotorVelocity = targetLinMotorVelocity; }
00230         btScalar getTargetLinMotorVelocity() { return m_targetLinMotorVelocity; }
00231         void setMaxLinMotorForce(btScalar maxLinMotorForce) { m_maxLinMotorForce = maxLinMotorForce; }
00232         btScalar getMaxLinMotorForce() { return m_maxLinMotorForce; }
00233         void setPoweredAngMotor(bool onOff) { m_poweredAngMotor = onOff; }
00234         bool getPoweredAngMotor() { return m_poweredAngMotor; }
00235         void setTargetAngMotorVelocity(btScalar targetAngMotorVelocity) { m_targetAngMotorVelocity = targetAngMotorVelocity; }
00236         btScalar getTargetAngMotorVelocity() { return m_targetAngMotorVelocity; }
00237         void setMaxAngMotorForce(btScalar maxAngMotorForce) { m_maxAngMotorForce = maxAngMotorForce; }
00238         btScalar getMaxAngMotorForce() { return m_maxAngMotorForce; }
00239 
00240         btScalar getLinearPos() const { return m_linPos; }
00241         btScalar getAngularPos() const { return m_angPos; }
00242         
00243         
00244 
00245         // access for ODE solver
00246         bool getSolveLinLimit() { return m_solveLinLim; }
00247         btScalar getLinDepth() { return m_depth[0]; }
00248         bool getSolveAngLimit() { return m_solveAngLim; }
00249         btScalar getAngDepth() { return m_angDepth; }
00250         // shared code used by ODE solver
00251         void    calculateTransforms(const btTransform& transA,const btTransform& transB);
00252         void    testLinLimits();
00253         void    testAngLimits();
00254         // access for PE Solver
00255         btVector3 getAncorInA();
00256         btVector3 getAncorInB();
00257         // access for UseFrameOffset
00258         bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; }
00259         void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; }
00260 
00261         void setFrames(const btTransform& frameA, const btTransform& frameB) 
00262         { 
00263                 m_frameInA=frameA; 
00264                 m_frameInB=frameB;
00265                 calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform());
00266                 buildJacobian();
00267         } 
00268 
00269 
00272         virtual void    setParam(int num, btScalar value, int axis = -1);
00274         virtual btScalar getParam(int num, int axis = -1) const;
00275 
00276         virtual int     calculateSerializeBufferSize() const;
00277 
00279         virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
00280 
00281 
00282 };
00283 
00285 struct btSliderConstraintData
00286 {
00287         btTypedConstraintData   m_typeConstraintData;
00288         btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
00289         btTransformFloatData m_rbBFrame;
00290         
00291         float   m_linearUpperLimit;
00292         float   m_linearLowerLimit;
00293 
00294         float   m_angularUpperLimit;
00295         float   m_angularLowerLimit;
00296 
00297         int     m_useLinearReferenceFrameA;
00298         int m_useOffsetForConstraintFrame;
00299 
00300 };
00301 
00302 
00303 SIMD_FORCE_INLINE               int     btSliderConstraint::calculateSerializeBufferSize() const
00304 {
00305         return sizeof(btSliderConstraintData);
00306 }
00307 
00309 SIMD_FORCE_INLINE       const char*     btSliderConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
00310 {
00311 
00312         btSliderConstraintData* sliderData = (btSliderConstraintData*) dataBuffer;
00313         btTypedConstraint::serialize(&sliderData->m_typeConstraintData,serializer);
00314 
00315         m_frameInA.serializeFloat(sliderData->m_rbAFrame);
00316         m_frameInB.serializeFloat(sliderData->m_rbBFrame);
00317 
00318         sliderData->m_linearUpperLimit = float(m_upperLinLimit);
00319         sliderData->m_linearLowerLimit = float(m_lowerLinLimit);
00320 
00321         sliderData->m_angularUpperLimit = float(m_upperAngLimit);
00322         sliderData->m_angularLowerLimit = float(m_lowerAngLimit);
00323 
00324         sliderData->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA;
00325         sliderData->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame;
00326 
00327         return "btSliderConstraintData";
00328 }
00329 
00330 
00331 
00332 #endif //BT_SLIDER_CONSTRAINT_H
00333 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


bullet
Author(s): Erwin Coumans, ROS package maintained by Tully Foote
autogenerated on Wed Oct 31 2012 07:54:31