dCustomHinge spring problem[SOLVED]

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

dCustomHinge spring problem[SOLVED]

Postby MeltingPlastic » Tue Feb 19, 2019 8:37 pm

Hi Julio,

I am getting a bug I cant explain with the dCustomHinge. In my code I make 2 bikes, one that is facing in the world x direction and one that is facing in the negative world y direction.

one Bike has a back suspension that is springy, and the other does not. Every other aspect of the joint rotations seem to be working just the springiness is not consistent.

Here is a demo:
https://drive.google.com/open?id=1AmIMs ... CJspvdOp9P
Last edited by MeltingPlastic on Fri Mar 01, 2019 1:21 pm, edited 1 time in total.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Julio Jerez » Wed Feb 20, 2019 4:10 am

Are both bikes identical?
What happens if you place them with the same orientation?
Julio Jerez
Moderator
Moderator
 
Posts: 10988
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby Julio Jerez » Wed Feb 20, 2019 10:06 am

I just download the demo, and Is hard to see what happen,
can you do this, make the same test only with the problematic bike and the ground nothing else.

btw the bike driving straight look great, you can get it to go straight.

here is an experiment you can try,
when you make the wheel try this function NewtonBodySetGyroscopicTorque(gyroTop, 1);
and make the inertia proper, instead of spherical like the trick for a car.

I am not promise anythong but in theory the bike to stay string up as alon as the wheel are spinning.
you can check that out by runniong the demo GyroscopyPrecession
../demosSandbox\sdkDemos\demos\GyroscopyPrecession.cpp

look at the top, and the fly wheel see that opposite commonsense, they tend to do straight up as the wheel loses speed.

. If you have a hard time believing those results you can compare to some video for MIT of some other so that you can see the as the wheel loses speed it rises up, as long as the gyro torque is still stronger than the gravity torque trying to make it flop.
I made a video a while back showing com
https://www.youtube.com/watch?v=UlErvZoU7Q0

try that is the good bike and see if is gets better. This can be a good test to see if it is true, that bikes and bicycles are essensiall Gyro tops, I know is true, because that hwo bike toyes works, the manufactures of those toys actually cheat my make teh rear wheel of some metal so that is has stonger inertia, that why will have a high aligning torque at lower speed.
Julio Jerez
Moderator
Moderator
 
Posts: 10988
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby MeltingPlastic » Wed Feb 20, 2019 8:03 pm

Both Bikes are Identical - If you look close the one driving towards the camera at start has a suspension that droops, letting the rear end hit the top of the wheel.

The Bike driving to the right has a much stiffer suspension.

both bikes were created with the same parameters.

I'll try to get a simpler demo going.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby MeltingPlastic » Wed Feb 20, 2019 8:55 pm

Here is a simpler demo with 2 hinges at different orientations, you can see how one has springiness and the other doesn't event though they have the same parameters set:
https://drive.google.com/open?id=1h_Wez ... GHoN9WSZLM
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Dave Gravel » Wed Feb 20, 2019 9:25 pm

I don't have seen the demo and maybe i'm wrong.
I think you need to rotate the joint pin matrix.

If i'm not wrong the joint row is calculated with the pin matrix front row.
Maybe you need to rotate the pin matrix to get it in the good axe for get it working with the front row.

I remember to have already rewrite a joint with the possibility to choice the matrix row to use for calcul the joint row, but if i'm not wrong you can only rotate the pin matrix.
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 » Wed Feb 20, 2019 9:34 pm

I do set the pin and matrix for both bodies. The orientation of the hinge is rotating as expected.

I only use the constructor of the joint to set the reference frames.

Since the hinge is rotating fine it tells me there must be something with the spring portion of the joint code that is not respecting the orientation correctly.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Dave Gravel » Thu Feb 21, 2019 1:14 am

Here it is what I get with the hinge spring.
https://www.youtube.com/watch?v=K_MeDXhV6EE

I have already get a similar problem to your problem with the vehicle mesh + tire placement and rotation side.
This can place the spring in bad direction too, All of this is caused by the mesh barycenter, rotation, pos from the modeler and the matrix pin.

Here I have success to fix it with the pin matrix, In my very old vehicle code in the joint options I can change the joint matrix row for use the front right or up.

Now I don't have get the problem anymore with the vehicle, Now when I place correctly the mesh in blender I can setup all in the good axes and after I can rotate it in any direction.

This video reproduce the problem, Or you talk about a other thing ?
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 Julio Jerez » Thu Feb 21, 2019 11:20 am

I think Dave is right,
The joint that is wrong is the first one, when I traced the joint angles and these are the results.

for joint 0, the angle increase.
joint0 angle: -0.000000 -0.000000 0.000000
joint0 angle: 1.141428 0.000155 0.000011
joint0 angle: 2.291748 0.000166 0.000014

for joint 1 the correct one the angle decrease,
joint1 angle: -0.000000 -0.000000 0.000000
joint1 angle: -0.395129 -0.000051 0.000458
joint1 angle: -0.784298 -0.000052 0.000490

both angles should be decreasing so that the sprin correction is negation, and is stand for joint zero, the correction is action in the same direction of the angle error, making the joint deviate even more, this is why the angle increased fasters.

This indicate the bug is on the initializaion and I believe this is the case,
I traced the pin matrix and the rigid body matrix of the moving part.
for the correct body, these are the values
Code: Select all
joint 1 correct one
pinsAndPivotFrame
{m_x=3.5762786865234375e-07 m_y=0.00000000000000000 m_z=-0.99999994039535522 ...}
{m_x=0.00000000000000000 m_y=1.0000000000000000 m_z=0.00000000000000000 ...}
{m_x=0.99999994039535522 m_y=0.00000000000000000 m_z=3.5762786865234375e-07 ...}

matrix0
{m_x=1.0000000000000000 m_y=0.00000000000000000 m_z=0.00000000000000000 ...}
{m_x=0.00000000000000000 m_y=1.0000000000000000 m_z=0.00000000000000000 ...}
{m_x=0.00000000000000000 m_y=0.00000000000000000 m_z=1.0000000000000000 ...}


notice that the body has a identity matrix, and the joint axis is 90 degree around the y axis
for the secund hinge these are the values
Code: Select all
Joint 0 (the wrong one
matrix0   
{m_x=5.9604644775390625e-08 m_y=0.00000000000000000 m_z=0.99999994039535522 ...}
{m_x=0.00000000000000000 m_y=1.0000000000000000 m_z=0.00000000000000000 ...}
{m_x=-0.99999994039535522 m_y=0.00000000000000000 m_z=5.9604644775390625e-08 ...}

pinsAndPivotFrame   
{m_x=1.0000000000000000 m_y=0.00000000000000000 m_z=0.00000000000000000 ...}
{m_x=0.00000000000000000 m_y=1.0000000000000000 m_z=0.00000000000000000 ...}
{m_x=0.00000000000000000 m_y=0.00000000000000000 m_z=1.0000000000000000 ...}


as you can see the body still has a identity matrix, and the pin is now rotate -90 degree, which is right, but some how when you rotate the body, you are rotating the visual geometry, but you are leaving the rigid body matrix unchanged. not sure how you did that, maybe you are rotation the collision shape offset. by that is the problem,
you can undertand better is you look at the two bodies, and see then at 90 degrees relative to each other, by the transform matrix of both is identity.
Julio Jerez
Moderator
Moderator
 
Posts: 10988
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby MeltingPlastic » Thu Feb 21, 2019 2:07 pm

Thanks guys for the help!

Yeah something is up with my code, its a tough one.


my Api is "Deferring" calls to newton so for example the following Urho3D Code:
Code: Select all
void PhysicsTests::SpawnHingeSpringTest(const Vector3 worldPosition, const Quaternion worldOrientation)
{

    //Set up contraption in around 0,0,0 world space
    Node* baseNode = SpawnSamplePhysicsBox(scene_, Vector3::ZERO, Vector3(10,1,1));
    HingeConstraint* constraint = baseNode->CreateComponent<HingeConstraint>();
    constraint->SetOwnWorldPosition(Vector3(-5,0,0));
    constraint->SetOtherWorldPosition(worldPosition);
    constraint->SetNoPowerSpringDamper(true);

    constraint->SetOwnWorldRotation(Quaternion(90, Vector3(0, 1, 0)));//<--this rotation throws things off.

    //explicitly set world orientation of other frame because that wont be rotated by final move of whole contraption.
    constraint->SetOtherWorldRotation(worldOrientation);


    //finally move the whole contraption to desired location.
    baseNode->SetWorldPosition(worldPosition);
    baseNode->SetWorldRotation(worldOrientation);
}


Creates one hinge contraint and body like in the demo. However all this code happens without a call to newton. That happens on the next "frame" where everything is built based off of dirty flags.

So before newton is ever called the body transform is implicitly assumed to be the same as the baseNode's transform. And the 2 frames of the hinge contraint are stored as local frames relative to the baseNodes transform. Finally the last 2 lines rotate and move the baseNode to where it should actually be built.

Later newton actually builds the body with the final matrix (could be rotated - this is working) and then the contraints are built by converting from the stored local frames into world frames.

The line:

Code: Select all
   constraint->SetOwnWorldRotation(Quaternion(90, Vector3(0, 1, 0)));//<--this rotation throws things off.


seems to be the problem indicating something is wrong with my world->local->world transform logic..

if that line is not there then the joint is rotated just along with the body and the spring works -etc.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Julio Jerez » Thu Feb 21, 2019 3:10 pm

here is one clue the transform are incorrect.
if you look at my print out of the matrix use to crate the joint.
you will see that the first row which is the hinge pin are 180 degree for one another.
by they should be 90 degree, this is what the are.

pin for join0 { 0, 0, -1}
pin for join1 { 0, 0, 1}

by assuming y is the up direction they should be

pin for join0 { 0, 0, -1}
pin for join1 { 1, 0, 0}

because is a global space and it is what the visual indicate.
My guess is that your rigid bodies are parent form some node and you are using a local matrix in one case and a global on other.
I hope this help to figure it out.
Julio Jerez
Moderator
Moderator
 
Posts: 10988
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby MeltingPlastic » Fri Feb 22, 2019 3:48 pm

I am now looking at just the one rigid body with the rotation that is not working.



When I render the debug information to render both global frames I am using newtonJoint_->CalculateGlobalMatrix(mat0, mat1); and rendering directly from that. The debug information looks good! how is it possible then that the joint is formed wrong?

shouldn't it be that If I supply any global frame matrix to the joint and (as long as it wasn't sheared or inverted) a functional joint would be formed?

More specifically what kind of attributes would make a "bad" pinMatrix?
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: dCustomHinge spring problem

Postby Julio Jerez » Fri Feb 22, 2019 3:55 pm

Yes the matrix define the axis of rotation, and since in both cases the pin is along z, they both should be pinning along z axis, but visually they aren't.
In am at lost, because this is too simple to be such a significant bug.
Tomorrow I can recreate the same test in the sand box.
Julio Jerez
Moderator
Moderator
 
Posts: 10988
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

Postby Julio Jerez » Fri Feb 22, 2019 4:01 pm

Pin matrices are like normal transform matrices without scale.
My observation is that they are rotate by 180 degree, rather than by 90 as the visual say.
So it most be a problem how you are generation them.
I have seen weird bugs but never one that if true would mean a hell of a lot of stuff is wrong.
Julio Jerez
Moderator
Moderator
 
Posts: 10988
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomHinge spring problem

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

In my video I use the AbsoluteMatrix for setup the construction.
My joint have a self local matrix for the pin setup.
The joint local matrix is calculated by a dummy object AbsoluteMatrix.
After in the joint local matrix I can modify it for get any directions or add position offset.
My matrix don't use any scale at all, When I need scale I do it from a other method.

My joint and my object use the same calculation method.
In my code exemple the creation matrix is generate only when my object is create, Or if the body is rebuild or modified.
I use this matrix for reset the scene at the initial pos and rot...

Here is my system matrix calculation.
It's hard for me to explain all parts here, but maybe you can see more the difference with this part of code.

Code: Select all
procedure TOXRenderList.RenderChildren(ctx: PRenderContext; nobj: TOXNewtonObject; child: boolean; steptime: dFloat);
var nObj0: TOXNewtonObject;
    a: integer;
    newMatx0: TMatrix;
begin
  for a := 0 to nobj.mChildrens.Count - 1 do begin
    nObj0 := TOXNewtonObject(nobj.mChildrens.Objects[a]);
    nObj0.SetShader(mShader);
    if (nObj0.mDynamic = false) then begin
      if (nObj0.GetVisualOnly() = false) then
        newMatx0 := MatrixMultiply(nObj0.mMatrix, nobj.GetAbsoluteMatrix())
      else
        if nObj0.GetFollowPhysics() = false then
          newMatx0 := MatrixMultiply(nObj0.mCreationMatrix, nobj.GetCreationAbsoluteMatrix())
        else
          newMatx0 := MatrixMultiply(nObj0.mMatrix, nobj.mFinalAbsoluteMatrix);
    end else begin
      if (nObj0.mMass = 0.0) then begin
        NewtonBodyGetMatrix(nObj0.mBody, @newMatx0.V[0].V[0]);
      end else begin
        newMatx0 := nObj0.mMatrix;
      end;
    end;
    //
    nObj0.mFinalAbsoluteMatrix := newMatx0;
    //
    glUniformMatrix4fv(glGetUniformLocation(mShader, 'Model_Matrix'), 1, false, @newMatx0.V[0].V[0]);
    //
    nObj0.RenderGL(ctx, steptime);
    //
    if (nObj0.mChildrens.Count > 0) then
      RenderChildren(ctx, nObj0, true, steptime);
  end;
end;

procedure TOXRenderList.RenderGL(ctx: PRenderContext; steptime: dFLoat);
var i : integer;
    nObj : TOXNewtonObject;
    newMatx : TMatrix;
begin
  if (mShader = 0) then exit;
  //
  glUseProgram(mShader);
  //
  glUniformMatrix4fv(glGetUniformLocation(mShader, 'Projection_Matrix'), 1, false, @aProjMat.V[0].V[0]);
  glUniformMatrix4fv(glGetUniformLocation(mShader, 'View_Matrix'), 1, false, @aViewMat.V[0].V[0]);
  //
  // The last added in the list is the first rendered.
  for i := 0 to count -1 do begin
    nObj := TOXNewtonObject(Objects[i]);
    nObj.SetShader(mShader);
    if (nObj.mDynamic = false) then begin
      newMatx := nObj.GetAbsoluteMatrix();
    end else begin
      if (nObj.mMass = 0.0) then begin
        NewtonBodyGetMatrix(nObj.mBody, @newMatx.V[0].V[0]);
      end else begin
        newMatx := nObj.mMatrix;
      end;
    end;
    //
    nObj.mChildrens.SetShader(mShader);
    // Build the final matrix absolute to the parent.
    nObj.mFinalAbsoluteMatrix := newMatx;
    //
    glUniformMatrix4fv(glGetUniformLocation(mShader, 'Model_Matrix'), 1, false, @newMatx.V[0].V[0]);
    //
    nObj.RenderGL(ctx, steptime);
    //
    RenderChildren(ctx, nObj, false, steptime);
    //
  end;
  //
  glUseProgram(0);
  //
  //
  if (mListChanged = true) then begin
    UpdateEditorList;
    mListChanged := false;
  end;
end;
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.

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 1 guest