Bullet Collision Detection & Physics Library
btMultiBodyJointMotor.cpp
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
17
19#include "btMultiBody.h"
22
24 : btMultiBodyConstraint(body, body, link, body->getLink(link).m_parent, 1, true, MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR),
25 m_desiredVelocity(desiredVelocity),
26 m_desiredPosition(0),
27 m_kd(1.),
28 m_kp(0),
29 m_erp(1),
30 m_rhsClamp(SIMD_INFINITY)
31{
33 // the data.m_jacobians never change, so may as well
34 // initialize them here
35}
36
38{
40 // note: we rely on the fact that data.m_jacobians are
41 // always initialized to zero by the Constraint ctor
42 int linkDoF = 0;
43 unsigned int offset = 6 + (m_bodyA->getLink(m_linkA).m_dofOffset + linkDoF);
44
45 // row 0: the lower bound
46 // row 0: the lower bound
47 jacobianA(0)[offset] = 1;
48
50}
51
53 //:btMultiBodyConstraint(body,0,link,-1,1,true),
54 : btMultiBodyConstraint(body, body, link, body->getLink(link).m_parent, 1, true, MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR),
55 m_desiredVelocity(desiredVelocity),
56 m_desiredPosition(0),
57 m_kd(1.),
58 m_kp(0),
59 m_erp(1),
60 m_rhsClamp(SIMD_INFINITY)
61{
62 btAssert(linkDoF < body->getLink(link).m_dofCount);
63
65}
67{
68}
69
71{
72 if (this->m_linkA < 0)
73 {
75 if (col)
76 return col->getIslandTag();
77 }
78 else
79 {
81 {
83 }
84 }
85 return -1;
86}
87
89{
90 if (m_linkB < 0)
91 {
93 if (col)
94 return col->getIslandTag();
95 }
96 else
97 {
99 {
101 }
102 }
103 return -1;
104}
105
109{
110 // only positions need to be updated -- data.m_jacobians and force
111 // directions were set in the ctor and never change.
112
114 {
116 }
117
118 //don't crash
120 return;
121
122 if (m_maxAppliedImpulse == 0.f)
123 return;
124
125 const btScalar posError = 0;
126 const btVector3 dummy(0, 0, 0);
127
128 for (int row = 0; row < getNumRows(); row++)
129 {
131
132 int dof = 0;
136
139 if (rhs > m_rhsClamp)
140 {
141 rhs = m_rhsClamp;
142 }
143 if (rhs < -m_rhsClamp)
144 {
145 rhs = -m_rhsClamp;
146 }
147
149 constraintRow.m_orgConstraint = this;
150 constraintRow.m_orgDofIndex = row;
151 {
152 //expect either prismatic or revolute joint type for now
155 {
157 {
158 constraintRow.m_contactNormal1.setZero();
159 constraintRow.m_contactNormal2.setZero();
161 constraintRow.m_relpos1CrossNormal = revoluteAxisInWorld;
162 constraintRow.m_relpos2CrossNormal = -revoluteAxisInWorld;
163
164 break;
165 }
167 {
169 constraintRow.m_contactNormal1 = prismaticAxisInWorld;
170 constraintRow.m_contactNormal2 = -prismaticAxisInWorld;
171 constraintRow.m_relpos1CrossNormal.setZero();
172 constraintRow.m_relpos2CrossNormal.setZero();
173
174 break;
175 }
176 default:
177 {
178 btAssert(0);
179 }
180 };
181 }
182 }
183}
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
@ MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR
btVector3 quatRotate(const btQuaternion &rotation, const btVector3 &v)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define SIMD_INFINITY
Definition btScalar.h:544
#define btAssert(x)
Definition btScalar.h:153
btScalar * jacobianA(int row)
btScalar * jacobianB(int row)
btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint &solverConstraint, btMultiBodyJacobianData &data, btScalar *jacOrgA, btScalar *jacOrgB, const btVector3 &constraintNormalAng, const btVector3 &constraintNormalLin, const btVector3 &posAworld, const btVector3 &posBworld, btScalar posError, const btContactSolverInfo &infoGlobal, btScalar lowerLimit, btScalar upperLimit, bool angConstraint=false, btScalar relaxation=1.f, bool isFriction=false, btScalar desiredVelocity=0, btScalar cfmSlip=0, btScalar damping=1.0)
virtual int getIslandIdB() const
btMultiBodyJointMotor(btMultiBody *body, int link, btScalar desiredVelocity, btScalar maxMotorImpulse)
This file was written by Erwin Coumans.
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)
virtual int getIslandIdA() const
btScalar * getJointPosMultiDof(int i)
const btMultibodyLink & getLink(int index) const
const btMultiBodyLinkCollider * getBaseCollider() const
btScalar * getJointVelMultiDof(int i)
btQuaternion getRotation() const
Return a quaternion representing the rotation.
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...