A SERIOUS SURGICAL simulation!

Share with us how are you using the powerrrr of the force

Moderator: Alain

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Wed Feb 26, 2020 2:28 pm

Oh, I see you were no going to be able to do it because I did no realiced the spring damper functionality of the ball socket joint is disabled.
Code: Select all
void dCustomBallAndSocket::SetTwistSpringDamper(bool state, dFloat springDamperRelaxation, dFloat spring, dFloat damper)
{
//   m_spring = spring;
//   m_damper = damper;
   m_options.m_option1 = state;
//   m_springDamperRelaxation = dClamp(springDamperRelaxation, dFloat(0.0f), dFloat(0.999f));
}


it was in some version but at some point I decided to remove all the flavors of that joint and made a unified one that can can be customized by setting parameters.
Is not a big deal, I this is a good test case to add the functionality now.

I will add that today and then test with your case problem.
sorry about that, my mistake.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Wed Feb 26, 2020 8:55 pm

Julio Jerez wrote:Oh, I see you were no going to be able to do it because I did no realiced the spring damper functionality of the ball socket joint is disabled.
Code: Select all
void dCustomBallAndSocket::SetTwistSpringDamper(bool state, dFloat springDamperRelaxation, dFloat spring, dFloat damper)
{
//   m_spring = spring;
//   m_damper = damper;
   m_options.m_option1 = state;
//   m_springDamperRelaxation = dClamp(springDamperRelaxation, dFloat(0.0f), dFloat(0.999f));
}


it was in some version but at some point I decided to remove all the flavors of that joint and made a unified one that can can be customized by setting parameters.
Is not a big deal, I this is a good test case to add the functionality now.

I will add that today and then test with your case problem.
sorry about that, my mistake.


That's all right, digging the code could be helpful later on. :D
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Sat Feb 29, 2020 3:33 pm

ok I added some tweaks to the demo, see if this is close to what you want.

remember the motion in the demo are exagerated, is possible to stall the pipe what violent motion,
my guess is that a medical device is not design to do that kind of motion.
tell what you think, and if you need some more tweaks, as I do not really know and do not want to know the details of this kind of simulations.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Sun Mar 01, 2020 9:11 am

Julio Jerez wrote:ok I added some teaks to the demo, see if this is close to what you want.

remember the motion in eh demo are exaggerated, is possible to stall the pipe what violent motion,
my guess is that a medical device is no design to do that kind of motion.

tell what you think, and if you need some more tweaks, as I do not really know and do not want to know the details of this kind of simulations..


Thanks! I will play around with it! :D
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Mon Mar 02, 2020 3:29 am

Hi Julio, I find a bug if it is in the Unity Plugin of Newton. The bug is:

When the "Time.deltaTime" is very small, say 0.005, the bodies of the rod will get infinite positions.
But when set a bigger value say 0.02 instead of the Time.deltaTime, everything goes fine.
The "Time.deltaTime": https://drive.google.com/open?id=1YvQWe ... QTM5Z2GV0N

I have gone through the code and it seems that the "Time.deltaTime" should not have an effect on the physics. I debugged the code and finally i could only get this and had no clue about it:
https://drive.google.com/open?id=1EJZYT ... xrIptyPK37
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Mon Mar 02, 2020 8:15 am

In general smaller time step yeild better simulation.
No sure why you are getting an infinite value, my guess there is a divide by zero in a joint callback.

The two joints use in the demo has are subclassed from a base joint, make sure there is not a divide by zero in the function submitconstraint.

Few think you can try.
Are you using continue collision, if so disable it.

Instead of passing a very small time step, try using the set substep functionality.
For engine like unity this is a huge saving because save the number of transform updates, which is where most the time is spend.

I will check the plug in to see if the is exposed to the unity inerface.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Mon Mar 02, 2020 9:51 am

Julio Jerez wrote:ok I added some tweaks to the demo, see if this is close to what you want.

remember the motion in the demo are exagerated, is possible to stall the pipe what violent motion,
my guess is that a medical device is not design to do that kind of motion.
tell what you think, and if you need some more tweaks, as I do not really know and do not want to know the details of this kind of simulations.


I have played the demo, it seems the same as before except the smaller friction. And how should i use the spring and damper of the dCustomBallAndSocket class cause I find no reference of the "m_coneSpring" and "m_coneDamper" except the function to set value to them?
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Mon Mar 02, 2020 10:46 am

I did not do the spring damper, because I realized it will not work as I thought it would.
the joint you need to look at is dFlexyPipeSpinner, it is different that the plain ballsokect.
the ball socket has one twist axis shared by both bodies, and this is why causes problem, what is need it is that the each body spins along its own twist axis.
joint dFlexyPipeSpinner implement that, but for that to work since the joint coordinate system is not longer orthonormal, the cone has to be relaxed a lot. so I set it to about 60% and that seem to achieve the effect.

the friction reduction is to make it easy to spin in place, the default friction is too high and offer a lot of resistance to rotation. is not really need it, I added to see it rotation in place.

you need to implement joint dFlexyPipeSpinner in the plugin.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Mon Mar 02, 2020 8:51 pm

Julio Jerez wrote:I did not do the spring damper, because I realized it will not work as I thought it would.
the joint you need to look at is dFlexyPipeSpinner, it is different that the plain ballsokect.
the ball socket has one twist axis shared by both bodies, and this is why causes problem, what is need it is that the each body spins along its own twist axis.
joint dFlexyPipeSpinner implement that, but for that to work since the joint coordinate system is not longer orthonormal, the cone has to be relaxed a lot. so I set it to about 60% and that seem to achieve the effect.

the friction reduction is to make it easy to spin in place, the default friction is too high and offer a lot of resistance to rotation. is not really need it, I added to see it rotation in place.

you need to implement joint dFlexyPipeSpinner in the plugin.


Sorry, my bad, there is the dFlexyPipeSpinner indeed. :)

And i have merged it into Unity, the simulation gets better. :D I will test the rod in finally environment with complex collision next ! Thanks!
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Tue Mar 03, 2020 3:39 pm

ah cool, you now have a start point, that you can build upon.
on the last thing about the update rate.
I cant check now if this is expose to the Unity interface. but you can added very easilly.

instead of calling the update with a small time step. you can set the number of sub steps of the simulation, is works like this:
Code: Select all
   // create the newton world
   m_world = NewtonCreate();
...
...

   // set the number of sub steps
   NewtonSetNumberOfSubsteps (m_world, MAX_PHYSICS_SUB_STEPS);
 


where MAX_PHYSICS_SUB_STEPS in a integer that subdivided the time step.
for example if the time step was

0.016 and MAX_PHYSICS_SUB_STEPS is set to 2
the the effective time step is 0.008.
if you set to 3 then the dt is 0.0053 which is about 180 tick per second.
for your case I would go for MAX_PHYSICS_SUB_STEPS = 4

the effect of this is a huge saving in call back between the graphics and the simulation update, specially on engine like unity in which callback between manage and native code really expensive delegate functions.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Tue Mar 03, 2020 9:17 pm

Julio Jerez wrote:the effect of this is a huge saving in call back between the graphics and the simulation update, specially on engine like unity in which callback between manage and native code really expensive delegate functions.


This is nice, i will have a try! And it is in the plugin already.
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Thu Mar 05, 2020 9:32 pm

Hi Julio,

One question about the compound collider : How can i get the sub-colliders' shapeID that are in contact? For now i can only get the shapeID of the compound collider itself from the collision callback.

Basically, i want use different materials of one compound collider, but the Unity Plugin doesn't support this for now, so i want use shapeID to distinguish the parts of one compound collider as the Newton Wiki says:
http://www.newtondynamics.com/wiki/index.php/ShapeID
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby JernejL » Fri Mar 06, 2020 2:47 am

Charles wrote:Hi Julio,

One question about the compound collider : How can i get the sub-colliders' shapeID that are in contact? For now i can only get the shapeID of the compound collider itself from the collision callback.

Basically, i want use different materials of one compound collider, but the Unity Plugin doesn't support this for now, so i want use shapeID to distinguish the parts of one compound collider as the Newton Wiki says:
http://www.newtondynamics.com/wiki/index.php/ShapeID


You can do and use this, yes:

In contact callback - do:

b1 := NewtonJointGetBody0(contact);
b2 := NewtonJointGetBody1(contact);

Then when looping thru contacts (NewtonContactJointGetContactCount, NewtonContactJointGetFirstContact, NewtonContactJointGetNextContact)

NewtonMaterialGetContactPositionAndNormal(material, nil, @ContactLocation, @ContactNormal);

Then you get the collision shapes of each body / or body compound via:

Collision_Primary:= NewtonMaterialGetBodyCollidingShape(material, b1);
Collision_Secondary := NewtonMaterialGetBodyCollidingShape(material, b2);

This logic doesn't need special checking if it's compound or not, it works regardless, then you can use NewtonCollisionGetUserData on the shapeid and so on..

I use this to build compound shapes, where particular parts do not collide (for example, a truck shape collides with everything, but rear part of truck does not collide with trailers so that they can be hooked up) - it works very well!
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Fri Mar 06, 2020 4:06 am

JernejL wrote:In contact callback - do:

b1 := NewtonJointGetBody0(contact);
b2 := NewtonJointGetBody1(contact);

Then when looping thru contacts (NewtonContactJointGetContactCount, NewtonContactJointGetFirstContact, NewtonContactJointGetNextContact)

NewtonMaterialGetContactPositionAndNormal(material, nil, @ContactLocation, @ContactNormal);

Then you get the collision shapes of each body / or body compound via:

Collision_Primary:= NewtonMaterialGetBodyCollidingShape(material, b1);
Collision_Secondary := NewtonMaterialGetBodyCollidingShape(material, b2);


Thanks , I have integrated it into Unity and it works well! :D
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby JernejL » Fri Mar 06, 2020 7:30 am

You're welcome, compound collisions are awesome 8)
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

PreviousNext

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 21 guests

cron