Contact Info

sandeep_slash
Posts: 48
Joined: Thu Jul 10, 2008 6:36 pm

Contact Info

Post by sandeep_slash »

btManifoldPoint doesn't say anthing about contact force and contact torque info.

Can someone tell me how to get this info when 2 bodies collide?

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

Re: Contact Info

Post by Erwin Coumans »

Bullet uses an impulse-based constraint solver, so it applies impulses.

The applied impulse vector is stored in btManifoldPoint::m_appliedImpulse

Note that you have to access this information _after_ the constraint solver is finished, so a good place is the internal tick callback, btDynamicsWorld::setInternalTickCallback. See Demos\CollisionInterfaceDemo\CollisionInterfaceDemo.cpp how to iterate over contact manifolds and contact points.

Hope this helps,
Erwin
peacemoon
Posts: 15
Joined: Wed Sep 03, 2008 12:52 pm

How to get force feedback at the contact point?

Post by peacemoon »

I use Bullet in Haptic application. My programm interacts with a robot. The robot sends velocity information to the program and receives force information back. I have searched all the documents and found out that i can't get feedback force with bullet, and i can only get impulse (m_appliedImpulse). But m_appliedImpulse is a scalar value, but what i need is a vector value so that i can get the directions of feedback impulse . Is there any function in Bullet so that i can get it?
peacemoon
Posts: 15
Joined: Wed Sep 03, 2008 12:52 pm

Re: Contact Info

Post by peacemoon »

i figured out how to do this: use m_normalWorldOnB and m_appliedImpulse.
I also found in class btRigidBody 2 private attributes m_totalForce, m_totalTorque . Why are these attributes private and there isn't any function to read theses values ? I think the author could do this with purpose ??? . So, is there any method so that i can read the feedback forces and torques that apply to a body when collision occurred? (like function dJointGetFeedback in ODE)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Contact Info

Post by Erwin Coumans »

peacemoon wrote:i figured out how to do this: use m_normalWorldOnB and m_appliedImpulse.
So, is there any method so that i can read the feedback forces and torques that apply to a body when collision occurred? (like function dJointGetFeedback in ODE)
Indeed, m_appliedImpulse*m_normalWorldOnB is your applied impulse vector.

If you need a force, just multiply by the timestep: impulse = deltaTime*force. Ignore the internal btRigidBody members, they simply accumulate the external forces applied by the user.

Hope this helps,
Erwin
sandeep_slash
Posts: 48
Joined: Thu Jul 10, 2008 6:36 pm

Re: Contact Info

Post by sandeep_slash »

Hey Erwin,

Thanks for the info....

In CharacterDemo,

Code: Select all

void debugDrawContacts()
{
	.....

	for (int p=0;p<manifold->getNumContacts();p++)
	{
		const btManifoldPoint&pt = manifold->getContactPoint(p);
	}
}
I tried debugging btManifoldPoint to get the contactinfo. When the character hits the ground, m_appliedImpulse will be zero.

As, ImpulseVector = (m_appliedImpulse * m_normalWorldonB)

Therefore, ContactForce = ImpulseVector/deltaTime, will also be zero....
peacemoon
Posts: 15
Joined: Wed Sep 03, 2008 12:52 pm

Re: Contact Info

Post by peacemoon »

Erwin Coumans wrote:
peacemoon wrote:i figured out how to do this: use m_normalWorldOnB and m_appliedImpulse.
So, is there any method so that i can read the feedback forces and torques that apply to a body when collision occurred? (like function dJointGetFeedback in ODE)
Indeed, m_appliedImpulse*m_normalWorldOnB is your applied impulse vector.

If you need a force, just multiply by the timestep: impulse = deltaTime*force. Ignore the internal btRigidBody members, they simply accumulate the external forces applied by the user.

Hope this helps,
Erwin
Thanks Erwin for your answer.
is the unit of the impulse in SI (kg*m/s)? And when i step the world like this: dynamicsWorld->stepSimulation(0.001,10,0.01); and use InternalTickCallback for the collision detection, should i use the fixedTimeStep (=0.01) as the deltaTime to calculate the force or should i use an btClock variable to measure the deltaTime ?

Thanks
peacemoon
Posts: 15
Joined: Wed Sep 03, 2008 12:52 pm

Re: Contact Info

Post by peacemoon »

This is my internaltickcallback

Code: Select all

void myTickCallback( btDynamicsWorld *world, btScalar timeStep) {
	if (world)
		world->performDiscreteCollisionDetection();
	int i;
	///one way to draw all the contact points is iterating over contact manifolds / points:
	int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
	for (i=0;i<numManifolds;i++)
	{
		btPersistentManifold* contactManifold = world->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

		int numContacts = contactManifold->getNumContacts();
		for (int j=0;j<numContacts;j++)
		{
			btManifoldPoint& contactPoint = contactManifold->getContactPoint(j);
			btVector3 normal = contactPoint.m_normalWorldOnB;
			btScalar angleX = normal.angle(btVector3(1,0,0));
			btScalar angleY = normal.angle(btVector3(0,1,0));
			btScalar angleZ = normal.angle(btVector3(0,0,1));
			btScalar impulseX = contactPoint.m_appliedImpulse*cos(angleX);
			btScalar impulseY = contactPoint.m_appliedImpulse*cos(angleY);
			btScalar impulseZ = contactPoint.m_appliedImpulse*cos(angleZ);
			btScalar forceX = impulseX/(timeStep);
			btScalar forceY = impulseY/(timeStep);
			btScalar forceZ = impulseZ/(timeStep);
			//printf("Force: %8.6f %8.6f %8.6f %8.6f \n",(float)timeStep,forceX,forceY,forceZ);
		}
	}
}
My Problem is that, when i vary the timeStep, i have the same impulse but different forces .
Can anyone help me to calculate the right feedback forces? I step my world with this: dynamicsWorld->stepSimulation(0.001,0);

Thanks
peacemoon
Posts: 15
Joined: Wed Sep 03, 2008 12:52 pm

Re: Contact Info

Post by peacemoon »

ok, i try to post my question the last time, and hopefully that someone can help me.
I use Bullet in my haptic application. A robot sends velocity information to my program. In my program, a ball will be move with this velocity and hit a wall, the program simulates the scene and sends force information back to the robot.
I measured the values and i have something like that.
The robot sends the velocity with the value of about 0.1m/s in x-direction
After i use the callback above, i have the impulse at the contact point = 1.4 <-- i don't know whether the unit is in SI.
Because i step my program with this dynamicsWorld->stepSimulation(0.001,0); (the robot works with frequency 1kHz), and i use this form force = impulse / deltaTime to calculate the feedback force => i have a feedback force of about 1400 .
When the unit of this force is [N] => the force is too big, because the sensor on the robot indicates that i applied only about 6N on the robot.
I have searched in forum for 2 weeks and can't find an answer for my problem.
My program worked with ODE, but ODE doesn't calculate somehow the feedback force accurately as i want. I really want to try Bullet but i have struggled with this problem for weeks. So, hopefully that some can light me the way.
Thanks
sandeep_slash
Posts: 48
Joined: Thu Jul 10, 2008 6:36 pm

Re: Contact Info

Post by sandeep_slash »

Hey peacemoon,

Even I'm working on the similiar stuff... I'd used dJointfeedback in ODE code to get torque and force...

So, I'm curious to know how you calculate Torque in Bullet...

Thanx...
peacemoon
Posts: 15
Joined: Wed Sep 03, 2008 12:52 pm

Re: Contact Info

Post by peacemoon »

hi sandeep_slash,
i don't need Torque, so that i still don't think about it. But i think we have to calculate it explicitly with force and distance .
Can you calculate force right?
Can you show me your code?
Thanks
sandeep_slash
Posts: 48
Joined: Thu Jul 10, 2008 6:36 pm

Re: Contact Info

Post by sandeep_slash »

Hi,

This is how I calculate Force and Torque.... I'm not sure if it's correct...

Code: Select all

LinearImpulse = m_appliedImpulse * m_normalWorldOnB;
Force = LinearImpulse/dt;

AngularImpulse = LinearImpulse.CrossProduct(CentreOfMass - m_positionWorldOnB);
Torque = AngularImpulse/dt;
Do you think it's correct?


Thanks,
Sandeep.
peacemoon
Posts: 15
Joined: Wed Sep 03, 2008 12:52 pm

Re: Contact Info

Post by peacemoon »

what is your dt?
Can you post your whole function?

As i said, when i use timeStep as dt, i have a very big force!!

Regards
prince
Posts: 4
Joined: Tue Jul 08, 2008 11:20 am

Re: Contact Info

Post by prince »

I am facing the same problem- big value for force. Has anyone found the solution?
sara
Posts: 39
Joined: Thu Mar 24, 2011 3:50 pm

Re: Contact Info

Post by sara »

Anybody has found the answer to the big forces problem?