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