Skip to content

Instantly share code, notes, and snippets.

@andrewdolce
Created February 26, 2013 18:15
Show Gist options
  • Save andrewdolce/5040721 to your computer and use it in GitHub Desktop.
Save andrewdolce/5040721 to your computer and use it in GitHub Desktop.
braking
// We're traveling in the same direction we want to go, so do we
// need to brake?
var brakeDist = 0;
var wantsBrake = false;
if ( result.ccw === angularVelocity > 0 ) {
var brakeTime = -angularVelocity / ( brakeTorque * inverseInertia );
brakeDist = brakeTime * angularVelocity * 0.5;
wantsBrake = Math.abs(brakeDist) - Math.abs(targetAngle) > -0.01;
}
if ( wantsBrake ) {
result.brakeDist = brakeDist;
var tmp = desiredTorque;
desiredTorque = brakeTorque;
brakeTorque = tmp;
} else {
result.brakeDist = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment