Last active
July 3, 2020 11:10
-
-
Save korchoon/f45eac72a7e93070839450f4648afa5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[System.Serializable] | |
public class SimplePID { | |
public float Kp = 1f; | |
public float Ki = 0f; | |
public float Kd = .1f; | |
float _lastError; | |
float _p, _i, _d; | |
public void Reset() { | |
_lastError = 0; | |
} | |
public float Update(float error, float dt) { | |
_p = error; | |
_i += error * dt; | |
_d = (error - _lastError) / dt; | |
_lastError = error; | |
return _p * Kp + _i * Ki + _d * Kd; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment