"Motor at limit" jitter fixed for btGeneric6Dof constraint

This also _should_ fix situation when 6DOF constraint with motor get stuck at limit 
(see forum topic at  http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=3598&p=13603&hilit=ode*#p13603 )
This commit is contained in:
rponom
2009-05-27 00:36:02 +00:00
parent c9f3d3f8b6
commit 056659d2af
2 changed files with 14 additions and 2 deletions

View File

@@ -418,6 +418,7 @@ void btGeneric6DofConstraint::buildAngularJacobian(
bool btGeneric6DofConstraint::testAngularLimitMotor(int axis_index) bool btGeneric6DofConstraint::testAngularLimitMotor(int axis_index)
{ {
btScalar angle = m_calculatedAxisAngleDiff[axis_index]; btScalar angle = m_calculatedAxisAngleDiff[axis_index];
m_angularLimits[axis_index].m_currentPosition = angle;
//test limits //test limits
m_angularLimits[axis_index].testLimitValue(angle); m_angularLimits[axis_index].testLimitValue(angle);
return m_angularLimits[axis_index].needApplyTorques(); return m_angularLimits[axis_index].needApplyTorques();
@@ -542,6 +543,7 @@ int btGeneric6DofConstraint::setLinearLimits(btConstraintInfo2* info)
{ // re-use rotational motor code { // re-use rotational motor code
limot.m_bounce = btScalar(0.f); limot.m_bounce = btScalar(0.f);
limot.m_currentLimit = m_linearLimits.m_currentLimit[i]; limot.m_currentLimit = m_linearLimits.m_currentLimit[i];
limot.m_currentPosition = m_linearLimits.m_currentLinearDiff[i];
limot.m_currentLimitError = m_linearLimits.m_currentLimitError[i]; limot.m_currentLimitError = m_linearLimits.m_currentLimitError[i];
limot.m_damping = m_linearLimits.m_damping; limot.m_damping = m_linearLimits.m_damping;
limot.m_enableMotor = m_linearLimits.m_enableMotor[i]; limot.m_enableMotor = m_linearLimits.m_enableMotor[i];
@@ -694,6 +696,7 @@ void btGeneric6DofConstraint::calculateLinearInfo()
m_calculatedLinearDiff = m_calculatedTransformA.getBasis().inverse() * m_calculatedLinearDiff; m_calculatedLinearDiff = m_calculatedTransformA.getBasis().inverse() * m_calculatedLinearDiff;
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
{ {
m_linearLimits.m_currentLinearDiff[i] = m_calculatedLinearDiff[i];
m_linearLimits.testLimitValue(i, m_calculatedLinearDiff[i]); m_linearLimits.testLimitValue(i, m_calculatedLinearDiff[i]);
} }
} }
@@ -743,9 +746,16 @@ int btGeneric6DofConstraint::get_limit_motor_info2(
if (powered) if (powered)
{ {
info->cfm[srow] = 0.0f; info->cfm[srow] = 0.0f;
if(!limit) // if(!limit)
{ {
info->m_constraintError[srow] += limot->m_targetVelocity; btScalar tag_vel = rotational ? limot->m_targetVelocity : -limot->m_targetVelocity;
btScalar mot_fact = getMotorFactor( limot->m_currentPosition,
limot->m_loLimit,
limot->m_hiLimit,
tag_vel,
info->fps * info->erp);
info->m_constraintError[srow] += mot_fact * limot->m_targetVelocity;
info->m_lowerLimit[srow] = -limot->m_maxMotorForce; info->m_lowerLimit[srow] = -limot->m_maxMotorForce;
info->m_upperLimit[srow] = limot->m_maxMotorForce; info->m_upperLimit[srow] = limot->m_maxMotorForce;
} }

View File

@@ -54,6 +54,7 @@ public:
//! temp_variables //! temp_variables
//!@{ //!@{
btScalar m_currentLimitError;//! How much is violated this limit btScalar m_currentLimitError;//! How much is violated this limit
btScalar m_currentPosition; //! current value of angle
int m_currentLimit;//!< 0=free, 1=at lo limit, 2=at hi limit int m_currentLimit;//!< 0=free, 1=at lo limit, 2=at hi limit
btScalar m_accumulatedImpulse; btScalar m_accumulatedImpulse;
//!@} //!@}
@@ -134,6 +135,7 @@ public:
btVector3 m_targetVelocity;//!< target motor velocity btVector3 m_targetVelocity;//!< target motor velocity
btVector3 m_maxMotorForce;//!< max force on motor btVector3 m_maxMotorForce;//!< max force on motor
btVector3 m_currentLimitError;//! How much is violated this limit btVector3 m_currentLimitError;//! How much is violated this limit
btVector3 m_currentLinearDiff;//! Current relative offset of constraint frames
int m_currentLimit[3];//!< 0=free, 1=at lower limit, 2=at upper limit int m_currentLimit[3];//!< 0=free, 1=at lower limit, 2=at upper limit
btTranslationalLimitMotor() btTranslationalLimitMotor()