Bullet Collision Detection & Physics Library
btMultiBodyConstraint.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_MULTIBODY_CONSTRAINT_H
17 #define BT_MULTIBODY_CONSTRAINT_H
18 
19 #include "LinearMath/btScalar.h"
21 #include "btMultiBody.h"
22 
23 
24 //Don't change any of the existing enum values, so add enum types at the end for serialization compatibility
26 {
34 
36 };
37 
38 class btMultiBody;
39 struct btSolverInfo;
40 
42 
44 {
46  btAlignedObjectArray<btScalar> m_deltaVelocitiesUnitImpulse; //holds the joint-space response of the corresp. tree to the test impulse in each constraint space dimension
47  btAlignedObjectArray<btScalar> m_deltaVelocities; //holds joint-space vectors of all the constrained trees accumulating the effect of corrective impulses applied in SI
53 };
54 
57 {
58 protected:
61  int m_linkA;
62  int m_linkB;
63 
64  int m_type; //btTypedMultiBodyConstraintType
65 
66  int m_numRows;
70 
74 
75  // warning: the data block lay out is not consistent for all constraints
76  // data block laid out as follows:
77  // cached impulses. (one per row.)
78  // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
79  // positions. (one per row.)
81 
82  void applyDeltaVee(btMultiBodyJacobianData & data, btScalar * delta_vee, btScalar impulse, int velocityIndex, int ndof);
83 
84  btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint & solverConstraint,
86  btScalar * jacOrgA, btScalar * jacOrgB,
87  const btVector3& constraintNormalAng,
88 
89  const btVector3& constraintNormalLin,
90  const btVector3& posAworld, const btVector3& posBworld,
91  btScalar posError,
92  const btContactSolverInfo& infoGlobal,
93  btScalar lowerLimit, btScalar upperLimit,
94  bool angConstraint = false,
95 
96  btScalar relaxation = 1.f,
97  bool isFriction = false, btScalar desiredVelocity = 0, btScalar cfmSlip = 0, btScalar damping = 1.0);
98 
99 public:
101 
102  btMultiBodyConstraint(btMultiBody * bodyA, btMultiBody * bodyB, int linkA, int linkB, int numRows, bool isUnilateral, int type);
103  virtual ~btMultiBodyConstraint();
104 
105  void updateJacobianSizes();
106  void allocateJacobiansMultiDof();
107 
108  int getConstraintType() const
109  {
110  return m_type;
111  }
112  //many constraints have setFrameInB/setPivotInB. Will use 'getConstraintType' later.
113  virtual void setFrameInB(const btMatrix3x3& frameInB) {}
114  virtual void setPivotInB(const btVector3& pivotInB) {}
115 
116  virtual void finalizeMultiDof() = 0;
117 
118  virtual int getIslandIdA() const = 0;
119  virtual int getIslandIdB() const = 0;
120 
121  virtual void createConstraintRows(btMultiBodyConstraintArray & constraintRows,
123  const btContactSolverInfo& infoGlobal) = 0;
124 
125  int getNumRows() const
126  {
127  return m_numRows;
128  }
129 
131  {
132  return m_bodyA;
133  }
135  {
136  return m_bodyB;
137  }
138 
139  int getLinkA() const
140  {
141  return m_linkA;
142  }
143  int getLinkB() const
144  {
145  return m_linkB;
146  }
147  void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
148  {
149  btAssert(dof >= 0);
150  btAssert(dof < getNumRows());
151  m_data[dof] = appliedImpulse;
152  }
153 
155  {
156  btAssert(dof >= 0);
157  btAssert(dof < getNumRows());
158  return m_data[dof];
159  }
160  // current constraint position
161  // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
162  // NOTE: ignored position for friction rows.
163  btScalar getPosition(int row) const
164  {
165  return m_data[m_posOffset + row];
166  }
167 
168  void setPosition(int row, btScalar pos)
169  {
170  m_data[m_posOffset + row] = pos;
171  }
172 
173  bool isUnilateral() const
174  {
175  return m_isUnilateral;
176  }
177 
178  // jacobian blocks.
179  // each of size 6 + num_links. (jacobian2 is null if no body2.)
180  // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
181  btScalar* jacobianA(int row)
182  {
183  return &m_data[m_numRows + row * m_jacSizeBoth];
184  }
185  const btScalar* jacobianA(int row) const
186  {
187  return &m_data[m_numRows + (row * m_jacSizeBoth)];
188  }
189  btScalar* jacobianB(int row)
190  {
191  return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
192  }
193  const btScalar* jacobianB(int row) const
194  {
195  return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
196  }
197 
199  {
200  return m_maxAppliedImpulse;
201  }
203  {
204  m_maxAppliedImpulse = maxImp;
205  }
206 
207  virtual void debugDraw(class btIDebugDraw * drawer) = 0;
208 
209  virtual void setGearRatio(btScalar ratio) {}
210  virtual void setGearAuxLink(int gearAuxLink) {}
211  virtual void setRelativePositionTarget(btScalar relPosTarget) {}
212  virtual void setErp(btScalar erp) {}
213 };
214 
215 #endif //BT_MULTIBODY_CONSTRAINT_H
btTypedMultiBodyConstraintType
@ MAX_MULTIBODY_CONSTRAINT_TYPE
@ MULTIBODY_CONSTRAINT_LIMIT
@ MULTIBODY_CONSTRAINT_SLIDER
@ MULTIBODY_CONSTRAINT_FIXED
@ MULTIBODY_CONSTRAINT_POINT_TO_POINT
@ MULTIBODY_CONSTRAINT_GEAR
@ MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR
@ MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
#define btAssert(x)
Definition: btScalar.h:153
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
virtual void setGearRatio(btScalar ratio)
virtual void setRelativePositionTarget(btScalar relPosTarget)
btScalar getPosition(int row) const
virtual int getIslandIdA() const =0
btAlignedObjectArray< btScalar > m_data
void setPosition(int row, btScalar pos)
virtual void debugDraw(class btIDebugDraw *drawer)=0
const btScalar * jacobianA(int row) const
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)=0
const btScalar * jacobianB(int row) const
virtual void setPivotInB(const btVector3 &pivotInB)
btScalar * jacobianA(int row)
void setMaxAppliedImpulse(btScalar maxImp)
btScalar getAppliedImpulse(int dof)
btScalar * jacobianB(int row)
virtual int getIslandIdB() const =0
virtual void setErp(btScalar erp)
btScalar getMaxAppliedImpulse() const
void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
virtual void setGearAuxLink(int gearAuxLink)
virtual void setFrameInB(const btMatrix3x3 &frameInB)
virtual void finalizeMultiDof()=0
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
btAlignedObjectArray< btScalar > m_deltaVelocities
btAlignedObjectArray< btScalar > m_jacobians
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
btAlignedObjectArray< btScalar > scratch_r
btAlignedObjectArray< btMatrix3x3 > scratch_m
btAlignedObjectArray< btVector3 > scratch_v
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...