Page 1 of 1

btRotationalLimitMotor lock

Posted: Mon May 03, 2010 10:56 pm
by zlash
Hello!

I recently started using bullet and I find it very useful, thanks for your hard work!
However, I've been struggling the last days trying to simulate some kind of servo motor. After lots of tests involving different constraints with different parameters, I decided to settle with a locked btGeneric6DofConstraint by changing the locked range every time the motor needs to move. This worked fairly well, but when the motor went over PI or under -PI, it turned along the longest arc path to reach the new locking position.
Luckly the btRotationalLimitMotor code was very easy to understand, and I made the following changes to btRotationalLimitMotor::testLimitValue (added lines preceded with ++):

Code: Select all

	if (test_value < m_loLimit)
	{
		m_currentLimit = 1;//low limit violation
		m_currentLimitError =  test_value - m_loLimit;
++		 if(m_currentLimitError>SIMD_PI) m_currentLimitError-=SIMD_2_PI;
++		 else if(m_currentLimitError<-SIMD_PI) m_currentLimitError+=SIMD_2_PI;
		return 1;
	}
	else if (test_value> m_hiLimit)
	{
		m_currentLimit = 2;//High limit violation
		m_currentLimitError = test_value - m_hiLimit;
++		if(m_currentLimitError>SIMD_PI) m_currentLimitError-=SIMD_2_PI;
++		else if(m_currentLimitError<-SIMD_PI) m_currentLimitError+=SIMD_2_PI;
		return 2;
	};
It works as I want, however, I'm wondering if I've broken some other expected behavior by manipulating the limit error this way.
Does somebody knows what could go wrong with change?
Thanks in advance.

Re: btRotationalLimitMotor lock

Posted: Tue May 04, 2010 2:24 am
by jarno
I think the 6Dof constraint has problems in general with rotations beyond a hemisphere or so from rest. Its calculateAngleInfo() computes a constraint coordinate system in such a way that effectively wraps around or flips an axis when one basis is rotated more than +-90 degrees from the other.

Mathematically, the vector resulting from the cross product of the Z and X axes of basis A and B respectively flips direction when the angle between them changes from positive to negative, or from less than 180 degrees to more than 180 degrees.

The effect in the simulation can be like the rotation hitting a hard stop and bouncing back.

---JvdL---

Re: btRotationalLimitMotor lock

Posted: Fri Feb 17, 2012 4:59 pm
by Flix
I know that this thread is nearly two years old, but I just wanted to say that I've found the code modification zlash posted very useful when locking a btRotationalLimitMotor that was free to rotate around one axis.
Please see http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=4457 for further info on how to unlock an axis (it seems to work with the X or Z axis free (which is better?), since the Y axis must always be in [-SIMD_HALF_PI,SIMD_HALF_PI] ).

Basically in this context this fix was very useful for me: although a 6DofConstraint with a free rotational axis can rotate seamlessly when a motor with a target velocity is applied without zlash fix, I've found out that problems may arise when we want to "lock" the free rotational axis in one position without this fix. So basically AFAIK this fix makes a "seamless lock" possible on such an axis (and prevents situations in which the locked axis (m_loLimit=m_hiLimit=m_currentPosition, m_motorEnabled=false) instead of being locked starts spinning like crazy).

I don't know if it breaks something (I've not seen any difference so far), but I think that all the people working with a 6DofConstraint with a free rotational axis should try it.

And I wanted to thank zlash for the fix (I've tried to achieve the same without modifying the Bullet source code with no luck).

Re: btRotationalLimitMotor lock

Posted: Sat Feb 18, 2012 9:12 am
by Erwin Coumans
Good point. I'll apply the fix in the Bullet source tree.

Thanks!
Erwin