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
24 //Don't change any of the existing enum values, so add enum types at the end for serialization compatibility
25 enum btTypedMultiBodyConstraintType
26 {
27 MULTIBODY_CONSTRAINT_LIMIT=3,
28 MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR,
29 MULTIBODY_CONSTRAINT_GEAR,
30 MULTIBODY_CONSTRAINT_POINT_TO_POINT,
31 MULTIBODY_CONSTRAINT_SLIDER,
32 MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR,
33 MULTIBODY_CONSTRAINT_FIXED,
34
35 MAX_MULTIBODY_CONSTRAINT_TYPE,
36 };
37
38 class btMultiBody;
39 struct btSolverInfo;
40
41 #include "btMultiBodySolverConstraint.h"
42
43 struct btMultiBodyJacobianData
44 {
45 btAlignedObjectArray<btScalar> m_jacobians;
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
48 btAlignedObjectArray<btScalar> scratch_r;
49 btAlignedObjectArray<btVector3> scratch_v;
50 btAlignedObjectArray<btMatrix3x3> scratch_m;
51 btAlignedObjectArray<btSolverBody>* m_solverBodyPool;
52 int m_fixedBodyId;
53 };
54
55 ATTRIBUTE_ALIGNED16(class)
56 btMultiBodyConstraint
57 {
58 protected:
59 btMultiBody* m_bodyA;
60 btMultiBody* m_bodyB;
61 int m_linkA;
62 int m_linkB;
63
64 int m_type; //btTypedMultiBodyConstraintType
65
66 int m_numRows;
67 int m_jacSizeA;
68 int m_jacSizeBoth;
69 int m_posOffset;
70
71 bool m_isUnilateral;
72 int m_numDofsFinalized;
73 btScalar m_maxAppliedImpulse;
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.)
80 btAlignedObjectArray<btScalar> m_data;
81
82 void applyDeltaVee(btMultiBodyJacobianData & data, btScalar * delta_vee, btScalar impulse, int velocityIndex, int ndof);
83
84 btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint & solverConstraint,
85 btMultiBodyJacobianData & data,
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);
98
99 public:
100 BT_DECLARE_ALIGNED_ALLOCATOR();
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,
122 btMultiBodyJacobianData & data,
123 const btContactSolverInfo& infoGlobal) = 0;
124
125 int getNumRows() const
126 {
127 return m_numRows;
128 }
129
130 btMultiBody* getMultiBodyA()
131 {
132 return m_bodyA;
133 }
134 btMultiBody* getMultiBodyB()
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
154 btScalar getAppliedImpulse(int dof)
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
198 btScalar getMaxAppliedImpulse() const
199 {
200 return m_maxAppliedImpulse;
201 }
202 void setMaxAppliedImpulse(btScalar maxImp)
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
btMultiBodyConstraint::m_type
int m_type
Definition: btMultiBodyConstraint.h:64
btMultiBodyJacobianData::scratch_v
btAlignedObjectArray< btVector3 > scratch_v
Definition: btMultiBodyConstraint.h:49
MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR
@ MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR
Definition: btMultiBodyConstraint.h:28
MULTIBODY_CONSTRAINT_LIMIT
@ MULTIBODY_CONSTRAINT_LIMIT
Definition: btMultiBodyConstraint.h:27
btMultiBodyConstraint::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btMultiBodyConstraint::getLinkB
int getLinkB() const
Definition: btMultiBodyConstraint.h:143
MULTIBODY_CONSTRAINT_FIXED
@ MULTIBODY_CONSTRAINT_FIXED
Definition: btMultiBodyConstraint.h:33
MULTIBODY_CONSTRAINT_GEAR
@ MULTIBODY_CONSTRAINT_GEAR
Definition: btMultiBodyConstraint.h:29
btContactSolverInfo
Definition: btContactSolverInfo.h:76
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:69
btMultiBodyConstraint::getMaxAppliedImpulse
btScalar getMaxAppliedImpulse() const
Definition: btMultiBodyConstraint.h:198
btMultiBodyJacobianData::m_jacobians
btAlignedObjectArray< btScalar > m_jacobians
Definition: btMultiBodyConstraint.h:45
btMultiBodyConstraint
Definition: btMultiBodyConstraint.h:57
btMultiBodyConstraint::setMaxAppliedImpulse
void setMaxAppliedImpulse(btScalar maxImp)
Definition: btMultiBodyConstraint.h:202
btMultiBodyConstraint::jacobianA
const btScalar * jacobianA(int row) const
Definition: btMultiBodyConstraint.h:185
btMultiBodyConstraint::getIslandIdB
virtual int getIslandIdB() const =0
btMultiBodyConstraint::internalSetAppliedImpulse
void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
Definition: btMultiBodyConstraint.h:147
btMultiBodyConstraint::m_linkA
int m_linkA
Definition: btMultiBodyConstraint.h:61
btMultiBodyConstraint::debugDraw
virtual void debugDraw(class btIDebugDraw *drawer)=0
btMultiBodyConstraint::getLinkA
int getLinkA() const
Definition: btMultiBodyConstraint.h:139
btMultiBodyConstraint::getNumRows
int getNumRows() const
Definition: btMultiBodyConstraint.h:125
btScalar.h
btMultiBodyConstraint::getMultiBodyB
btMultiBody * getMultiBodyB()
Definition: btMultiBodyConstraint.h:134
btMultiBodySolverConstraint.h
btMultiBodyConstraint::setPosition
void setPosition(int row, btScalar pos)
Definition: btMultiBodyConstraint.h:168
btMultiBodyConstraint::setFrameInB
virtual void setFrameInB(const btMatrix3x3 &frameInB)
Definition: btMultiBodyConstraint.h:113
btMultiBodyJacobianData
Definition: btMultiBodyConstraint.h:44
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:114
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:211
btMultiBodyConstraint::isUnilateral
bool isUnilateral() const
Definition: btMultiBodyConstraint.h:173
btMultiBodyConstraint::m_linkB
int m_linkB
Definition: btMultiBodyConstraint.h:62
btMultiBodyConstraint::m_maxAppliedImpulse
btScalar m_maxAppliedImpulse
Definition: btMultiBodyConstraint.h:73
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
btMultiBodyJacobianData::scratch_r
btAlignedObjectArray< btScalar > scratch_r
Definition: btMultiBodyConstraint.h:48
btMultiBodyConstraint::getIslandIdA
virtual int getIslandIdA() const =0
btMultiBodyConstraint::getPosition
btScalar getPosition(int row) const
Definition: btMultiBodyConstraint.h:163
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:209
btMultiBody
Definition: btMultiBody.h:51
btMultiBodyConstraint::jacobianB
const btScalar * jacobianB(int row) const
Definition: btMultiBodyConstraint.h:193
btMultiBodyConstraint::m_isUnilateral
bool m_isUnilateral
Definition: btMultiBodyConstraint.h:71
btMultiBodyConstraint::getConstraintType
int getConstraintType() const
Definition: btMultiBodyConstraint.h:108
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
MULTIBODY_CONSTRAINT_SLIDER
@ MULTIBODY_CONSTRAINT_SLIDER
Definition: btMultiBodyConstraint.h:31
btMultiBodyConstraint::m_numDofsFinalized
int m_numDofsFinalized
Definition: btMultiBodyConstraint.h:72
btAlignedObjectArray< btScalar >
btMultiBodyConstraint::jacobianA
btScalar * jacobianA(int row)
Definition: btMultiBodyConstraint.h:181
btMultiBodyConstraint::finalizeMultiDof
virtual void finalizeMultiDof()=0
btMultiBodyJacobianData::m_deltaVelocities
btAlignedObjectArray< btScalar > m_deltaVelocities
Definition: btMultiBodyConstraint.h:47
btMultiBodyConstraint::getAppliedImpulse
btScalar getAppliedImpulse(int dof)
Definition: btMultiBodyConstraint.h:154
btMultiBodyJacobianData::m_solverBodyPool
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
Definition: btMultiBodyConstraint.h:51
btMultiBody.h
btMultiBodyConstraint::m_bodyA
btMultiBody * m_bodyA
Definition: btMultiBodyConstraint.h:59
btMultiBodyConstraint::m_numRows
int m_numRows
Definition: btMultiBodyConstraint.h:66
MULTIBODY_CONSTRAINT_POINT_TO_POINT
@ MULTIBODY_CONSTRAINT_POINT_TO_POINT
Definition: btMultiBodyConstraint.h:30
btTypedMultiBodyConstraintType
btTypedMultiBodyConstraintType
Definition: btMultiBodyConstraint.h:26
btMultiBodyConstraint::m_data
btAlignedObjectArray< btScalar > m_data
Definition: btMultiBodyConstraint.h:80
btMultiBodyConstraint::setErp
virtual void setErp(btScalar erp)
Definition: btMultiBodyConstraint.h:212
btMultiBodyConstraint::getMultiBodyA
btMultiBody * getMultiBodyA()
Definition: btMultiBodyConstraint.h:130
MAX_MULTIBODY_CONSTRAINT_TYPE
@ MAX_MULTIBODY_CONSTRAINT_TYPE
Definition: btMultiBodyConstraint.h:35
btMultiBodyConstraint::m_jacSizeBoth
int m_jacSizeBoth
Definition: btMultiBodyConstraint.h:68
btAlignedObjectArray.h
btMultiBodyConstraint::jacobianB
btScalar * jacobianB(int row)
Definition: btMultiBodyConstraint.h:189
btMultiBodyConstraint::m_jacSizeA
int m_jacSizeA
Definition: btMultiBodyConstraint.h:67
btMultiBodyJacobianData::m_fixedBodyId
int m_fixedBodyId
Definition: btMultiBodyConstraint.h:52
MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR
@ MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR
Definition: btMultiBodyConstraint.h:32
btMultiBodyConstraint::m_bodyB
btMultiBody * m_bodyB
Definition: btMultiBodyConstraint.h:60
btMultiBodyJacobianData::scratch_m
btAlignedObjectArray< btMatrix3x3 > scratch_m
Definition: btMultiBodyConstraint.h:50
btMultiBodyJacobianData::m_deltaVelocitiesUnitImpulse
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
Definition: btMultiBodyConstraint.h:46
btMultiBodyConstraint::setGearAuxLink
virtual void setGearAuxLink(int gearAuxLink)
Definition: btMultiBodyConstraint.h:210