Physics Simulation Forum


All times are UTC

Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon May 03, 2010 10:56 pm 

Joined: Mon May 03, 2010 10:38 pm
Posts: 1

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 ++):

   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.

PostPosted: Tue May 04, 2010 2:24 am 
User avatar

Joined: Tue Mar 16, 2010 1:42 am
Posts: 57
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.


PostPosted: Fri Feb 17, 2012 4:59 pm 

Joined: Tue Dec 25, 2007 1:06 pm
Posts: 456
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 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).

PostPosted: Sat Feb 18, 2012 9:12 am 
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 4054
Location: California, USA
Good point. I'll apply the fix in the Bullet source tree.


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 14 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group