## Controlling Angle of a 6Dof constraints

jgagnet
Posts: 5
Joined: Sun Feb 12, 2012 11:55 am

### Controlling Angle of a 6Dof constraints

Hi,

I had a lot of fun with Bullet but slightly less recently. I need to control the angle of a 6DOF join - the angle is changing over time. I am using a motors and try compute the velocity to move to the angle to the targeted value. Here is the magic:

Code: Select all

``````	btScalar currentAngle = joinConstraint->getRotationalLimitMotor(i)->m_currentPosition;
joinConstraint->getRotationalLimitMotor(i)->m_targetVelocity = (targetedAngle - currentAngle) * 30;
joinConstraint->getRotationalLimitMotor(i)->m_maxMotorForce = 10.0f;
``````
This is sort of working. However depending of the shape (think of a spider) the legs don't have enough strength to support the body and my target angle are not met. If I increase the magic number 30 the simulation become very unstable.

I looked at the MotorDemo and it seems like I doing something similar.
I look at the code of the motors and it seems to be doing a lot of smart things. Is there something I've mis configured?
I remember hearing about PID controller back at school. Should I replace the motors with one of this PID monster?
Have anyone done something similar that could lead me on the right direction.

Thanks in for any help or thoughts.

Julien

Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

### Re: Controlling Angle of a 6Dof constraints

jgagnet wrote:However depending of the shape (think of a spider) the legs don't have enough strength to support the body and my target angle are not met. If I increase the magic number 30 the simulation become very unstable.
I've used 2. as "magic number" (instead of 30).
I've used much higher maxMotorForces (e.g. 10000000000, but I guess it might depend on the mass of the bodies...), and in addition I used a "reachedLimitEpsilon" ( = btRadians(5) ) that ends an animation transition "early" (when the difference (targetedAngle - currentAngle)< reachedLimitEpsilon).

That helped me to limit (but not to completely avoid) the problem.
Maybe you can try with lighter bodies or with slightly modified animations too...

So no bullet-proof solution from me, just a few hints

jgagnet
Posts: 5
Joined: Sun Feb 12, 2012 11:55 am

### Re: Controlling Angle of a 6Dof constraints

Hi Flix,

Thanks for your advices. I did try them and changing the magic number and the max motor force without any luck. Then you suggested making the body lighter which made everything a lot worse.

So I made the body heavier and that worked. A lot heavier. I've multiplied the mass by 100. It's now amazingly stable!

I working with shape around 100cm and the mass is now width*height*depth*100.

Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

### Re: Controlling Angle of a 6Dof constraints

jgagnet wrote:Then you suggested making the body lighter which made everything a lot worse. So I made the body heavier and that worked. A lot heavier. I've multiplied the mass by 100. It's now amazingly stable!
Wow, I gave you very useful tips indeed...
Actually I just reused a ragdoll from a previous Bullet demo, and now that you make me think about it, I remember that in that demo the gravity was set to something like (0,-30,0)

This is a very useful hint in my opinion, thank you for discovering it!

(the only problem is that now characters can be heavier (and stronger) than vehicles... ... good stuff for a video game about Superman ).

[Edit:] Actually in my code making the bodies lighter DOES improve things: the constraints are less "violated" and their motors have no problem moving them correctly (even if they must "lift" the character body against gravity). So I have the exact opposite problem: the character is too light (I guess that increasing the time step would allow me to use slightly heavier bodies). I suppose jgagnet's use of btGeneric6DofConstraints in his program must be different from mine.

Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

### Re: Controlling Angle of a 6Dof constraints

Flix wrote:Actually in my code making the bodies lighter DOES improve things: the constraints are less "violated" and their motors have no problem moving them correctly (even if they must "lift" the character body against gravity). So I have the exact opposite problem: the character is too light (I guess that increasing the time step would allow me to use slightly heavier bodies). I suppose jgagnet's use of btGeneric6DofConstraints in his program must be different from mine.
After a lot of testing I discovered why: actually it seems that the "stability" (or more appropriate "stiffness") of a btGeneric6DofConstraint increases when the local inertia of the bodies gets bigger: so I just used a bigger mass in the btCollisionShape::calculateLocalInertia(...) methods (and not in my rigid bodies); now my constraints work better and I have no more problems with gravity .

PS. Tuning the properties of the btGeneric6DofConstraints has less influence on the constraint stiffness compared to this approach (in the tests I've made so far).

jgagnet
Posts: 5
Joined: Sun Feb 12, 2012 11:55 am

### Re: Controlling Angle of a 6Dof constraints

Hi,

My game I was asking the question for just made its way to the App Store:
http://itunes.apple.com/gb/app/learning ... d530192045

I am using Bullet to run some genetics algorithms. Most of the physics simulation happen in the background and it clearly show how fast is Bullet. The game is running on an iPad and I can get through thousand of physical steps in a second.

I would love any feedback if anyone tries it.

Thanks a lot for your help.

Julien