Incorrect results when simulating multiple bodies

Post Reply
tgreif
Posts: 4
Joined: Mon May 27, 2019 9:51 am

Incorrect results when simulating multiple bodies

Post by tgreif »

Hello,

I'm a new Bullet user and have started using Bullet to simulate a mechanical system consisting of a vibrating bowl and smaller parts that move in this bowl. I use the GImpact collision algorithm since I load stl files that contain a triangular mesh, and the bodies are usually quite complex in shape. My problem is that the bodies stop moving if multiple bodies are present, but the part moves fine if only a single body is placed in the vibrating bowl (It is is supposed to slowly move along the rivets). Does anyone know what the problem might be?

Here are some code snippets that show how I use Bullet. Initialization:

GL.btCollision = new btDefaultCollisionConfiguration();
GL.btDispatcher = new btCollisionDispatcher(GL.btCollision);
GL.btInterface = new btDbvtBroadphase();
GL.btSolver = new btSequentialImpulseConstraintSolver;
GL.btDynamicsWorld = new btDiscreteDynamicsWorld(GL.btDispatcher, GL.btInterface, GL.btSolver, GL.btCollision);
GL.btDynamicsWorld->setGravity(btVector3(GL.gravVec[0], GL.gravVec[1], GL.gravVec[2]));
btGImpactCollisionAlgorithm::registerAlgorithm(GL.btDispatcher);

Adding a body:

btTransform btTrans;

btTrans.setIdentity();
btTrans.setOrigin(btVector3(x, y, z));

btScalar btMass = mass;
btVector3 inertia(0., 0., 0.);

btShape->calculateLocalInertia(btMass, inertia);

btDefaultMotionState* myMotionState = new btDefaultMotionState(btTrans);
btRigidBody::btRigidBodyConstructionInfo rbInfo(btMass, myMotionState, btShape, inertia);
btRigidBody* body = new btRigidBody(rbInfo);

body->setRestitution(P.restitution[P.num]);
body->setFriction(P.friction[P.num]);
body->forceActivationState(DISABLE_DEACTIVATION);

GL.btDynamicsWorld->addRigidBody(body);


Doing a Bullet step:

GL.btDynamicsWorld->stepSimulation(dt, 10);


Please let me know if you need any additional information. I've attached movies of both cases. I'm pretty desperate at this point and would appreciate any help!

Thank you,

Thomas
Attachments
test1.mp4.tar.gz
(3.04 MiB) Downloaded 250 times
test.mp4.tar.gz
(746.13 KiB) Downloaded 260 times
steven
Posts: 83
Joined: Mon Nov 05, 2018 8:16 am
Location: China

Re: Incorrect results when simulating multiple bodies

Post by steven »

Could you attach your stl files and code snippet of how did you create your world? i want to reproduce it and then debug it to find the root cause.
thanks!
tgreif
Posts: 4
Joined: Mon May 27, 2019 9:51 am

Re: Incorrect results when simulating multiple bodies

Post by tgreif »

The movies are attached in the original message. I've attached the stl files of the relevant bodies.The code of how I create the world is also in the original message as far as I know. Let me know if something is missing. Thanks for your help!
Attachments
stl_files.tar.gz
(89.77 KiB) Downloaded 238 times
steven
Posts: 83
Joined: Mon Nov 05, 2018 8:16 am
Location: China

Re: Incorrect results when simulating multiple bodies

Post by steven »

Could you tell me the initial postion of these two meshes, as well as some parameters, such as the initial velocity, friction, mass or other values? thanks.
tgreif
Posts: 4
Joined: Mon May 27, 2019 9:51 am

Re: Incorrect results when simulating multiple bodies

Post by tgreif »

The initial position of the bowl is at the origin, and that of the part is at (7, 2, 0). The restitution is zero and the friction is 1. The initial velocities are zero, but I modify the position of the bowl, which is a kinematic body, using two sine functions:


btCollisionObject* obj = GL.btDynamicsWorld->getCollisionObjectArray();

btRigidBody* body = btRigidBody::upcast(obj);

btTransform btTrans;

int flag = 0;

btTrans.setIdentity();

if(P.vibLinAxis[0] || P.vibLinAxis[1] || P.vibLinAxis[2])
flag = 1;

btQuaternion quat, quat1;

if(flag)
{
float x = P.posSave[0] + P.vibLinAxis[0] * sin(2 * M_PI * P.vibLinFreq * GL.time);
float y = P.posSave[1] + P.vibLinAxis[1] * sin(2 * M_PI * P.vibLinFreq * GL.time);
float z = P.posSave[i][2] + P.vibLinAxis[i][2] * sin(2 * M_PI * P.vibLinFreq[i] * GL.time);

btTrans.setOrigin(btVector3(btScalar(x), btScalar(y), btScalar(z)));
}

// Do initial rotation
if(flag || P.vibRotAmpl[i])
{
btScalar btAngleX = GL.degFac * P.anglesSave[i][0];
btScalar btAngleY = GL.degFac * P.anglesSave[i][1];
btScalar btAngleZ = GL.degFac * P.anglesSave[i][2];

quat1.setEulerZYX(btAngleZ, btAngleY, btAngleX);

quat = quat1;
}

// Compute vibrational rotation
if(P.vibRotAmpl[i])
{
btVector3 btAxis(P.vibRotAxis[i][0], P.vibRotAxis[i][1], P.vibRotAxis[i][2]);

float angle = P.vibRotAmpl[i] * sin(2 * M_PI * P.vibRotFreq[i] * GL.time);

btScalar btAngle = GL.degFac * angle;

btQuaternion quat2(btAxis, btAngle);

quat = quat2 * quat1;
}

if(flag || P.vibRotAmpl[i])
{
// Do total rotation;
btTrans.setRotation(quat);

body->setWorldTransform(btTrans);
body->getMotionState()->setWorldTransform(btTrans);
}
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Incorrect results when simulating multiple bodies

Post by drleviathan »

You say the objects stop moving. Perhaps they are being deactivated by the simulation?

One thing to try: flag the objects to never deactivate:

Code: Select all

body->setActivationState(DISABLE_DEACTIVATION)
If the objects never stop moving then that is your problem: object deactivation because the objects aren't moving fast enough for the deactivation thresholds. AND, if that is your problem: instead of disabling deactivation altogether you can set lower deactivation thresholds on a per-object basis:

Code: Select all

body->setSleepingThresholds(minLinearSpeed, minAngularSpeed);
steven
Posts: 83
Joined: Mon Nov 05, 2018 8:16 am
Location: China

Re: Incorrect results when simulating multiple bodies

Post by steven »

hi tgreif,
sorry, it is hard for me to reproduce your issue. hope next time i can help you. good luck!
tgreif
Posts: 4
Joined: Mon May 27, 2019 9:51 am

Re: Incorrect results when simulating multiple bodies

Post by tgreif »

drleviathan wrote: Tue May 28, 2019 4:33 pm You say the objects stop moving. Perhaps they are being deactivated by the simulation?

One thing to try: flag the objects to never deactivate:

Code: Select all

body->setActivationState(DISABLE_DEACTIVATION)
If the objects never stop moving then that is your problem: object deactivation because the objects aren't moving fast enough for the deactivation thresholds. AND, if that is your problem: instead of disabling deactivation altogether you can set lower deactivation thresholds on a per-object basis:

Code: Select all

body->setSleepingThresholds(minLinearSpeed, minAngularSpeed);
Thanks for the suggestion, but I already disabled the deactivation. Any other ideas?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Incorrect results when simulating multiple bodies

Post by drleviathan »

Thanks for the suggestion, but I already disabled the deactivation. Any other ideas?
Ah yes, so you did.

And I realize now: I should have actually watched your videos. It isn't that the objects stop outright, but that they sorta bounce around in place instead of advancing along the path.

Your vibrating bowl... is it dynamic with the vibration driven by some external code slamming the transform + velocity? Or is it kinematic? If the former then maybe I could see how a large collection of smaller pieces might change the simulation, but if it is kinematic (e.g. its mass is effectively infinite compared to the smaller parts) then it would be even more puzzling.

Just curious: what is your substep duration and are you using single or double precision?
Post Reply