dCustomHinge spring problem[SOLVED]

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: dCustomHinge spring problem

Postby MeltingPlastic » Fri Feb 22, 2019 4:12 pm

I agree - when showing the debug geometry for the joint I don't see 180 degrees

Here is a demo with just the problem joint and body:
https://drive.google.com/open?id=1CHt_I ... lV0rOGrc-v

The program spits abunch of matrixes out from before the joint build and after the joint build.

specifically the joint is built using the global pin matrix (sorry for the formating):


-1 , 0 ,0 , 0
0 , 1 , 0 , 0
0 , 0 , -1 , 0
0 , 10 , 15 , 1

While the global Body matrix is:

0 ,0 , -1 , 0
0 , 1 , 0 , 0
1 , 0 , 0 , 0
0 , 10 , 10 , 1
Last edited by MeltingPlastic on Fri Feb 22, 2019 4:27 pm, edited 1 time in total.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby MeltingPlastic » Fri Feb 22, 2019 4:23 pm

Also Thanks Dave, I think I'm trying to do the same thing you are. I store local transforms in my code and at the end resolve to a global matrix.

I'll look at your code snippet

all my transforms should have no scale at all.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Dave Gravel » Fri Feb 22, 2019 4:29 pm

I get the object absolute matrix like this.
Code: Select all
function TOXNewtonObject.GetAbsoluteMatrix(): TMatrix;
begin
  if (mParent <> nil) then begin
    result := MatrixMultiply(mMatrix, mParent.GetAbsoluteMatrix());
  end else begin
    result := mMatrix;
  end;
end;


Edited:
Here a other exemple with the hinge and spring use in different axes.
https://www.youtube.com/watch?v=kP8Xh484VLM
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: dCustomHinge spring problem

Postby MeltingPlastic » Mon Feb 25, 2019 1:18 pm

I am setting the rigid body matrix's to be rotated in global space before I build the joint.

So one set of bodies is 90deg off from the other set.

All collision shapes are local to the rigid body. I never rotate those.

I did a test where I print out the relative (local) matrices of joint frame to body matrix, and they are identical in both rotations! Which is right! (Ive done this using Urho Transform functions and newton's GetMatrix0/1() functions - Both match up)

I also have verified the body matrices are indeed different at the time of joint formation. And I am not changing the body matrixes afterwards.

The rotated one still has Less springiness.

I've refactored and double checked alot - still cant find anything wrong.


The Code:
Code: Select all
            //URHO3D_LOGINFO("Relative Matrixes:");
            //PrintNewtonMatrix(UrhoToNewton(ownBody_->GetWorldTransform().Inverse() * GetOwnNewtonBuildWorldFrame()));
            //PrintNewtonMatrix(UrhoToNewton(otherBody_->GetWorldTransform().Inverse() * GetOtherNewtonBuildWorldFrame()));
            newtonJoint_ = new dCustomHinge(UrhoToNewton(GetOwnNewtonBuildWorldFrame()), UrhoToNewton(GetOtherNewtonBuildWorldFrame()), GetOwnNewtonBody(), GetOtherNewtonBody());

            URHO3D_LOGINFO("Relative Matrixes From Joint (GetMatrix0):");
            PrintNewtonMatrix(newtonJoint_->GetMatrix0());
            URHO3D_LOGINFO("Relative Matrixes From Joint (GetMatrix1):");
            PrintNewtonMatrix(newtonJoint_->GetMatrix1());

            URHO3D_LOGINFO("Body Matrixes (Own):");
            PrintNewtonMatrix(UrhoToNewton(ownBody_->GetWorldTransform()));
            URHO3D_LOGINFO("Body Matrixes (Other):");
            PrintNewtonMatrix(UrhoToNewton(otherBody_->GetWorldTransform()));


Generates the following output



90 DEGREE ROTATION:


[2019-02-25 09:12:02.759] [main] [info] Relative Matrixes From Joint (GetMatrix0):
[2019-02-25 09:12:02.759] [main] [info] 1.19209293103495e-07 , 1.19209289550781e-07 , 0.999999940395352 , 0
[2019-02-25 09:12:02.760] [main] [info] -0.99999988079071 , 5.96046447753906e-08 , 1.19209289550781e-07 , 0
[2019-02-25 09:12:02.760] [main] [info] -5.96046270118227e-08 , -0.999999940395355 , 1.19209285998067e-07 , 0
[2019-02-25 09:12:02.760] [main] [info] 0 , -0.5 , 0 , 1
[2019-02-25 09:12:02.760] [main] [info]
[2019-02-25 09:12:02.760] [main] [info] Relative Matrixes From Joint (GetMatrix1):
[2019-02-25 09:12:02.760] [main] [info] 1.19209293103495e-07 , 1.19209289550781e-07 , 0.999999940395352 , 0
[2019-02-25 09:12:02.760] [main] [info] -0.99999988079071 , 5.96046447753906e-08 , 1.19209289550781e-07 , 0
[2019-02-25 09:12:02.760] [main] [info] -5.96046270118227e-08 , -0.999999940395355 , 1.19209285998067e-07 , 0
[2019-02-25 09:12:02.760] [main] [info] 0.999999940395355 , 0 , -5.96046447753906e-08 , 1
[2019-02-25 09:12:02.760] [main] [info]
[2019-02-25 09:12:02.760] [main] [info] Body Matrixes (Own):
[2019-02-25 09:12:02.761] [main] [info] 5.96046447753906e-08 , 0 , -0.999999940395355 , 0
[2019-02-25 09:12:02.761] [main] [info] 0 , 1 , 0 , 0
[2019-02-25 09:12:02.761] [main] [info] 0.999999940395355 , 0 , 5.96046447753906e-08 , 0
[2019-02-25 09:12:02.761] [main] [info] 10 , 10 , 6 , 1
[2019-02-25 09:12:02.761] [main] [info]
[2019-02-25 09:12:02.761] [main] [info] Body Matrixes (Other):
[2019-02-25 09:12:02.762] [main] [info] 5.96046447753906e-08 , 0 , -0.999999940395355 , 0
[2019-02-25 09:12:02.762] [main] [info] 0 , 1 , 0 , 0
[2019-02-25 09:12:02.762] [main] [info] 0.999999940395355 , 0 , 5.96046447753906e-08 , 0
[2019-02-25 09:12:02.763] [main] [info] 10 , 9.5 , 7 , 1
[2019-02-25 09:12:02.763] [main] [info]


NORMAL ROTATION:


[2019-02-25 09:12:02.763] [main] [info] Relative Matrixes From Joint (GetMatrix0):
[2019-02-25 09:12:02.764] [main] [info] 2.38418579101563e-07 , 1.19209289550781e-07 , 0.99999988079071 , 0
[2019-02-25 09:12:02.764] [main] [info] -0.99999988079071 , 2.38418579101563e-07 , 1.19209289550781e-07 , 0
[2019-02-25 09:12:02.764] [main] [info] -1.19209289550781e-07 , -0.99999988079071 , 2.38418579101563e-07 , 0
[2019-02-25 09:12:02.764] [main] [info] 0 , -0.5 , 0 , 1
[2019-02-25 09:12:02.765] [main] [info]
[2019-02-25 09:12:02.765] [main] [info] Relative Matrixes From Joint (GetMatrix1):
[2019-02-25 09:12:02.766] [main] [info] 2.38418579101563e-07 , 1.19209289550781e-07 , 0.99999988079071 , 0
[2019-02-25 09:12:02.766] [main] [info] -0.99999988079071 , 2.38418579101563e-07 , 1.19209289550781e-07 , 0
[2019-02-25 09:12:02.766] [main] [info] -1.19209289550781e-07 , -0.99999988079071 , 2.38418579101563e-07 , 0
[2019-02-25 09:12:02.767] [main] [info] 1 , 0 , 0 , 1
[2019-02-25 09:12:02.767] [main] [info]
[2019-02-25 09:12:02.767] [main] [info] Body Matrixes (Own):
[2019-02-25 09:12:02.769] [main] [info] 1 , 0 , 0 , 0
[2019-02-25 09:12:02.770] [main] [info] 0 , 1 , 0 , 0
[2019-02-25 09:12:02.770] [main] [info] 0 , 0 , 1 , 0
[2019-02-25 09:12:02.770] [main] [info] 0 , 10 , 4 , 1
[2019-02-25 09:12:02.770] [main] [info]
[2019-02-25 09:12:02.771] [main] [info] Body Matrixes (Other):
[2019-02-25 09:12:02.771] [main] [info] 1 , 0 , 0 , 0
[2019-02-25 09:12:02.771] [main] [info] 0 , 1 , 0 , 0
[2019-02-25 09:12:02.772] [main] [info] 0 , 0 , 1 , 0
[2019-02-25 09:12:02.772] [main] [info] -1 , 9.5 , 4 , 1
[2019-02-25 09:12:02.772] [main] [info]


Other thing I cannot explain is that - if I save and reload - all the matrix's look identical but the joint will have more stiffness after the load.



Also I am on commit b0a4c809df479d86853d51028a66cadcc3d2b736 of newton.

Here is the debug-able program:
https://drive.google.com/open?id=1vhONE ... Dnv41zTd25
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Dave Gravel » Mon Feb 25, 2019 3:50 pm

Maybe it can become more simple for you to test directly inside newton sdk demo.
With a simple matrix setup inside the newton joint demo, You can see more what happen.

Here for setup my matrix I use this 3 tools + matrix multiplication.

dRollMatrix
dYawMatrix
dPitchMatrix
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: dCustomHinge spring problem [SOLVED]

Postby MeltingPlastic » Mon Feb 25, 2019 10:33 pm

Whew! I Got it. Turns out it was a problem in my rebuildBody() routine. I was setting the bodies mass matrix too soon in the process, resulting in a bad matrix or inertia matrix for the body thus I was seeing oscillations that were different across rotations. It seems to be solved now. Thanks guys for your help.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Julio Jerez » Tue Feb 26, 2019 8:33 am

Oh cool, glad this was resolved.
Last saturdat I was looking angain, and you were right the initialization matrices were right, everything on the onifi a Liz a room was correct, but aft e r the integration one matrix rotate on the opposite direction.
I run out of options, and did not know what else to do.
I knew the test on the demos were right, as they were Dave test, so was not that either,
I did not know what else to check.

But I am glad the is fix now.

Do you mean the bikes behave properly in both directions now?

If so try enable gyro torqued on both see is the make the stability better or worse.
Julio Jerez
Moderator
Moderator
 
Posts: 10994
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby MeltingPlastic » Tue Feb 26, 2019 1:58 pm

Yeah The Bikes are spawning in different directions now.

I did a little testing with and without gyro torque enabled.

It does behave a little different, with it enabled it seems to swerve back and forth more. On high speed runs there comes a point where it tried to correct for its lean. but of course it is so high speed that it flips at that point. without gyro it keeps its lean for much longer.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Julio Jerez » Tue Feb 26, 2019 4:47 pm

I expect to behave naturally more or less like this:
https://www.youtube.com/watch?v=Fy_XRVO-jl8

few thing:
1-are you using the chamfered cilider for shape.
2-are you using the inertia of the shape not the trick of making it spherical.
3-Gyro fore are highly unstable, the turn w x L W is extreme no linear you are advise to run the simulating with at a minimum 2 sub steps, I advise 4

3- eh inertial calculation assume a uniform density by in reality wheel are like balloons, the have most the mass on the outer ring so that the are very resilient to keep the angular momentum and that the trick of eth Gyro stability, you can make this with few trick, the ease is simply let the inertial calculate the value the read and scale by some factor, but the better trick is with arithmetic because inertia are additive, so you take two shape one the side for the wheel and one smaller, there calculate the interval each and subtract the smaller for the larger. this will give you the values for a hollow wheel, then that value you scale by some factor to make heavier.


A long time ago, some one was making a Bowling game and the want the ball to make the hook and that was reproduce by adding a cylinder inside the ball, the same way real balling ball are made, and to my surprise it worked.
Julio Jerez
Moderator
Moderator
 
Posts: 10994
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby Julio Jerez » Tue Feb 26, 2019 4:52 pm

Can you make a video of the behavior with gyro and without?
This with help to see how close is to simutation.
Very few people understand the physics of bikes, but its possible to do tricks on the air by them in the steering.
Julio Jerez
Moderator
Moderator
 
Posts: 10994
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby Julio Jerez » Tue Feb 26, 2019 5:14 pm

Swerving from side to side is a good that is on stable equilibrium.
Stable equilibrium is defined as local minimal point on a system where any small perturbation causes the total energy to encrease.
Think of a ball on top of a hill, it has a potential energy mgh, if you move a little it will go downhill. Since h became smaller, it loses energy and because there is a theorem called principle of least axiom, the ball move along the path that generates the maximum energy lost.
If for example that ball is on a valley and every motion causes the ball to goes up, that means is gain energy, but since it also gain velocity, it always goesback to a lower energy state. When the lost of potential energy is lower larger than the gain of kinetic energy the ball can get out of the state, which is what you are seeing.

The problem is that is a small window of stability, because the non linearity of the gyro torque.
But if you accept that ad a cost for a good simulation, you can run the simulation at more than one subset.

This is a tough sale, because you always find the fan of other engine that know nothing about dynamic and say engine B is faster.
I am not longer interested on those people opinion, they can use something else.

I only mention these thing to people who has pass the box stacking point and beging to understand a little more than running fast.
Julio Jerez
Moderator
Moderator
 
Posts: 10994
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby MeltingPlastic » Tue Feb 26, 2019 5:49 pm

The Wheels are not using the Sphere trick.

They are also not using the subtracted mass (intertia trick) from the center. I want to get this working with the Urho API so that you can give collision shapes "negative" density and the end result body will have a full inertia matrix that reflects the net density of all shapes.

The wheels are just normal chamfered cylinders.

all shapes you see have the same density.



I made a demo of the bike with and without gyro:

the bike on the right has gyro enabled for the wheels.
the bike on the left has no gyro enabled.

the back wheel is powered by a motor with small speed.

Its pretty Cool!
https://drive.google.com/open?id=1aP29c ... z542PFeK6w

Edit: The Bikes start off with a random tilt +- 1 degree
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Julio Jerez » Tue Feb 26, 2019 6:10 pm

I check out later, Here I found a video of toy bike with an exaggerate Gyro inside.
https://www.youtube.com/watch?v=3aZ2fhqX4gg

you can see the magic of what a Gyro can do.
That is what I would do if I have to make a Bike for fund.

there are also other variables that at part of what makes a Bike stand up, not just the Giro,
for example a Human drive is a big part, placing the fork is such way the when the while turn and lean, I list the center of mass.
https://www.youtube.com/watch?v=oZAc5t2lkvo

but in the accent of all those other variables, like a to bike, It is the Gyro that paly the most important role.
Julio Jerez
Moderator
Moderator
 
Posts: 10994
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby Julio Jerez » Wed Feb 27, 2019 1:35 am

Oh wow, this is quiet impressive. I love hwo teh bike of teh right, at the begging for the movement is gong to topple over, but as if going down the Gravity torque at on the entire body.
The Gravity torque is aliened with the bike longitudinal axis,

The Gyro Torque is at 90 degrees and almost aligned with the Bike front wheel fork,

This Toque act of the who body true to turn the Bike, by has almost no effect, because for of tire friction, however the front wheel can pivot of the fork and turn the direction that try to tur the bike even more and it is that effect that act as if there was a human driver trying to steer the Bike.
To me it is a remarkable effect. :D

here is a fun fact, Bikes can actually turn without turning the front tire by just leaning the body, in fact this trick is what professionals race bike driver do to make sharp turns a very high speed, No sure if you seeing them leaning way, way out in order to increase the gravity torque, so that the vertical torque on the entire body is strong enough that can turn the entire bike.
If instead they try to turn the wheel the front tire just slide on the ground an the just keep going straight turning very little.
isn't physics a cool thing when is work?

BTW the secund bike is cool too, but does not do the cool swivel like the one of the right which seem it about to fall but recovers. :D
Julio Jerez
Moderator
Moderator
 
Posts: 10994
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby Julio Jerez » Wed Feb 27, 2019 1:41 am

The next test you might want to try is, apply a little notch to the side of the bike and see if it recovers. This is a classic stability test, that is done in design to see if something is dynamically stable, what is show you that indeed there is a restoring torque that can recover from a perturbation up to some limit.
here is a video doing just that
https://www.youtube.com/watch?v=YmtPNIu4WI0

If is passes that test them from there you can figure out how to even drive like the two bike in the last video except that this will be more realistic, because it would not need the hidden counter heavy metal wheel spinning at high speed inside the body to make it more like a spinning top, more like a real bike.
Julio Jerez
Moderator
Moderator
 
Posts: 10994
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 2 guests