Skip to content

Instantly share code, notes, and snippets.

@korchoon
Last active July 3, 2020 11:10
Show Gist options
  • Save korchoon/f45eac72a7e93070839450f4648afa5e to your computer and use it in GitHub Desktop.
Save korchoon/f45eac72a7e93070839450f4648afa5e to your computer and use it in GitHub Desktop.
[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