Friction direction and impulse problem

ins7itia
Posts: 5
Joined: Wed Feb 01, 2012 5:37 am

Friction direction and impulse problem

Post by ins7itia »

Hi!

I had trouble with the friction. Previously, I could not get the lateral values (post: http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=7906)

Examining through btSequentialImpulseConstraintSolver, I understood how to update
friction values. It's interesting to learn how these variables work.


Now I can get the friction force, but still, I cannot understand regarding it's order.

When you look down into adding friction constraint sequence in btSequentialImpulseConstraintSolver, you can see that m_lateralFrictionDir2 is added prior to m_lateralFrictionDir1. With this order, after in resolve sequences, m_appliedImpulseLateral1 is set by the value which was computed from m_lateralFrictionDir2. It means, if you want to use friction direction and magnitude from outside, you should use m_lateralFrictionDir1 with m_appliedImpulseLateral2, and vice versa.

It was quite confusing, and I took a look through the functions of btSequentialImpulseConstraintSolver to verify the problem. I'm not sure if that is intended or not, but if it needs to be fixed, then just changing addition code should be enough.

for example, inside convertContact:

Code: Select all

if (!(infoGlobal.m_solverMode & SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION) && lat_rel_vel > SIMD_EPSILON)
				{
					cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel);
					if((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS))
					{
						cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
						cp.m_lateralFrictionDir2.normalize();//??
						applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir2);
						applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2);
						addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
					}

					applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1);
					applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1);
					addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
					cp.m_lateralFrictionInitialized = true;
				}

after changing order of adding constraints:

Code: Select all

if (!(infoGlobal.m_solverMode & SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION) && lat_rel_vel > SIMD_EPSILON)
				{
					cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel);

					applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1);
					applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1);
					addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);

					if((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS))
					{
						cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
						cp.m_lateralFrictionDir2.normalize();//??
						applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir2);
						applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2);
						addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
					}

					cp.m_lateralFrictionInitialized = true;
				}
anyway
Posts: 2
Joined: Mon Apr 23, 2012 2:57 pm

Re: Friction direction and impulse problem

Post by anyway »

Hi,

I had similar problems like you had. First I was not able to get the lateral components of the contact impulses. First I applied the solver flags and the values are updated now.

But even if I follow your advise concerning the changes in the code of Bullet, I can't manage to get proper results for the friction force applied to the body. I inserted a debug output for the values of m_appliedLateralImpulse1 and m_appliedLateralImpulse2 but these values change all the time as if they are integrated or they accumulate some values. In my example (10° inclined plane and a body on it) the value for m_appliedLateralImpulse1 change from 0.20 to -0.20 over a period of approximately 30 seconds and than keep that value. I did some analysis of the btSequentialImpulseConstraintSolver.cpp without finding something that helped.

Did you manged to get proper values for friction force? Or did anyone ever?

Regards,
anyway