Suggestion for higher precision velocity integration

ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Suggestion for higher precision velocity integration

Post by ola »

Hello,

I've just made an aircraft aerodynamic model coupled with Bullet. It applies aerodynamic forces on a rigid body generated by the wings to simulate flight.

To increase the precision of the velocity integration in btRigidBody I have a suggestion to use a two-step Adams-Bashford method instead of the current Euler method.

It does not add much extra code or cpu cycles and I've got a working code example here:

Code: Select all

(btRigidBody.cpp)

void btRigidBody::integrateVelocities(btScalar step) 
{
	if (isStaticOrKinematicObject())
		return;

   // Adams-Bashford method for integration
   
   btVector3 accel = m_totalForce*m_inverseMass;
   btVector3 angular_accel = m_invInertiaTensorWorld*m_totalTorque;
   
   btScalar hs = 0.5*step;
   m_linearVelocity += hs*(3.0*accel - m_previousAccel);
   m_angularVelocity += hs*(3.0*angular_accel - m_previousAngularAccel);
   
   m_previousAccel = accel;
   m_previousAngularAccel = angular_accel;

// Euler method:
// 	m_linearVelocity += m_totalForce * (m_inverseMass * step);
// 	m_angularVelocity += m_invInertiaTensorWorld * m_totalTorque * step;

#define MAX_ANGVEL SIMD_HALF_PI
	/// clamp angular velocity. collision calculations will fail on higher angular velocities	
	btScalar angvel = m_angularVelocity.length();
	if (angvel*step > MAX_ANGVEL)
	{
		m_angularVelocity *= (MAX_ANGVEL/step) /angvel;
	}

	clearForces();
}
Also

Code: Select all

btVector3   m_previousAccel;
btVector3   m_previousAngularAccel;
needs to be added to the btRigidBody.h file.

Here's more on the method: http://en.wikipedia.org/wiki/Linear_multistep_method

What do you think?

As an alternative I'd be very happy just to have the integrateVelocities function to be defined as virtual in btRigidBody.h. That way I can replace it myself without maintaining my own version of Bullet.

Best regards,
Ola
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Post by ola »

Oh nevermind. It certainly makes the simulation less stable...

It would still be nice if the integrateVelocities function was defined as virtual (and the class variables defined as protected instead of private).

Cheers
Ola
DevO
Posts: 95
Joined: Fri Mar 31, 2006 7:13 pm

Post by DevO »

Oh nevermind. It certainly makes the simulation less stable...
Why does this happens?
I am also using you code in my Bullet integration and have not noticed it by now.
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Post by ola »

I really don't know yet, but it is connected to the way I did the aerodynamic forces. The stability of the aircraft is made by a balance of the forces between main wings and tail fins so it's probably bound to get out of hand sooner of later.

It only happens with high velocities (well above 100 m/s) and forces. Still does with the Euler method too but then only with even higher velocities. So for slower moving things it should be just fine.
slithEToves
Posts: 24
Joined: Mon Mar 12, 2007 9:55 pm

Post by slithEToves »

Have you tried Runge-Kutta? It is usually considered the best general case numerical differential equation solver, and may work for your situation as well. Second order Runge-Kutta (RK2) is sometimes adequate, but RK4 seems to be the most often used method.

Here are some links:

http://mathworld.wolfram.com/Runge-KuttaMethod.html
http://en.wikipedia.org/wiki/Runge-Kutta_methods
ngbinh
Posts: 117
Joined: Fri Aug 12, 2005 3:47 pm
Location: Newyork, USA

Post by ngbinh »

Changing integrator in simulation is not that simple. If you do this only after you got all bodies's velocity, forces,etc.. and try to use higher integrator based on these information than it doesn't help.

The right way of implementing higher order integrator is rewriting the formulation thus result in different LCP formulation. Actually, if you use higher order integration then most likely it will end up as a Nonlinear CP instead of LCP.