angle constraint - joint

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

angle constraint - joint

Postby gommlich » Wed Jan 20, 2010 1:45 pm

Hey,

i have a problem with my Joint. I would like to limit the angle for my object by a joint.
I hove following code:

Code: Select all
   vhFloat angle;
   vhFloat sinAngle;
   vhFloat cosAngle;
   vhMatrix matrix0;
   vhMatrix matrix1;

   // calculate the position of the pivot point and the Jacobian direction vectors, in global space.
   CalculateGlobalMatrix (m_localMatrix0, m_localMatrix1, matrix0, matrix1);

   // Restrict the movement on the pivot point along all tree orthonormal direction
   NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_front[0]);
   NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_up[0]);
   NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_right[0]);
   
   // get a point along the pin axis at some reasonable large distance from the pivot
   vhVector q0 (matrix0.m_posit + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
   vhVector q1 (matrix1.m_posit + matrix1.m_front.Scale(MIN_JOINT_PIN_LENGTH));

   // two constraints row perpendicular to the pin vector
    NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
   NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);

   // the joint angle can be determine by getting the angle between any two non parallel vectors
   sinAngle = (matrix0.m_up * matrix1.m_up) % matrix0.m_front;
   cosAngle = matrix0.m_up % matrix1.m_up;
   angle = dAtan2 (sinAngle, cosAngle);
        m_actValue = (angle * 180) / 3.1416f;
        vhFloat test = ((m_driveAngle * 3.1416f ) / 180.0f);

      if (angle < m_minAngle)
                {
         vhFloat relAngle;
         relAngle = angle - m_minAngle;

         // tell joint error will minimize the exceeded angle error
         NewtonUserJointAddAngularRow (m_joint, relAngle, &matrix0.m_front[0]);


         // need high stiffness here
         //NewtonUserJointSetRowStiffness (m_joint, 1.0f);
    // need high stiffness here
      NewtonUserJointSetRowStiffness (m_joint, 2.0f);

      // allow the joint to move back freely
      NewtonUserJointSetRowMaximumFriction (m_joint, 0.0f);

      } else if (angle > m_maxAngle)
                {
         vhFloat relAngle;
         relAngle = m_maxAngle - angle;

         // tell joint error will minimize the exceeded angle error
         NewtonUserJointAddAngularRow (m_joint, relAngle, &matrix0.m_front[0]);
         // need high stiffness here
         // NewtonUserJointSetRowStiffness (m_joint, 1.0f);


      NewtonUserJointSetRowStiffness (m_joint, 2.0f);

      // allow the joint to move back freely
      NewtonUserJointSetRowMaximumFriction (m_joint, 0.0f);

      }


My problem is: if the oject reached the minimum or maximum, the object freezes. Its not possible to rotate the object later by a force.

How can I solve this problem? Any suggestions?

Thx
gommlich
 
Posts: 2
Joined: Thu Feb 14, 2008 6:42 am

Re: angle constraint - joint

Postby Julio Jerez » Wed Jan 20, 2010 2:36 pm

That was the behavior in 1.5 if it stops and you do no get any callback after that

for 2.0 the body will also frezze but you still get get the force and torque callback update, if you are apply the force there them it should work,
if you want to controll the body from the joint then you can call NewtpnASutoFreeze(body, 0) and the body will never freeze.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: angle constraint - joint

Postby gommlich » Wed Jan 20, 2010 3:59 pm

Thanks for your fast reply. I cant upgrade to 2.0!
But, my program has a main loop and update loop.

Is it possible to solve this problem in 1.5 and an external loop?
maybe, i check the applied force in the update loop. If the force is
not 0, I set NewtpnASutoFreeze(body, 0) ???


Thanks
gommlich
 
Posts: 2
Joined: Thu Feb 14, 2008 6:42 am

Re: angle constraint - joint

Postby Julio Jerez » Wed Jan 20, 2010 4:36 pm

I though you were in 1.5 bu teh descrition.

Thera are work around, bu my serius recomendation is that if you are going to use Newton you better upgrade to 2.16
It is better and easier in every aspect. It has being 5 years since 1.53 last update it is time to let it go.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 397 guests

cron