[SOLVED] issue with dcustomHinge

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: issue with dcustomHinge

Postby Julio Jerez » Wed Nov 25, 2020 7:25 am

That's the ideas of the mass independent spring damper.
Use the new function.
Code: Select all
   hinge->SetasSpringDamper(true, 10.f, 1.f);

Remember the this funtion does not uses a fix regularizer, instead it uses the timestep and the mass ratio to calculate a regularizer that correlates to the denominator of the implicit integration of a spring damper step.

Also notice the the spring is not a function of the mass, it is funtion of the inertia along the shared axis.
The torque actin on the small box is variable because the distance to the axis is small and become even smaller as the body deflects. So the total effect is quite small.

But if you detach the object from the world and they fall free, the the effect should be more pronounced with the mass dependent spring damper. This is because gravity act equally on both wing of the hinge and cancel out leaving only the spring/damper acting on them.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby blackbird_dream » Wed Nov 25, 2020 8:43 am

I'd like to model a hinge joint with a rotational spring in it.
it appears that both of the function SetasSpringDamper and SetMassIndependentSpringDamper do not simulate it correctly:
increasing the mass of the child body (considering, for sake of simplicity, the parent clamped) increases the force transmitted to the parent, due to gravity as you wrote. Then higher force in the spring must induce a larger angular deflection.
Unfortnately I was not able to observe it using SetMassIndependentSpringDamper nor SetasSpringDamper either.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: issue with dcustomHinge

Postby blackbird_dream » Wed Nov 25, 2020 8:58 am

when you say
detach the object from the world
it means set a non-null mass to the parent body or change the body type from adtStatic to adtDynamic ?
Yes when I do this the joint reacts differently depending on the mass of the childbody, using SetasSpringDamper. I must test in various conditions
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: issue with dcustomHinge

Postby Julio Jerez » Wed Nov 25, 2020 9:26 am

blackbird_dream wrote:Yes when I do this the joint reacts differently depending on the mass of the childbody, using SetasSpringDamper. I must test in various conditions

Yes thats what is expected.

The small body will not generate a significant deflection because not mater how big the mass is the fact that the distance from the center of mass to the axis of rotation is very small and the same, plus the moment of inertia is also very small causes variation of the external torque to be negligible compare to the spring torque, so you get the sum of two very small value one of which changes very little.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby Julio Jerez » Wed Nov 25, 2020 9:35 am

If you want to test the effect of both methods you can override the inertia of the body by using the funrion set mass matrix to set an moment of inertia that will be on some range that is in the same scale of the spring damper reaction torque.

That may show the difference better.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby blackbird_dream » Wed Nov 25, 2020 10:56 am

The small body will not generate a significant deflection because not mater how big the mass is the fact that the distance from the center of mass to the axis of rotation is very small and the same, plus the moment of inertia is also very small causes variation of the external torque to be negligible compare to the spring torque, so you get the sum of two very small value one of which changes very little.

Yes but in my try I observed the opposite http://newtondynamics.com/forum/viewtopic.php?f=9&t=9694#p65922 the mass are very small and the deflection is unexpectedly high.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: issue with dcustomHinge

Postby Julio Jerez » Wed Nov 25, 2020 11:25 am

well to me, opposite means the body with smaller mass deflect more.

again, the effect of the geometry makes the effect of the mass almost zero. One more time.
the free body diagram of the the torque of the small box is

Code: Select all
Ixx * a = Text + Tspring

a = invIxx * (Text + Tspring)

Ixx is a very small value because of the characteristic for the geometry, so what we get is a stiff system where a large value multiply a very small value. Because invIxx is a large value.

Tspring = -k * x - c * v

in the example K and C are not function of the inerta and K is large, this value change very fast.
Text is the external torque which is the gravity time the distance to the axis time sin of the angle.

Code: Select all
Text = g * d * sin(angle)

this is a very small value compared to Tspring

so in the end you get

Text + Tstring = g * d * sin(angle) - k * x - c * v

Text + Tstring = smallValue + largeValue

where the small value change is not enough to modify the overall effect of the spring.

I mentioned few ways to test this by changing some parameters. The easiest one I can think off is make the distance larger do that it has a larger influence.

I changed the small box size to this
//dVector size(0.4f, 0.25f, 0.75f, 0.0f);
dVector size(0.4f, 0.25f, 1.5f, 0.0f);

and you can clearly see the box with large mass deflect more. and also has lower oscillation frequency.
There are also other ways, to do teh same.
-setting the inerta arbitrarily
-Calculation K and C taking into account the Inertia of the bodies.

I committed the test with the large box,
Sync and check it out
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby blackbird_dream » Thu Nov 26, 2020 5:54 am

x and v are angle and angular velocity aren't they ?not disp and linear vel ?
is it consistent Tstring with Text? I guess kx-cv is consistent with force, not Tstring. Would say Text=m*g * d * sin(angle)
you say K is large, ok. K change very fast: is it not constant ?
K is large but x is the position relative to the free position of the spring (no load and assuming x an angle), so x can be low enough to counterbalance K and balance Text, meaning that the position is close to the free position of the spring. That should be consistent ?
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: issue with dcustomHinge

Postby Julio Jerez » Thu Nov 26, 2020 8:14 am

X and v are angular angle and angular velocity.
When you apply invIxx to the part in patentesis
Text becomes g * d * sin(angle)
The mass in not a factor only the distance remains.
But when appling to the spring damper, invIxx * k is just another k. Because the are both const.
The you get one value small value changing with the sin of the angle and the other with the angle.

It is eassy to get that formula from a Lagrange derivation.

If k is large the k*x changes very fast compared to g*d because d is a small constant.

This is a really common trick used in mechanical design, if you want to nullify a torque, just place the pivot close to the center of mass of the rotaing body.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby blackbird_dream » Thu Nov 26, 2020 9:22 am

the lagrangian derivative should lead to the angular momentum theorem ? Whose formulation is here Ixx * a = Text + Tspring I agree with this.
Text and Tspring are torques. They should have same units as you sum up the 2 quantities
Tspring has the dimension of a torque.
Not Text.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: issue with dcustomHinge

Postby Julio Jerez » Thu Nov 26, 2020 9:48 am

If you agree with the first expression, the what follows is the calculation of the two term in the sum.

One is function of mass, distance to the pivot, and sin of the angle. The other is just a large const multiplied by the angle.
Since the com is close to the pivot, the first term has very little influence over the second.

I showed in the demo that if you just move the center of mass away from the pivot, then the mass has more influence.

I do not know how else I can explain this. Is quite straight forward. A force close to a pivot, does not generate strong torque.

Try replacing the gravity with a constant torque in the force and torque call back, then it will act as a linear spring damper.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby blackbird_dream » Thu Nov 26, 2020 11:58 am

I agree with the 1st expression but I'm not pleased with :
Text is the external torque which is the gravity time the distance to the axis time sin of the angle.

because in my opinion the ext torque is the gravity time the lever arm time the mass. unit should be N.m
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: issue with dcustomHinge

Postby Julio Jerez » Thu Nov 26, 2020 1:49 pm

Either way is the same.

I explained both ways, if you leave the sum as torque the it is

G * m * d * sin(angle)

If you apply the inv of the inertia the is just
G * d * sin(angle) time some scaling factor of the inertia of the shape form.

In both cases the torque, or the angular acceleration is determined by the distance from the center of mass to the pivot.
Since is that distance is the one that make that quality small. Then as long as the pivot is closed to the com, the massnullified.

All I am saying you can not expect the system behave like a linear spring damper because the angular acceleration generated by the gravity is not linear and has very small influence over the spring.

I believe it is working as I expect it would.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby Julio Jerez » Thu Dec 03, 2020 2:59 pm

oh Blackbird, I apologize, there is still a bug in the modification I made to the joint.
this is the expression to calculate the acceleration one time step ahead of a spring damper.
f = [- k * (x2 - x1) - c * (v2 - v1) - dt * k * (v2 - v1)] / [m + dt * c + dt * dt * k]

this is the expression for calculating the force of one constrain row.

*jm^1jt + b(jm^1j)) f = aext + extforce * jm^1 + somePenatry

if we make jm^1j = invM

the equation become

(invM * b * invM) f = aext + extforce * jm^1 + somePenatry

now those two equations are linear equations on f. I will highlight both
1) f = [- k * (x2 - x1) - c * (v2 - v1) - dt * k * (v2 - v1)] / [m + dt * c + dt * dt * k]
(2) (invM + b * invM) f = aext + extforce * jm^1 + somePenatry


We I can adjust the coefficients so that they produce the same result we can get equation two to calculate a spring force.

The method that is in 3.14 now works as follows.

I set the penalty term in equation 2 to the entire value of on the right side of expression 1.
and I have the user passing an arbitrary regularizer b on the left size of equation 2.

this generates a mass independent spring damper force because the value on the right does not depend of the masses of the bodies, as long as k, c and t dominate m. and b is an arbitration regularizer if teh diagonal of teh mass matrix.

to get a mass dependent spring damper we can do this
let b = m + dt * c + dt * dt * k
and the penalty on the right be a = - k * (x2 - x1) - c * (v2 - v1) - dt * k * (v2 - v1)

we can factor m from b to get
1 + (dt * c + dt * dt * k)/m

now when we replace b with his in equation 2. k, c and t modify the diagonal of the mass matrix according. The bug was that after I made the fix, I did not divided the regularizer dt * c + dt * dt * k by m. so it produced some effect but not enough to see without ambiguity.

I just discovered the mistake when trying to add the springs functionality to newton 4.0.

notice that if (dt *c + dt * dt * k)/m is larger or comparable 1.0
the effect is stable but not longer accurate.

this is a behavior that is typical of implicitly integration because by definition, implicit integration method use the derivative of the function either one step ahead or one step behind. so they are accurate only as long as the time step is small enough to reduce the stiffness of the system.

so if k, c, or dt combine to make (dt * c + dt * dt * k)/m close to 1.0 the result diverge from accurate.

I will make the correction later.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: issue with dcustomHinge

Postby blackbird_dream » Thu Dec 03, 2020 3:53 pm

Many thks.
brilliant as usual.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 21 guests

cron