Pose matching with direct angular velocity control

Post Reply
David20321
Posts: 17
Joined: Sat Mar 13, 2010 10:08 pm

Pose matching with direct angular velocity control

Post by David20321 »

I am working on animation for my new game, more specifically I am working on partial ragdolls. For example, in a walking animation I can set the character's arms to be only partially kinematic so that they swing a little when changing direction. Currently I am using btHingeConstraint and Generic6DofConstraint, and their corresponding rotational motors.

However, I am having trouble getting the parameters right to make it look natural, largely because the motor parameters (target angular velocity and maximum motor force) are secondary values for what I really need.

Let's consider a simple hinge joint like the elbow, which is currently bent at 90 degrees, and the target angle is 70 degrees. Right now I then set the motor to a target angular velocity of -20 degrees per timestep, and the maximum force to a high amount. This successfully achieves 100% pose matching. Similarly, I can set the maximum force to 0 to get 0% pose matching, and leave the arm completely limp.

The hard part is when I want something like 50% pose matching. I would like this to work like an angular spring that adds 50% of the angular difference to the angular velocity every timestep. However, I don't know how to set this up using the exposed motor parameters (target velocity and maximum motor force).

I suppose I could do it by setting the target velocity to + or - infinity and setting the max motor force based on torque = inertia tensor * angular acceleration, and then modulate it by the amount of pose matching I want. Surely there is a more direct way to do this though?
User avatar
rponomarev
Posts: 56
Joined: Sat Mar 08, 2008 12:37 am

Re: Pose matching with direct angular velocity control

Post by rponomarev »

Hello,

You may try to use btGeneric6DofSpringConstraint or derive your own hinge constraint
from btHingeConstraint and use code like btGeneric6DofSpringConstraint::internalUpdateSprings()
to update motor parameters on each step depending on pose matching that you need
Basically targetVelocity adds some value to the right-hand side of constraint equation and
maxMotorForce defines limits for the sequential-impulse solver
So if you need spring-like behavior you will need to update these parameters on each simulation step.
btGeneric6DofSpringConstraint does this by calling btGeneric6DofSpringConstraint::internalUpdateSprings()
from btGeneric6DofSpringConstraint::getInfo2(), which is automatically called by Bullet library on each simulation step
before constraint solving.



Hope this will help,
Roman
David20321
Posts: 17
Joined: Sat Mar 13, 2010 10:08 pm

Re: Pose matching with direct angular velocity control

Post by David20321 »

Thanks! I can successfully create spring-like behavior, but I am having trouble figuring out exactly what parameters will result in the pose being 100% matched, 50% matched, and so on, so that I can control it in a precise way. That is, I'm trying to act on the angle velocity directly in this manner:

angle_vel *= (1.0 - damping);
angle_vel += (target_angle - angle) * pose_strength;

This way if pose_strength = 1.0 and damping = 1.0, it behaves in a purely kinematic way, and if pose_strength = 0.0 and damping = 0.0, it behaves in a purely dynamic way. Then I can mix the parameters in between to get different kinds of partial pose matching.

I'm not sure how to get this kind of result using the motor force and target velocity directly because the force and velocity interact in complicated ways, and I am having trouble figuring out how to precisely compensate for that.
paul.dubois
Posts: 10
Joined: Thu May 20, 2010 10:45 pm

Re: Pose matching with direct angular velocity control

Post by paul.dubois »

David20321 wrote:Thanks! I can successfully create spring-like behavior, but I am having trouble figuring out exactly what parameters will result in the pose being 100% matched, 50% matched, and so on, so that I can control it in a precise way.
If you want the object to move N% of the way to the goal during a fixed timestep dt, that is essentially exponential decay towards a goal. You are asking how to get that exponential decay through application of forces and torques.

Fortunately for you, a critically-damped spring system acts like exponential decay. Google "critical damping" and you'll easily find closed-form equations that give you the relationship between a spring constant, critical damping, and the resulting curve. The derivation is also not so difficult. Just be warned that equations assume a perfect integrator; the stiffer your system the more the results will diverge from ideal.

Also, I am pretty sure this will NOT work for the general case of a non-trivial inertia tensor being forced/damped towards a goal orientation. But if rotation is always about a fixed axis, or if you can otherwise make the magnitude of the moment of inertia constant, it should all work out identically to the translational case.
Post Reply