If I would a "NewtonSetRowVelocity"...

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

If I would a "NewtonSetRowVelocity"...

Postby Gianluca » Fri Dec 11, 2009 1:07 pm

Hello,
for custom joints there is NewtonUserJointSetRowAcceleration(const NewtonJoint* joint, dFloat acceleration) that allow to specify the acceleration to set on a DOF of a custom joint...
but what I really need is a something like NewtonUserJointSetRowVelocity( NewtonJoint* joint, dFloat velocity) that instead of setting the acceleration ... allow me to set at what velocity the DOF has to move.
I'm sure that there is a solution using RowAcceleration calculating the right acceleration for a given desired velocity... but after 2 week spent on that...
I realized that I'm not so good in physics to get the right formulation.

So, how can I implement a NewtonUserJointSetRowVelocity in a such way that it will be stable with external perturbations also (like gravity) ??

Thanks,
Gianluca.
Gianluca
 
Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

Re: If I would a "NewtonSetRowVelocity"...

Postby Julio Jerez » Fri Dec 11, 2009 1:18 pm

basically you need to calculate the joint relative velocity by projection on that DOF by using dot product precjection,
the is get veloty at the joint proin
then subtract it for the disered velocity, and call

NewtonUserJointSetRowVelocity ((relVeloc - diseredvelocity) / timestep)

ther are few demos tah do that sort of thing in the SDK
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: If I would a "NewtonSetRowVelocity"...

Postby Julio Jerez » Fri Dec 11, 2009 2:44 pm

Ok here is an code snipe for the cork screw joint fomr the Joint library

Code: Select all
   if (m_angularmotorOn) {
      dFloat relOmega;
      dFloat relAccel;
      dVector omega0 (0.0f, 0.0f, 0.0f);
      dVector omega1 (0.0f, 0.0f, 0.0f);


      // get relative angular velocity
      NewtonBodyGetOmega(m_body0, &omega0[0]);
      if (m_body1) {
         NewtonBodyGetOmega(m_body1, &omega1[0]);
      }

      // calculate the desired acceleration
      relOmega = (omega0 - omega1) % matrix0.m_front;
      relAccel = m_angularAccel - m_angularDamp * relOmega;

      // if the motor capability is on, then set angular acceleration with zero angular correction
      NewtonUserJointAddAngularRow (m_joint, 0.0f, &matrix0.m_front[0]);
      
      // override the angular acceleration for this Jacobian to the desired acceleration
      NewtonUserJointSetRowAcceleration (m_joint, relAccel);
   }


It motorized the rotational velocity, but if you want to control linear velocity the idea is the same, just get the linear velocity at the point the joint connect the bodies.
once you get it it is very intutive,
the idea is to figure out the relive velicity at teh contact point whne eth tow bodies are connected and add extra what you need
in the example I was not interested in a const velocity so I jsut add a damped accelrations
relAccel = m_angularAccel - m_angularDamp * relOmega;

you wan a const velocity teh you can do this

Code: Select all
// calculate the desired acceleration
    relOmega = (omega0 - omega1) % matrix0.m_front;
    relAccel = desiredOmega - relOmega;
    relAccel = relAccel / timestep;

To cope with numerical incuracys and stiffeness, you may want to damp it a litle so instead of doing relAccel = relAccel / timestep;
you can do relAccel = k * relAccel / timestep;
where k is a value lowe than 1.0, ussually 0.3 is a nice values.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
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 2 guests

cron