Porting from 3.xx to 4.00 - need help

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Mon Jun 26, 2023 12:48 pm

again.
-a kinematic body does not move by applying forces.
-they can move by setting the velocity, which is used by the solver to move them
-they can move by setting position, by the solve does not know about changes of positions.
-if you attach a joint to a kinematic body, the joint will calculate the force needed to move both bodies
but since a kinematic body does not move by forces, what you get is one body moving while the kinematic state put.

this is what you see in the demo. the picking code, does not uses forces or velocity to move the picked body, it attaches a kinematic joint.

there are good reasons for that. among them.
1-using a joint, uses the engine for doing all the calculation of converting changes of position to impulses.
2-it works better when picking objects that are part of a contraction of bodies. because is calculates the forces that propagate to those other bodies.

but it is not perfect, because as you can see, if a kinematic body is attached to dynamics body, the joint will never be able to move the kinematic body.

fixing the picking code, so that convert the pick kinematic bodies by calculation the velocity,
only fix part of the problem.
if the app picks the kinematic body and apply the velocity, it will move correctly because the solver will see the velocity, so attached bodies will also move.

but if the app picks an attached dynamics body, now it does not know that the body was attached to a kinematic body, so the din body will move, but the kinematic will remind put.

this is why I said that the best way in to encapsuled the bodies and joint int a model, and use an invDynamic solve to predict the motion and use that to set the velocity of the kinematic body.

it is also why I asked what you were doing, because I did not think you were doing that kind of stuff.
if you want to just move the kinematic body, just set the velocity, and it should bode everything.

and again, dynamics bodies attach to kinematic body do not affect the kinematic body.
basically, it can state as:
Kinematic bodies are one way interaction objects, they affect dynamics bodies but dynamic bodies do not affect them.

are you try to attach dynamics bodies to the plane?
if so, them using a kinematic body may not be the best solution.
there are other ways.

you can use a dynamics body.
then in the notify call back, give a force and torque callback that translate the conversion of the changes in the trajectory to impulses.
that is, in each frame once you calculate:

Code: Select all
v to move from p(body) to p(plane)
w to move from q(body) to q(plane)


you can calculate a Linear and angular impulse.
Code: Select all
LinearImpulse = (v - v(body)) * inverseMass
angularImpulse = (w - w(body)) * inverseInertia


them use the function on the dynamics body to apply the impulse to the dynamic body representing the plane.

this is how was done in 3.xx, and I believe the will probably be simpler for you.
The plane will be a dynamics body and will work with everything that you are used to.
so it will be a full physics object.

they only this is that as Joe said, there will be a small lag, between the physics and the plane simulation. This is because, physics are subject to their one inertia, so impulses so impulse cannot change their trajectory in finite time.
but of you make the body representing the plane sufficiently massive, they the attached bodies will fallow with negligible lag.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Jun 26, 2023 3:28 pm

Julio Jerez wrote:again.
-a kinematic body does not move by applying forces.
-they can move by setting the velocity, which is used by the solver to move them
-they can move by setting position, by the solve does not know about changes of positions.
-if you attach a joint to a kinematic body, the joint will calculate the force needed to move both bodies
but since a kinematic body does not move by forces, what you get is one body moving while the kinematic state put.


Hi Julio - yes, I understood and verified the above. I have adjusted my code to, first, move the kinematic body by directly setting the position in the body's matrix. In this case, I can see only the dynamic body (the top plank) moving

Then, I have inserted the code to apply the velocity to kinematic body. In this case, as you said, I would expect to see both kinematic and dynamic body moving, but, as in the above case, I see only dynamic body moving.

Julio Jerez wrote:fixing the picking code, so that convert the pick kinematic bodies by calculation the velocity,
only fix part of the problem.
if the app picks the kinematic body and apply the velocity, it will move correctly because the solver will see the velocity, so attached bodies will also move.
...
if you want to just move the kinematic body, just set the velocity, and it should bode everything.


Right - I didn't intend to change the picking code, but I wrote a new Notify callback. However, the kinematic body is NOT moving. My updated code can be found here (this is a new link, don't use the one from the previous post). Use the "O" key to move the body up, and "L" key to move the body down.

Julio Jerez wrote:are you try to attach dynamics bodies to the plane?


No - as we discussed, I want to have a kinematic body slaved to position and orientation of Flight Simulator aircraft, and I want to have the Dynamic body attached to the kinematic body, like in this picture: (Green body kinematic, blue body dynamic)

Image

I think that, in my test case, if I get the kinematic body moving, then I am almost there.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Mon Jun 26, 2023 5:01 pm

No - as we discussed, I want to have a kinematic body slaved to position and orientation of Flight Simulator aircraft, and I want to have the Dynamic body attached to the kinematic body, like in this picture: (Green body kinematic, blue body dynamic)

yes, that what I ment.

I figured you are not modifying the camera picking code. I said that there were two ways to fix the problem.
-Augment the pick code so that can pick kinematic
-Encapsulate the everything in a ndModel, and use the invDynamic solve to predict the velocity.
both solutions are problematic. and even if one worked, I can see it breaking down is a near future.

the problem is that you want to make us a kinematic body as a surrogate of a dynamics body that should have the full capability of a dynamics body: and kinematic bodies are no design for that.
there are ok, for trigger, player capsule, elevators, and stuff like that.

when I suggested a kinematic body, I was thinking using a compound for the moving parts. but that will bring other problems as well, animation the motion, and when to turn a child shape into a body.
considering all those problems, I believe is would be better to just do it the same way was done in 3.14.

basically, convert the displacement into a velocity and there the velocity change into an impulse.
there are few European vehicle simulator that use newton and do that quite well. the simulation comes from a package, and the feed the impulse to newton.

I suggest you do that, It is just one more step to get the impulse and will save you lot of aggravations.

edit:
I see if I modify the last script to use a dynamics body that convert the input to impulses.
I cann't do it now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Jun 26, 2023 5:47 pm

Ok. I thought that what I needed was possible by, as you said, setting velocity on a kinematic body.

No problem then - let me know what is the best possible way of doing this, either in 3.xx or 4.00. Feel free to modify the code in the file I provided directly from the link. Please note that the aircraft may move very fast, so I hope the solution will be able to keep up with the speeds....
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Mon Jun 26, 2023 6:22 pm

you do it in 4:00
just not using kinematic.
I do the test tonight.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Jun 26, 2023 7:18 pm

Thank you, Julio, I really appreciate it!!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Tue Jun 27, 2023 9:36 pm

Julio Jerez wrote:you do it in 4:00
just not using kinematic.
I do the test tonight.


Hi Julio, I was just wondering if you had a chance to do the test? thanks!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Wed Jun 28, 2023 3:22 pm

did not had time.
Try tonight.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Thu Jun 29, 2023 9:23 am

Sounds good! I just need to know whether it can be done or not.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Thu Jun 29, 2023 3:45 pm

yes is canbe done, not problem at all. Just that this week is tight for me.
I probably do Saturday morning.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Jul 03, 2023 2:13 pm

Ok, to further clarify and simplify this test case, I have updated it to include 2 separate objects, a jet cargo aircraft, and a droppable fuel tank (shown in blue), attached to the red pylon (which is a part of the aircraft) on the left aircraft wing.

Image

Test case source, Aircraft and Fuel tank FBX files can be found here:

ndMishoTestCase.cpp
SimpleCargoPlane.fbx
SimpleFuelTank.FBX

The code first loads the Aircraft and Fuel tank, and joins them with the hard ndJointFix6dof Joint. Both bodies are Dynamic type. You can use "P" key to destroy the joint and drop the tank, and "O" key to position and re-attach the fuel tank by re-creating the ndJointFix6dof joint.

There is also a matrix called FlightSimPosition, which basically represents the position and orientation of the aircraft which would be dictated (set) by Flight Simulator. This matrix does nothing in the default state of the test case.

Then - you can use "U" key to UNLOCK the setting of the position of the FlightSimPosition matrix. What this does is,

  • MOVES the FlightSimPosition matrix horizontally by using I,J,K, and M keys
  • APPLIES this matrix to the Aircraft body's position

You can use "L" key to again LOCK the moving and application of this matrix to Aircraft body. In the LOCKED mode, Aircraft and Fuel Tank are locked tightly to each other. You can grab and tumble the aircraft around with a mouse pointer, and the Fuel Tank will stay attached to it, as expected. In the UNLOCKED mode, when aircraft is moved using the keys, Fuel Tank follows but with a "rubber band" delay.

So basically, the ask is to have the plane in the UNLOCKED mode so that its position (and orientation, but I have not implemented that) can be set externally, (in my case, by a Flight Simulator flight model), but all the attached objects stay rigidly attached to it. I hope this test case simplifies it a bit more.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Mon Jul 03, 2023 4:06 pm

Wow, that looks very cool, I will try to check tonight.

I was doing the reinforcement learning thing and took lot of debugging time.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Mon Jul 03, 2023 4:57 pm

Thanks Julio, no worries, whenever you have time. I just wanted to make it easier to work on it.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby misho » Sat Jul 15, 2023 1:08 pm

As I continue working on the conversion, I am encountering things like this:

In 3.xx, we had:

Code: Select all
m_matrix.SanityCheck()


and this is gone in 4.00. Is this done somewhere internally, or do I have to perform my own?
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Porting from 3.xx to 4.00 - need help

Postby Julio Jerez » Sun Jul 16, 2023 12:10 am

ah yes, I added now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 58 guests

cron