Bullet Collision Detection & Physics Library: btMultiBodyConstraint.h Source File

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"
20 #include "LinearMath/btAlignedObjectArray.h"
21 #include "btMultiBody.h"
22
23 class btMultiBody;
24 struct btSolverInfo;
25
26 #include "btMultiBodySolverConstraint.h"
27
28 struct btMultiBodyJacobianData
29 {
30 btAlignedObjectArray<btScalar> m_jacobians;
31 btAlignedObjectArray<btScalar> m_deltaVelocitiesUnitImpulse; //holds the joint-space response of the corresp. tree to the test impulse in each constraint space dimension
32 btAlignedObjectArray<btScalar> m_deltaVelocities; //holds joint-space vectors of all the constrained trees accumulating the effect of corrective impulses applied in SI
33 btAlignedObjectArray<btScalar> scratch_r;
34 btAlignedObjectArray<btVector3> scratch_v;
35 btAlignedObjectArray<btMatrix3x3> scratch_m;
36 btAlignedObjectArray<btSolverBody>* m_solverBodyPool;
37 int m_fixedBodyId;
38 };
39
40 ATTRIBUTE_ALIGNED16(class)
41 btMultiBodyConstraint
42 {
43 protected:
44 btMultiBody* m_bodyA;
45 btMultiBody* m_bodyB;
46 int m_linkA;
47 int m_linkB;
48
49 int m_numRows;
50 int m_jacSizeA;
51 int m_jacSizeBoth;
52 int m_posOffset;
53
54 bool m_isUnilateral;
55 int m_numDofsFinalized;
56 btScalar m_maxAppliedImpulse;
57
58 // warning: the data block lay out is not consistent for all constraints
59 // data block laid out as follows:
60 // cached impulses. (one per row.)
61 // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
62 // positions. (one per row.)
63 btAlignedObjectArray<btScalar> m_data;
64
65 void applyDeltaVee(btMultiBodyJacobianData & data, btScalar * delta_vee, btScalar impulse, int velocityIndex, int ndof);
66
67 btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint & solverConstraint,
68 btMultiBodyJacobianData & data,
69 btScalar * jacOrgA, btScalar * jacOrgB,
70 const btVector3& constraintNormalAng,
71
72 const btVector3& constraintNormalLin,
73 const btVector3& posAworld, const btVector3& posBworld,
74 btScalar posError,
75 const btContactSolverInfo& infoGlobal,
76 btScalar lowerLimit, btScalar upperLimit,
77 bool angConstraint = false,
78
79 btScalar relaxation = 1.f,
80 bool isFriction = false, btScalar desiredVelocity = 0, btScalar cfmSlip = 0);
81
82 public:
83 BT_DECLARE_ALIGNED_ALLOCATOR();
84
85 btMultiBodyConstraint(btMultiBody * bodyA, btMultiBody * bodyB, int linkA, int linkB, int numRows, bool isUnilateral);
86 virtual ~btMultiBodyConstraint();
87
88 void updateJacobianSizes();
89 void allocateJacobiansMultiDof();
90
91 //many constraints have setFrameInB/setPivotInB. Will use 'getConstraintType' later.
92 virtual void setFrameInB(const btMatrix3x3& frameInB) {}
93 virtual void setPivotInB(const btVector3& pivotInB) {}
94
95 virtual void finalizeMultiDof() = 0;
96
97 virtual int getIslandIdA() const = 0;
98 virtual int getIslandIdB() const = 0;
99
100 virtual void createConstraintRows(btMultiBodyConstraintArray & constraintRows,
101 btMultiBodyJacobianData & data,
102 const btContactSolverInfo& infoGlobal) = 0;
103
104 int getNumRows() const
105 {
106 return m_numRows;
107 }
108
109 btMultiBody* getMultiBodyA()
110 {
111 return m_bodyA;
112 }
113 btMultiBody* getMultiBodyB()
114 {
115 return m_bodyB;
116 }
117
118 int getLinkA() const
119 {
120 return m_linkA;
121 }
122 int getLinkB() const
123 {
124 return m_linkB;
125 }
126 void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
127 {
128 btAssert(dof >= 0);
129 btAssert(dof < getNumRows());
130 m_data[dof] = appliedImpulse;
131 }
132
133 btScalar getAppliedImpulse(int dof)
134 {
135 btAssert(dof >= 0);
136 btAssert(dof < getNumRows());
137 return m_data[dof];
138 }
139 // current constraint position
140 // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
141 // NOTE: ignored position for friction rows.
142 btScalar getPosition(int row) const
143 {
144 return m_data[m_posOffset + row];
145 }
146
147 void setPosition(int row, btScalar pos)
148 {
149 m_data[m_posOffset + row] = pos;
150 }
151
152 bool isUnilateral() const
153 {
154 return m_isUnilateral;
155 }
156
157 // jacobian blocks.
158 // each of size 6 + num_links. (jacobian2 is null if no body2.)
159 // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
160 btScalar* jacobianA(int row)
161 {
162 return &m_data[m_numRows + row * m_jacSizeBoth];
163 }
164 const btScalar* jacobianA(int row) const
165 {
166 return &m_data[m_numRows + (row * m_jacSizeBoth)];
167 }
168 btScalar* jacobianB(int row)
169 {
170 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
171 }
172 const btScalar* jacobianB(int row) const
173 {
174 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
175 }
176
177 btScalar getMaxAppliedImpulse() const
178 {
179 return m_maxAppliedImpulse;
180 }
181 void setMaxAppliedImpulse(btScalar maxImp)
182 {
183 m_maxAppliedImpulse = maxImp;
184 }
185
186 virtual void debugDraw(class btIDebugDraw * drawer) = 0;
187
188 virtual void setGearRatio(btScalar ratio) {}
189 virtual void setGearAuxLink(int gearAuxLink) {}
190 virtual void setRelativePositionTarget(btScalar relPosTarget) {}
191 virtual void setErp(btScalar erp) {}
192 };
193
194 #endif //BT_MULTIBODY_CONSTRAINT_H
btMultiBodyJacobianData::scratch_v
btAlignedObjectArray< btVector3 > scratch_v
Definition: btMultiBodyConstraint.h:34
btMultiBodyConstraint::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btMultiBodyConstraint::getLinkB
int getLinkB() const
Definition: btMultiBodyConstraint.h:122
btContactSolverInfo
Definition: btContactSolverInfo.h:73
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btMultiBodyConstraint::m_posOffset
int m_posOffset
Definition: btMultiBodyConstraint.h:52
btMultiBodyConstraint::getMaxAppliedImpulse
btScalar getMaxAppliedImpulse() const
Definition: btMultiBodyConstraint.h:177
btMultiBodyJacobianData::m_jacobians
btAlignedObjectArray< btScalar > m_jacobians
Definition: btMultiBodyConstraint.h:30
btMultiBodyConstraint
Definition: btMultiBodyConstraint.h:42
btMultiBodyConstraint::setMaxAppliedImpulse
void setMaxAppliedImpulse(btScalar maxImp)
Definition: btMultiBodyConstraint.h:181
btMultiBodyConstraint::jacobianA
const btScalar * jacobianA(int row) const
Definition: btMultiBodyConstraint.h:164
btMultiBodyConstraint::getIslandIdB
virtual int getIslandIdB() const =0
btMultiBodyConstraint::internalSetAppliedImpulse
void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
Definition: btMultiBodyConstraint.h:126
btMultiBodyConstraint::m_linkA
int m_linkA
Definition: btMultiBodyConstraint.h:46
btMultiBodyConstraint::debugDraw
virtual void debugDraw(class btIDebugDraw *drawer)=0
btMultiBodyConstraint::getLinkA
int getLinkA() const
Definition: btMultiBodyConstraint.h:118
btMultiBodyConstraint::getNumRows
int getNumRows() const
Definition: btMultiBodyConstraint.h:104
btScalar.h
btMultiBodyConstraint::getMultiBodyB
btMultiBody * getMultiBodyB()
Definition: btMultiBodyConstraint.h:113
btMultiBodySolverConstraint.h
btMultiBodyConstraint::setPosition
void setPosition(int row, btScalar pos)
Definition: btMultiBodyConstraint.h:147
btMultiBodyConstraint::setFrameInB
virtual void setFrameInB(const btMatrix3x3 &frameInB)
Definition: btMultiBodyConstraint.h:92
btMultiBodyJacobianData
Definition: btMultiBodyConstraint.h:29
btAssert
#define btAssert(x)
Definition: btScalar.h:153
btMultiBodySolverConstraint
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
Definition: btMultiBodySolverConstraint.h:30
btMultiBodyConstraint::setPivotInB
virtual void setPivotInB(const btVector3 &pivotInB)
Definition: btMultiBodyConstraint.h:93
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
btMultiBodyConstraint::setRelativePositionTarget
virtual void setRelativePositionTarget(btScalar relPosTarget)
Definition: btMultiBodyConstraint.h:190
btMultiBodyConstraint::isUnilateral
bool isUnilateral() const
Definition: btMultiBodyConstraint.h:152
btMultiBodyConstraint::m_linkB
int m_linkB
Definition: btMultiBodyConstraint.h:47
btMultiBodyConstraint::m_maxAppliedImpulse
btScalar m_maxAppliedImpulse
Definition: btMultiBodyConstraint.h:56
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:48
btMultiBodyJacobianData::scratch_r
btAlignedObjectArray< btScalar > scratch_r
Definition: btMultiBodyConstraint.h:33
btMultiBodyConstraint::getIslandIdA
virtual int getIslandIdA() const =0
btMultiBodyConstraint::getPosition
btScalar getPosition(int row) const
Definition: btMultiBodyConstraint.h:142
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btMultiBodyConstraint::createConstraintRows
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)=0
btMultiBodyConstraint::setGearRatio
virtual void setGearRatio(btScalar ratio)
Definition: btMultiBodyConstraint.h:188
btMultiBody
Definition: btMultiBody.h:51
btMultiBodyConstraint::jacobianB
const btScalar * jacobianB(int row) const
Definition: btMultiBodyConstraint.h:172
btMultiBodyConstraint::m_isUnilateral
bool m_isUnilateral
Definition: btMultiBodyConstraint.h:54
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
btMultiBodyConstraint::m_numDofsFinalized
int m_numDofsFinalized
Definition: btMultiBodyConstraint.h:55
btAlignedObjectArray< btScalar >
btMultiBodyConstraint::jacobianA
btScalar * jacobianA(int row)
Definition: btMultiBodyConstraint.h:160
btMultiBodyConstraint::finalizeMultiDof
virtual void finalizeMultiDof()=0
btMultiBodyJacobianData::m_deltaVelocities
btAlignedObjectArray< btScalar > m_deltaVelocities
Definition: btMultiBodyConstraint.h:32
btMultiBodyConstraint::getAppliedImpulse
btScalar getAppliedImpulse(int dof)
Definition: btMultiBodyConstraint.h:133
btMultiBodyJacobianData::m_solverBodyPool
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
Definition: btMultiBodyConstraint.h:36
btMultiBody.h
btMultiBodyConstraint::m_bodyA
btMultiBody * m_bodyA
Definition: btMultiBodyConstraint.h:44
btMultiBodyConstraint::m_numRows
int m_numRows
Definition: btMultiBodyConstraint.h:49
btMultiBodyConstraint::m_data
btAlignedObjectArray< btScalar > m_data
Definition: btMultiBodyConstraint.h:63
btMultiBodyConstraint::setErp
virtual void setErp(btScalar erp)
Definition: btMultiBodyConstraint.h:191
btMultiBodyConstraint::getMultiBodyA
btMultiBody * getMultiBodyA()
Definition: btMultiBodyConstraint.h:109
btMultiBodyConstraint::m_jacSizeBoth
int m_jacSizeBoth
Definition: btMultiBodyConstraint.h:51
btAlignedObjectArray.h
btMultiBodyConstraint::jacobianB
btScalar * jacobianB(int row)
Definition: btMultiBodyConstraint.h:168
btMultiBodyConstraint::m_jacSizeA
int m_jacSizeA
Definition: btMultiBodyConstraint.h:50
btMultiBodyJacobianData::m_fixedBodyId
int m_fixedBodyId
Definition: btMultiBodyConstraint.h:37
btMultiBodyConstraint::m_bodyB
btMultiBody * m_bodyB
Definition: btMultiBodyConstraint.h:45
btMultiBodyJacobianData::scratch_m
btAlignedObjectArray< btMatrix3x3 > scratch_m
Definition: btMultiBodyConstraint.h:35
btMultiBodyJacobianData::m_deltaVelocitiesUnitImpulse
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
Definition: btMultiBodyConstraint.h:31
btMultiBodyConstraint::setGearAuxLink
virtual void setGearAuxLink(int gearAuxLink)
Definition: btMultiBodyConstraint.h:189