dCustomBallAndSocket joint gaining lots of energy

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

dCustomBallAndSocket joint gaining lots of energy

Postby Sweenie » Tue Nov 14, 2017 7:33 pm

Hi.

Not sure if this happens because of numerical integration errors or if it's an actual bug but when I create a simple dCustomBallAndSocket joint and the set the linear and angular damping of the body to 0 and give the body a little push the body is quickly gaining extra energy and finally explode.

Easily recreated in the sandbox by modifying this function in standardjoints.cpp

Code: Select all
static void AddDistance (DemoEntityManager* const scene, const dVector& origin)
{
   dVector size (1.0f, 1.0f, 1.0f);
   NewtonBody* const box0 = CreateBox(scene, origin + dVector (0.0f, 6.0f + size.m_y + 0.25f, 0.0f, 0.0f), size.Scale (0.2f));
   NewtonBody* const box1 = CreateCapule (scene, origin + dVector (0.0f, 6.0f, 0.0f, 0.0f), size);
   //NewtonBody* const box2 = CreateCapule (scene, origin + dVector (0.0f, 6.0f - size.m_y * 4.0f, 0.0f, 0.0f), size);

   dMatrix pinMatrix (dGrammSchmidt (dVector (0.0f, -1.0f, 0.0f, 0.0f)));
   NewtonBodySetMassMatrix(box0, 0.0f, 0.0f, 0.0f, 0.0f);
   

   // connect first box to the world
   dMatrix matrix0;
   NewtonBodyGetMatrix (box1, &matrix0[0][0]);
   pinMatrix.m_posit = matrix0.m_posit + dVector (0.0f, size.m_y, 0.0f, 0.0f);
   new dCustomBallAndSocket (pinMatrix, box1, box0);

   dVector damp(0.0f);
   NewtonBodySetLinearDamping(box1, 0);
   NewtonBodySetAngularDamping(box1, &damp[0]);

   //// link the two boxes with a distance joint
   //dMatrix matrix1;
   //NewtonBodyGetMatrix (box2, &matrix1[0][0]);

   //// get the origins
   //dVector pivot0 (matrix0.m_posit - dVector (0.0f, size.m_y, 0.0f, 0.0f));
   //dVector pivot1 (matrix1.m_posit + dVector (0.0f, size.m_y, 0.0f, 0.0f));

   //// connect bodies at a corner
   //new dCustomPointToPoint (pivot1, pivot0, box2, box1);
}
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: dCustomBallAndSocket joint gaining lots of energy

Postby Julio Jerez » Tue Nov 14, 2017 8:13 pm

maybe the new solver changes.
in file ..\sdk\dgPhysics\dgWorldDynamicsSimpleSolver.cpp line 47
\dgPhysics\dgWorldDynamicsSimpleSolver.cpp

line 1043 and 1203 try uncomment the new solver and use the old one.
I expect this to solve it but we still be to use the new solver.
let us see what happens first.

that's actually a good test case.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomBallAndSocket joint gaining lots of energy

Postby Sweenie » Wed Nov 15, 2017 3:58 am

Uhm, I assume you meant dgWorldDynamicsSimpleSolver.cpp in the standard Newton source and not in PEEL.

I changed to the 3.13 solver but unfortunately that didn't make any difference.

[EDIT]
For info, i just tried reverting to commit abf4e74 from Oct 23 (Merge branch 'master' of https://github.com/MADEAPPS/newton-dynamics) and in that version the body isn't gaining extra energy so at least we know it happened somewhere on or after Oct 23.

Works fine also with commit 90f0e17 (start optimizing single joint solver) from Nov 6.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: dCustomBallAndSocket joint gaining lots of energy

Postby Julio Jerez » Wed Nov 15, 2017 9:33 am

yes I mean \dgPhysics\dgWorldDynamicsSimpleSolver.cpp

I am testing the performance of the new solve in the Peel demos, I am going to upload the next integration as I promised over the Leadwerk forum to Pierre.

On the joint gaining energy now I see the problem, this is the optimization that I made that single joints should not use RK4 instead simple Euler, if I am right now we can see the huge difference that the integration method makes.

let us do this to test this hypothesis.
in file ..\sdk\dgPhysics\dgWorldDynamicsSimpleSolver.cpp line 47

make this change
//CalculateSingleClusterReactionForces(cluster, threadID, timestep);
CalculateClusterReactionForces(cluster, threadID, timestep);

if this work we than can make the an option for the joints, in one of two ways.
1-a flag in the joint itself that select RK4 or Euler
2-setting the joint stifness (this was does in 1.xx but I neve like it, but now I see it has some merit)
3-leave the way it was using RK4.
pmay a combination of 1 and 2 but let us try and see if this is the problem
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomBallAndSocket joint gaining lots of energy

Postby Sweenie » Wed Nov 15, 2017 12:21 pm

Yep, that solved the problem :)
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: dCustomBallAndSocket joint gaining lots of energy

Postby Julio Jerez » Wed Nov 15, 2017 2:52 pm

Ha cool now we know what it is, all we nee to do is to add the option.
I believe I can fix it, I look at the bug and I believe the problem is this.

the engine was using a RK4 for all island integration, there are literally dozen of RK method of numeral integration, each one claiming more accuracy that the predecessor.
https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods

most claim extreme high order bound like ridicules E(dt^6)
It has been about 20 year since I deal with the stuff I particularly think the starndart
RK4 is an error bound E(dt^5) which is extremely accurate.
Since I am using a variant that is not optimal, I suppose our is somewhere between E(dt^4) and
O(dt^5) which is also quite good.

here is the problem that I found. We know island goes trough RK4, but single bodies do not,
for the I wrote a predictor corrector integrator, which is an adaptive error bound integrator.

but now if a joint system is a single joint, since is no using RK4, the integration is plain Euler which is E(dt^2) error bound.
so what I can do is that these weekend I can adapt the predictor current integration to integrate single joints.

The reason I put so much emphasis on this is because many simulation and Game there are lot of single joint object. Thing like Doors, Lamp, drawer, single body collision, and so on make the larger majority of object in scene. so using RK4 is an over kill when we know the error is no that large.

The important point is that we know what the malfunction is and there are many way to fix it.

for now I will leave it the way it is until I fix next Saturday.
Thank for the Report.

I am getting ready for the final release, so I am try to cover all these lose ends.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 4 guests

cron