A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by rattus » Tue Mar 08, 2011 11:09 am
Hello,
I'm trying to find out how to limit angular speed ( omega ).
My model is simple "ship" in space, ideally no damping.
I have "thrusters" that generate rotation and main engine generating forward speed
i apply forces during the normal newton callback - NewtonApplyForceAndTorque
the "thrusters" are forces applied in opposite points of the center - example:
- Code: Select all
if ( TurnImpulse.x != 0 ) {
float ratio = TurnImpulse.x;
body.AddLocalForce( Vector3.UNIT_X * 50, Vector3.UNIT_Z * ratio );
body.AddLocalForce( Vector3.UNIT_X * -50, Vector3.UNIT_Z * -ratio );
}
this does nice turning so i can apply yaw/pitch/roll.
all fine but i would like to limit the top angular speed to some value.
how should i do it ?
count myself the torque, limit it on maximum value and then apply it with setTorque ?
or set body omega value ?
Thanks for any suggestion

-
rattus
-
- Posts: 7
- Joined: Tue Aug 31, 2010 9:20 am
by JoeJ » Tue Mar 08, 2011 5:17 pm
The following code sets a target anguler velocity by clamping to a maximum constant.
This is used to compute a torque which tries to reach that over some time.
- Code: Select all
vector curAngVel = BodyGetOmega()
if (curAngVel.Lenght() > MAX_OMEGA)
{
vector targetAngVel = curAngVel / curAngVel.Lenght() * MAX_OMEGA;
targetAngVel -= curAngVel * 1.0; // take actual angvel in account - something between 0.0 and 1.0; recommended >0.5
vector torque = targetAngVel / timestep;
torque = matrix.Unrotate (torque); // matrix = BodyGetMatrix
torque[0] *= Ixx; // Inertia from BodyGetMassMatrix
torque[1] *= Iyy;
torque[2] *= Izz;
torque = matrix.Rotate (torque);
torque *= 0.1; // something between 0.0 and 1.0; recommended <0.5, high value could generate overspin
BodyAddTorque (torque)
}
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
by rattus » Fri Mar 11, 2011 11:09 am
I tried this and few modifications, and it works when i only roll the body, but gets out of control once i start using two axes of rotation.
I'm using c# wrapper for ogre and newton also, so my code is bit different, but functionally it should be same.
i tried to be sure i apply the torque in correct space ( swapped matrix.Unrotate for quaternion rotations ) but no good.
i will try once again on weekend and post code if still failing.
-
rattus
-
- Posts: 7
- Joined: Tue Aug 31, 2010 9:20 am
by JoeJ » Sat Mar 12, 2011 8:11 am
Also to me this looks like a transformation problem.
Some Math lib could require the Unrotate / Rotate swapped, but it seems you tried that.
Try a body with uniform inertia (sphere), that would make the transformations unneccessary.
For a simpler test case you can try:
vector targetAngVel (1,2,3);
if (VEL_DIRECT)
{
BodySetOmega (targetAngVel);
}
else
{
targetAngVel -= curAngVel * 1.0;
vector torque = targetAngVel / timestep;
torque = matrix.Unrotate (torque); // to local space
torque[0] *= Ixx;
torque[1] *= Iyy;
torque[2] *= Izz;
torque = matrix.Rotate (torque); // back to global space
torque *= 1.0;
BodyAddTorque (torque)
}
This gives 2 options: Either set angular velocity directly, or use torque to reach the same motion.
I developed this by having two bodies side by side, one using the velocity, other using torque method.
Both should rotate about same angle and at equal speed.
Anything done in the force / torque callback.
-

JoeJ
-
- Posts: 1489
- Joined: Tue Dec 21, 2010 6:18 pm
by rattus » Mon Mar 14, 2011 12:11 pm
actually both work quite well as expected.
I found "bug" in setting inertia - i multiplied inertia vector by mass which gave me abnormally high inertia and everything spinned out of control

Thanks.
-
rattus
-
- Posts: 7
- Joined: Tue Aug 31, 2010 9:20 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests