Bullet Collision Detection & Physics Library
btMultiBodyLink.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_MULTIBODY_LINK_H
17#define BT_MULTIBODY_LINK_H
18
22
24{
27};
28
29//both defines are now permanently enabled
30#define BT_MULTIBODYLINK_INCLUDE_PLANAR_JOINTS
31#define TEST_SPATIAL_ALGEBRA_LAYER
32
33//
34// Various spatial helper functions
35//
36
37//namespace {
38
39
41
42//}
43
44//
45// Link struct
46//
47
49{
50
52
53 btScalar m_mass; // mass of link
54 btVector3 m_inertiaLocal; // inertia of link (local frame; diagonal)
55
56 int m_parent; // index of the parent link (assumed to be < index of this link), or -1 if parent is the base link.
57
58 btQuaternion m_zeroRotParentToThis; // rotates vectors in parent-frame to vectors in local-frame (when q=0). constant.
59
60 btVector3 m_dVector; // vector from the inboard joint pos to this link's COM. (local frame.) constant.
61 //this is set to zero for planar joint (see also m_eVector comment)
62
63 // m_eVector is constant, but depends on the joint type:
64 // revolute, fixed, prismatic, spherical: vector from parent's COM to the pivot point, in PARENT's frame.
65 // planar: vector from COM of parent to COM of this link, WHEN Q = 0. (local frame.)
66 // todo: fix the planar so it is consistent with the other joints
67
69
71
73 {
78 eFixed = 4,
80 };
81
82
83
84 // "axis" = spatial joint axis (Mirtich Defn 9 p104). (expressed in local frame.) constant.
85 // for prismatic: m_axesTop[0] = zero;
86 // m_axesBottom[0] = unit vector along the joint axis.
87 // for revolute: m_axesTop[0] = unit vector along the rotation axis (u);
88 // m_axesBottom[0] = u cross m_dVector (i.e. COM linear motion due to the rotation at the joint)
89 //
90 // for spherical: m_axesTop[0][1][2] (u1,u2,u3) form a 3x3 identity matrix (3 rotation axes)
91 // m_axesBottom[0][1][2] cross u1,u2,u3 (i.e. COM linear motion due to the rotation at the joint)
92 //
93 // for planar: m_axesTop[0] = unit vector along the rotation axis (u); defines the plane of motion
94 // m_axesTop[1][2] = zero
95 // m_axesBottom[0] = zero
96 // m_axesBottom[1][2] = unit vectors along the translational axes on that plane
98 void setAxisTop(int dof, const btVector3 &axis) { m_axes[dof].m_topVec = axis; }
99 void setAxisBottom(int dof, const btVector3 &axis)
100 {
101 m_axes[dof].m_bottomVec = axis;
102 }
103 void setAxisTop(int dof, const btScalar &x, const btScalar &y, const btScalar &z)
104 {
105 m_axes[dof].m_topVec.setValue(x, y, z);
106 }
107 void setAxisBottom(int dof, const btScalar &x, const btScalar &y, const btScalar &z)
108 {
109 m_axes[dof].m_bottomVec.setValue(x, y, z);
110 }
111 const btVector3 & getAxisTop(int dof) const { return m_axes[dof].m_topVec; }
112 const btVector3 & getAxisBottom(int dof) const { return m_axes[dof].m_bottomVec; }
113
115
116 btQuaternion m_cachedRotParentToThis; // rotates vectors in parent frame to vectors in local frame
117 btVector3 m_cachedRVector; // vector from COM of parent to COM of this link, in local frame.
118
119 btVector3 m_appliedForce; // In WORLD frame
120 btVector3 m_appliedTorque; // In WORLD frame
121
124
126
127 //m_jointTorque is the joint torque applied by the user using 'addJointTorque'.
128 //It gets set to zero after each internal stepSimulation call
130
133
134
135 int m_dofCount, m_posVarCount; //redundant but handy
136
138
140
141 btTransform m_cachedWorldTransform;//this cache is updated when calling btMultiBody::forwardKinematics
142
143 const char* m_linkName;//m_linkName memory needs to be managed by the developer/user!
144 const char* m_jointName;//m_jointName memory needs to be managed by the developer/user!
145 const void* m_userPtr;//m_userPtr ptr needs to be managed by the developer/user!
146
147 btScalar m_jointDamping; //todo: implement this internally. It is unused for now, it is set by a URDF loader. User can apply manual damping.
148 btScalar m_jointFriction; //todo: implement this internally. It is unused for now, it is set by a URDF loader. User can apply manual friction using a velocity motor.
149 btScalar m_jointLowerLimit; //todo: implement this internally. It is unused for now, it is set by a URDF loader.
150 btScalar m_jointUpperLimit; //todo: implement this internally. It is unused for now, it is set by a URDF loader.
151 btScalar m_jointMaxForce; //todo: implement this internally. It is unused for now, it is set by a URDF loader.
152 btScalar m_jointMaxVelocity;//todo: implement this internally. It is unused for now, it is set by a URDF loader.
153
154 // ctor: set some sensible defaults
156 : m_mass(1),
157 m_parent(-1),
158 m_zeroRotParentToThis(0, 0, 0, 1),
159 m_cachedRotParentToThis(0, 0, 0, 1),
160 m_collider(0),
161 m_flags(0),
162 m_dofCount(0),
163 m_posVarCount(0),
166 m_linkName(0),
167 m_jointName(0),
168 m_userPtr(0),
175 {
176
177 m_inertiaLocal.setValue(1, 1, 1);
178 setAxisTop(0, 0., 0., 0.);
179 setAxisBottom(0, 1., 0., 0.);
180 m_dVector.setValue(0, 0, 0);
181 m_eVector.setValue(0, 0, 0);
182 m_cachedRVector.setValue(0, 0, 0);
183 m_appliedForce.setValue( 0, 0, 0);
184 m_appliedTorque.setValue(0, 0, 0);
185 //
186 m_jointPos[0] = m_jointPos[1] = m_jointPos[2] = m_jointPos[4] = m_jointPos[5] = m_jointPos[6] = 0.f;
187 m_jointPos[3] = 1.f; //"quat.w"
190 }
191
192 // routine to update m_cachedRotParentToThis and m_cachedRVector
194 {
195 btScalar *pJointPos = (pq ? pq : &m_jointPos[0]);
196
197 switch(m_jointType)
198 {
199 case eRevolute:
200 {
203
204 break;
205 }
206 case ePrismatic:
207 {
208 // m_cachedRotParentToThis never changes, so no need to update
210
211 break;
212 }
213 case eSpherical:
214 {
215 m_cachedRotParentToThis = btQuaternion(pJointPos[0], pJointPos[1], pJointPos[2], -pJointPos[3]) * m_zeroRotParentToThis;
217
218 break;
219 }
220 case ePlanar:
221 {
223 m_cachedRVector = quatRotate(btQuaternion(getAxisTop(0),-pJointPos[0]), pJointPos[1] * getAxisBottom(1) + pJointPos[2] * getAxisBottom(2)) + quatRotate(m_cachedRotParentToThis,m_eVector);
224
225 break;
226 }
227 case eFixed:
228 {
231
232 break;
233 }
234 default:
235 {
236 //invalid type
237 btAssert(0);
238 }
239 }
240 }
241};
242
243
244#endif //BT_MULTIBODY_LINK_H
btVector3 quatRotate(const btQuaternion &rotation, const btVector3 &v)
Definition: btQuaternion.h:917
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
#define btAssert(x)
Definition: btScalar.h:131
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:55
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652