Kinematic Joint Problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Kinematic Joint Problem

Postby pHySiQuE » Wed Jun 07, 2017 1:58 pm

I replaced my picking-up-objects system with a kinematic joint. This works a lot better than trying to use AddForce/AddTorque to adjust the object's position.

However, I am getting some odd behavior with the Kinematic joint. When an object is picked up, a kinematic joint is created, and the target position and rotation is continually set. When the object is dropped, the kinematic joint is deleted.

In my demo, walk into the room on the right. Press E to pick up the crate sitting in the back of the pickup truck and move around to carry the crate. Drop the crate by pressing E again.

After the crate is dropped, it cannot be picked up again. It can still be pushed and shot to move it, but a new kinematic joint will have no effect on it.

Other times, such as in this video, it will freeze up on either the SetTargetPosition or SetTargetRotation commands.

Download
https://www.leadwerks.com/files/KinematicJoint.zip

Code
Code: Select all
   void NewtonDynamicsJoint::SetTargetPosition(const Vec3& pos, const float blend)
   {
      if (type == KINEMATIC)
      {
         dVector posf;
            posf.m_x = pos.x * blend + entity[0]->body->nextmat.t.x * (1.0f- blend);
            posf.m_y = pos.y * blend + entity[0]->body->nextmat.t.y * (1.0f - blend);
            posf.m_z = pos.z * blend + entity[0]->body->nextmat.t.z * (1.0f - blend);
            posf.m_w = 1.0f;
            ((dCustomKinematicController*)newtonuserjoint)->SetTargetPosit(posf);
      }
   }

   void NewtonDynamicsJoint::SetTargetRotation(const Quat& rotation, const float blend)
   {
      if (type == KINEMATIC)
      {
            dQuaternion rotf;
            Quat q = entity[0]->body->nextquat.Slerp(rotation, blend);
            q = q.Normalize();
            rotf.m_q0 = q.w;
            rotf.m_q1 = -q.x;
            rotf.m_q2 = -q.y;
            rotf.m_q3 = -q.z;
            ((dCustomKinematicController*)newtonuserjoint)->SetTargetRotation(rotf);
       }
   }


Video
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Kinematic Joint Problem

Postby Julio Jerez » Wed Jun 07, 2017 2:32 pm

are you deleting the joint from inside a newton update? that would be a problem.

also set a break point on like 86 file
../packages\dCustomJoints\dCustomJoint.cpp

and see if this function is called when you delete the joint.
NewtonDestroyJoint(m_world, m_joint);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic Joint Problem

Postby pHySiQuE » Wed Jun 07, 2017 2:53 pm

NewtonDestroyJoint is being called, consistently, at the right time.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Kinematic Joint Problem

Postby Julio Jerez » Thu Jun 08, 2017 9:07 am

the mouse is lock in exclusive mode.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic Joint Problem

Postby pHySiQuE » Thu Jun 08, 2017 4:25 pm

I updated the demo so the mouse can be unlocked by pressing escape. Same download link.
https://www.leadwerks.com/files/KinematicJoint.zip
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Kinematic Joint Problem

Postby Julio Jerez » Fri Jun 09, 2017 8:41 am

ok I see that there could be a problem there, but you should have seen this long before since there are many assert to alert of these situations. Are you commenting out the dgAssert? if you do that then you have people on your forum complaining about the physics because warning that are symptom of a misbehavior are not properly addressed.

anyway I have to do some check that I do not have time today, I will do this Saturday
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic Joint Problem

Postby pHySiQuE » Fri Jun 09, 2017 12:03 pm

I have dgassert disabled. There are too many random places in the code Newton can trigger a crash with no explanation.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Kinematic Joint Problem

Postby Julio Jerez » Sun Jun 11, 2017 12:12 am

ok, I believe I fixed. sync and see if it working for you?
after I determined what was wrong I fixed using the sandbox demos, but when I tested again in your demo, I was not able to pick the box at all, I see the joint been created and destroyed when I press the E key but the box does not move, I am guessing the friction force is too small.

anyway that fact that the assert do not trigger anymore plus that it is working on the sandbox tell me that it is fixed.

Please next time when you have a problem make sure you enabled the assert before you give me a test so that the problem is captured as soon as possible, that demo without sent me into a wild goose chase because by the time the bug happened, a lot of things that where not supposed to happen were already wrong, so I was debugging stuff that was not wrong and made no sense.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic Joint Problem

Postby pHySiQuE » Mon Jun 12, 2017 1:39 pm

I haven't been able to crash the program. However, boxes regularly lose the ability to be picked up.

However, if I move the player forward so they are touching the box, waking it up, and then press E I can always pick up the box. So it looks to me like the kinematic joint is not "waking up" the physics sometimes.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Kinematic Joint Problem

Postby Julio Jerez » Mon Jun 12, 2017 2:27 pm

pHySiQuE wrote:I haven't been able to crash the program. However, boxes regularly lose the ability to be picked up.

that the part I do not understand, I was not able to pick the joint once.
can you get the later code, build and put another demo?

as for the joints not waking up, joint do not wake up in newton only bodies.
It may be possible that they to sleep but I have not test that, but I had similar problem with the vehicle, I do see that you have some debug that show the box changing form blue to orange.
try disable auto sleep on the target body and see fix that.
in newton 3.14 object go to sleep in one frame, that one different with previous version.

anyway the code does not malfunction now, so that good.
please after you link the new code, send me another demo, if you can't get it to work.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic Joint Problem

Postby pHySiQuE » Mon Jun 12, 2017 2:36 pm

I will send another demo.

I was able to get this to work by waking up the body myself every time SetTargetPosition, SetTargetRotation, or SetTargetMatrix are called.
Code: Select all
   void NewtonDynamicsBody::Wake()
   {
      if (body == NULL) return;
      if (NewtonBodyGetSleepState(body)) entity->CallFunction("Wake");
      dFloat i[4]={0.0,0.0,0.0,0.0};
      NewtonBodyApplyImpulsePair(body,i,i, 1.0/60.0);
      NewtonStaticBodySetFreezeState(body,0);
   }
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Kinematic Joint Problem

Postby Julio Jerez » Mon Jun 12, 2017 3:01 pm

ok, so maybe that's the problem, applying an impulse is the wrong way of doing that.
and freeze is the wrong function to used. try this.

Code: Select all
void NewtonDynamicsBody::Wake()
   {
      if (body == NULL) return;
      if (NewtonBodyGetSleepState(body)) {
           entity->CallFunction("Wake");
           NewtonBodySetSleepState(body, 0);
//      dFloat i[4]={0.0,0.0,0.0,0.0};
//      NewtonBodyApplyImpulsePair(body,i,i, 1.0/60.0);
//      NewtonStaticBodySetFreezeState(body,0);
      }
   }


do no wake all object every time, this should only apply to the picked body.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic Joint Problem

Postby Julio Jerez » Tue Jun 13, 2017 12:48 am

ok if you sync, it should be working correctly now.
you do not need to write that function since the joints now takes care automatically the proper way.

I tested with your demo, and it works quite nicely. Is actually very cool to pick object and not worry about then malfunctioning or acting weird if the hit other obstacles, instead they behave in a plausible way as the would is reality. :D

That joint has being in the engine for more than five years, and so far I think only two people has used them, you are the third client to do so. No matter how many feature an engine has if they at not used it might as well not have them.

Those are the stuff I was trying to tell your "fast physics engine" friend over your forum that he removed from his benchmark tool pretending that only fast box stacking is the only thing important on a physics library, which btw his engine does not do right either. But what do I know?

hey do you know what you should do? you should program a shift key so that when that key is depressed, moving the mouse on any direction modify the pitch and yaw angle of the kinematic joint matrix, that way the player can align object in the scene similar to what soma and penumbra do.
I was trying to take boxes from the shelves and place then on the pickup, I placed one top of another, but if when lifted the top body failed down if is lift high enough, rotation alignment can fix that :) .
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic Joint Problem

Postby pHySiQuE » Tue Jun 13, 2017 2:09 am

I can add that easily.

I'm actually using this right now for robot poses in VR. :D
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Kinematic Joint Problem

Postby pHySiQuE » Wed Jun 14, 2017 5:21 am

This joint is great for VR, too. I can easily pick up objects and throw them around.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests