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.