Custom Hinge Applying Torque to achieve specific angle

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Custom Hinge Applying Torque to achieve specific angle

Postby JoeJ » Sun Feb 05, 2017 5:38 pm

SBlade wrote:OK thanks, but all this almost proves that its not doable with hinges/custom hinges because I can not have variable pivot point, am I wrong ?


You're wrong, you can do this. Why do you think so, what do you mean with 'variable pivot'?

Imagine each body has a lever attached to it, and the endpoints of the levers are connected.
But you can also make this lever with a length of zero for one body to get the pendulum.
(You would set the pivot to the same position as either the child or the parent body)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Custom Hinge Applying Torque to achieve specific angle

Postby SBlade » Mon Feb 06, 2017 4:01 am

The reasoning behind of this was that: Even if I attach the hinge to body, that is blue sphere in my case, I never saw a hinge moving with the attached body . As is shown in previous animation gifs my hinges always have fixed point in worldspace so they don't move, but establishing parent child relations should be enough to attach them to body, where when body moves hinge will move also, but I have never observed such behaviour. Can you point out to any example in newton folder which impleemnts that ? Where hinge moves with body as well.

With variable point I meant, hinge positon will be having diffrent positions depending on attached body oscillation,

Unfortunately I couldn't compile ND with vs2015 downloaded from github, it shows approx 20 errors, which I didn't understand , otherwise I totally would skip the pascal part and continue from scratch with c++ to testify the newton dynamics, because I feel like there is some fundamental part or something obvious I'm missing.

Regards,
SBlade
 
Posts: 20
Joined: Thu Jan 12, 2017 5:42 am

Re: Custom Hinge Applying Torque to achieve specific angle

Postby JoeJ » Mon Feb 06, 2017 5:35 am

SBlade wrote:I never saw a hinge moving with the attached body


This is what i was talking about proper rendering of the pivot.
I have the impression you have some kind of transform hirarchy or scene graph, but that may be more confusing than helpful for physics, because all data is just in worldspace independent of any joint relationships.

Continueing from my example with the picture, some pseudocode to render the joint would be:
(My example assumes both bodies have an identity matrix for orientation at setup, otherwise my local offsets would be wrong)

vec3 localOffsetP (3,0,0);
vec3 localOffsetC (-3,0,0);

matrix mP = NewtonBodyGetMatrix (parentBody);
vec3 pivotWorldspaceP = mP * localOffsetP; // or mP.position + mP.Rotate(localOffsetP)
DrawLine (mp.position, pivotWorldspaceP);

matrix mC = NewtonBodyGetMatrix (childBody);
vec3 pivotWorldspaceC = mC * localOffsetC;
DrawLine (mC.position, pivotWorldspaceC);

SBlade wrote:As is shown in previous animation gifs my hinges always have fixed point in worldspace so they don't move

They don't move because you render them wrong, you need to transform with current body position and orientation as shown above to reflect what happens inside the physics engine.
If you look at Submit Constraints functions of joints, they do the same transformations to calculate the data given to the solver.

SBlade wrote:Can you point out to any example in newton folder which impleemnts that ? Where hinge moves with body as well.

Any example does this, but unfortunately they do not visualize joint pin and pivot.

SBlade wrote:Unfortunately I couldn't compile ND with vs2015 downloaded from github, it shows approx 20 errors, which I didn't understand , otherwise I totally would skip the pascal part and continue from scratch with c++ to testify the newton dynamics, because I feel like there is some fundamental part or something obvious I'm missing.


This might be a good idea, even if you're new to C++, another language is probably less confusing than this transformations stuff :)

Should compile out of the box:

File / Open Project Solution: \newton-dynamics-master\applications\demosSandbox\projects\visualStudio_2015/demosSandbox.sln

In Solution Explorer ther are lots of projects (dContainers, dCustomJoints...), right click demosSandbox (set Startup Project if not already, you also build it from there).

Build and run with'Local Windows Debugger' - button with the green triangle.

Edit StandartJoints.cpp to modify and play around (Uncomment AddHinge (scene, dVector (-20.0f, 0.0f, 0.0f)); for a similar setup like your goal)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Custom Hinge Applying Torque to achieve specific angle

Postby SBlade » Mon Feb 06, 2017 3:37 pm

Can I make that verdict: If the pivot point rendering is wrong then whole pivoting system is wrong? Because in Pascal implementation it directly takes the pivot without any preprocssing or post processing for rendering, so if rendering of pivot point is wrong then teh position of pivot point should be wrong as well.

With your pseudo code, If I understand it correctly you perform the GlobalToLocal conversion of pivot point with regard to attached body, this normally is standart way of coordinate transformation, I modified code then I got the following video, now pivot moves but not exactly on the blue sphere. CAn you shed some light on that?

Green cross is pivot point
http://i.giphy.com/26xBSrudszmwpUCeQ.gif

Code snippet for correct pivot point rendering.
Code: Select all
var
  m :TMatrix;
  v1 :Tvector;
  procedure DrawPivot(pivot: TVector);
  var
    size: Single;
  begin
   
    v1 := VectorSubtract(FParentObject.AbsolutePOsition, pivot);
    pivot :=  Vectortransform(v1,FParentObject.Absolutematrix);

    size := FManager.DebugOption.DotAxisSize;
    FManager.FCurrentColor := FManager.DebugOption.JointPivotColor;
    FManager.AddNode(VectorAdd(pivot, VectorMake(0, 0, size)));
    FManager.AddNode(VectorAdd(pivot, VectorMake(0, 0, -size)));
    FManager.AddNode(VectorAdd(pivot, VectorMake(0, size, 0)));
    FManager.AddNode(VectorAdd(pivot, VectorMake(0, -size, 0)));
    FManager.AddNode(VectorAdd(pivot, VectorMake(size, 0, 0)));
    FManager.AddNode(VectorAdd(pivot, VectorMake(-size, 0, 0)));
  end;   
SBlade
 
Posts: 20
Joined: Thu Jan 12, 2017 5:42 am

Re: Custom Hinge Applying Torque to achieve specific angle

Postby JoeJ » Mon Feb 06, 2017 4:01 pm

SBlade wrote:Because in Pascal implementation it directly takes the pivot without any preprocssing or post processing for rendering


The question is what kind if pivot data you get.
1. It may be the world space position from setup, so the same numbers every frame.
2. It may be the local position relative to either the parent or child body or both (i used localOffsetP and localOffsetC for this), also same numbers every frame.
3. Or it may be already transformed to worldspace so you don't need to do it yourself (different numbers ech frame).

I don't know, you'd need to look up Pascal wrapper source code or compare the returned numbers with those you give in setup.
I Newton i see getters varying between options 2 and 3.

v1 := VectorSubtract(FParentObject.AbsolutePOsition, pivot);
pivot := Vectortransform(v1,FParentObject.Absolutematrix);


This line would be correct if pivot is the value from setup AND bodies has no rotation at setup (otherwise you need to unrotate as well or multiply with the inverse to get the proper local pivot in body space)

I suggest you change the blue sphere to a cube so it becomes visible if the pivot is properly fixed to its orientation.
You should also start with only one joint between only two dynamic bodies, at the moment the gif is still strange but there's too much options of what could be wrong.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Custom Hinge Applying Torque to achieve specific angle

Postby SBlade » Mon Feb 06, 2017 5:03 pm

As pivot point data, I got item #3 after code modification as per your suggestion, different numebrs in each frame, the code snippets that you quoted. But before code modification it was item #1, same numbers every frame .
SBlade
 
Posts: 20
Joined: Thu Jan 12, 2017 5:42 am

Re: Custom Hinge Applying Torque to achieve specific angle

Postby JoeJ » Mon Feb 06, 2017 5:54 pm

Looking at the gif a bit longer it my be a correct double pendulum indeed and just the pivot rendering is wrong.

So here some pseudo code if bodies have rotation at setup, this should work in any case:

// setup:
joint = BuildHinge (parentBody, childBody, worldPivot, worldPidDir);
matrix4x4 pM = parentBody.GetMatrix();
vec3 localPivot = pM.Unrotate(worldPivot - pM.position); // store this for rendering

// render:
matrix4x4 pM = parentBody.GetMatrix();
vec3 curWorldPivot = pM.position + pM.Rotate(localPivot);
DrawLine (pM.position, curWorldPivot);
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Custom Hinge Applying Torque to achieve specific angle

Postby SBlade » Tue Feb 07, 2017 3:12 am

Thanks in advance,

Normally they are not setup with rotation at initialization, I must play around with contraption to see if I can addopt it to a skeleton ( not complicated one, very simple mechanism will serve the purpose) doesn't need to be ultra super good.

I noticed that distance of rigid body to hinge elongates or shrinks, I couldn't decide whether it is due to wrong pivot point or eye illusion, but it seemed so. Does it have anything to do with SetLinearLimits ?

Regards,
SBlade
 
Posts: 20
Joined: Thu Jan 12, 2017 5:42 am

Re: Custom Hinge Applying Torque to achieve specific angle

Postby JoeJ » Tue Feb 07, 2017 4:52 am

SBlade wrote:I noticed that distance of rigid body to hinge elongates or shrinks, I couldn't decide whether it is due to wrong pivot point or eye illusion, but it seemed so. Does it have anything to do with SetLinearLimits ?


The stretching comes most probably from a huge force by your mouse pick.
I real life either the hinge or the picking joint would break (it's possible to implement this),
but what you can do is:
For a force based picking system limit the force to some max value.
For a joint based system you can set the max forces / torques by 'max and min friction'.

But if you have a robotic arm lifting a huge weight, some error will occur for the same reasons.
This is what the new skeleton joints we talk about in the other thread are good for.
So you'll want to update to new Newton version in the future.
It also helps to increase solver iterations and decrease the timestep (I used 120 Hz and 7 iterations for a walking ragdoll with the old joints that you currently have).

'SetLinearLimits' more probably has to do with some hard joint limits,
e.g. min and max angle for a hinge (but we would call it angular limits, linear means position)
or min / max translation for a slider joint etc.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Custom Hinge Applying Torque to achieve specific angle

Postby SBlade » Tue Feb 07, 2017 3:14 pm

Thank you very much indeed for sharing very valuable information.
SBlade
 
Posts: 20
Joined: Thu Jan 12, 2017 5:42 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 22 guests

cron