btGeneric6DofConstraint - Division by zero when inertia 0

Post Reply
skol81
Posts: 4
Joined: Wed Dec 02, 2009 8:32 am

btGeneric6DofConstraint - Division by zero when inertia 0

Post by skol81 »

Hi,

I am using Bullet for a robot simulator and I am trying to get the generic 6DOF joint working by using a Blender Collada export which I reimport using our own tools and create the Bullet world.

I have two rigid bodies, one is static and has 0 mass and the other is dynamic and has mass 1kg. The two are connected using the constraint.

Code: Select all

			<rigid_body name="r_upper_arm-RigidBody" sid="r_upper_arm-RigidBody">
				<technique_common>
					<dynamic>false</dynamic>
					<mass>0</mass>
					<instance_physics_material url="#r_upper_arm-PhysicsMaterial"/>
					<shape>
						<instance_geometry url="#r_upper_arm-Geometry"/>
					</shape>
				</technique_common>
			</rigid_body>
			<rigid_body name="r_lower_arm-RigidBody" sid="r_lower_arm-RigidBody">
				<technique_common>
					<dynamic>true</dynamic>
					<mass>1.0</mass>
					<instance_physics_material url="#r_lower_arm-PhysicsMaterial"/>
					<shape>
						<instance_geometry url="#r_lower_arm_004"/>
					</shape>
				</technique_common>
			</rigid_body>
			<rigid_constraint name="Const" sid="Const">
				<ref_attachment rigid_body="r_upper_arm-RigidBody">
					<translate>0.00000 0.00000 -1.05833</translate>
					<rotate>1 0 0 0.00000</rotate>
					<rotate>0 1 0 -0.00000</rotate>
					<rotate>0 0 1 90.00000</rotate>
				</ref_attachment>
				<attachment rigid_body="r_lower_arm-RigidBody">
					<translate>0.00000 0.00000 1.02500</translate>
					<rotate>1 0 0 0.00000</rotate>
					<rotate>0 1 0 0.00000</rotate>
					<rotate>0 0 1 90.00000</rotate>
				</attachment>
				<technique_common>
					<enabled>true</enabled>
					<limits>
						<linear>
							<min>0 0 0</min>
							<max>0 0 0</max>
						</linear>
						<swing_cone_and_twist>
							<min>0 0 0</min>
							<max>0 0 0</max>
						</swing_cone_and_twist>
					</limits>
				</technique_common>
			</rigid_constraint>
When using the btGeneric6DofConstraint I am running in a division by zero in the btSequentialImpulseConstraintSolver in the following lines:

Code: Select all

							btVector3 iMJlA = solverConstraint.m_contactNormal*rbA.getInvMass();
							btVector3 iMJaA = rbA.getInvInertiaTensorWorld()*solverConstraint.m_relpos1CrossNormal;
							btVector3 iMJlB = solverConstraint.m_contactNormal*rbB.getInvMass();//sign of normal?
							btVector3 iMJaB = rbB.getInvInertiaTensorWorld()*solverConstraint.m_relpos2CrossNormal;

							btScalar sum = iMJlA.dot(solverConstraint.m_contactNormal);
							sum += iMJaA.dot(solverConstraint.m_relpos1CrossNormal);
							sum += iMJlB.dot(solverConstraint.m_contactNormal);
							sum += iMJaB.dot(solverConstraint.m_relpos2CrossNormal);

							solverConstraint.m_jacDiagABInv = btScalar(1.)/sum;
The inertia is calculated in the code by calling calculateLocalInertia but of course only for the 1kg mass body. What I found out is that for the 1st constraint row everything works fine but for the second the m_contactNormal is 0 which causes the iMJlB to become 0 and the same happens for the iMJaB. Hence sum becomes also 0 and I have the division by zero. I do not really understand the internals of the constraint solver but it makes some sense to me that the iMJaA and iMJlA are 0 for the zero mass body. But for the 1kg mass body this should not happen I guess.

Could this be a Bullet problem or a problem in our code. Maybe someone could give me a hint to speed up the debugging process.

Thanks a lot.

Cheers
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: btGeneric6DofConstraint - Division by zero when inertia 0

Post by Erwin Coumans »

It is hard to tell where the problem is, but the bodies/constraints are likely not initialized properly.

If you are using Blender, the best way is to extract the rigid body information straight from the .blend file: check out the GameKit project.
Can you try to load your .blend file into GameKit and let us know the results? Can you share the .blend, attached as zipfile?

Thanks,
Erwin
skol81
Posts: 4
Joined: Wed Dec 02, 2009 8:32 am

Re: btGeneric6DofConstraint - Division by zero when inertia 0

Post by skol81 »

SOLVED

I found the bug in my code. The inertia was not calculated and the inertia tensor was not updated after setting setMassProps() for the rigid body. Thanks anyway for the reply.
Tony
Posts: 6
Joined: Tue Sep 03, 2013 1:36 pm

Re: btGeneric6DofConstraint - Division by zero when inertia

Post by Tony »

skol81 wrote:SOLVED

I found the bug in my code. The inertia was not calculated and the inertia tensor was not updated after setting setMassProps() for the rigid body. Thanks anyway for the reply.
Hi,

I also encounter the same problem, how do you solve the problem?
Thanks
Post Reply