Created
February 26, 2013 18:15
-
-
Save andrewdolce/5040721 to your computer and use it in GitHub Desktop.
braking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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