Created
April 2, 2022 20:20
-
-
Save moppius/da35386dd212797116bcb47153fdc568 to your computer and use it in GitHub Desktop.
PID Controller for Unreal Angelscript
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
struct FPIDController | |
{ | |
UPROPERTY(Category = "PID Controller") | |
const float ProportionalMultiplier = 1.f; | |
UPROPERTY(Category = "PID Controller") | |
const float IntegralMultiplier = 0.f; | |
UPROPERTY(Category = "PID Controller") | |
const float DerivativeMultiplier = 0.f; | |
UPROPERTY(Category = "PID Controller") | |
const float Bias = 0.f; | |
private float LastError = 0.f; | |
private float LastIntegral = 0.f; | |
float Update(float DesiredValue, float CurrentValue, float DeltaSeconds) | |
{ | |
const float Error = DesiredValue - CurrentValue; | |
const float Integral = LastIntegral + Error * DeltaSeconds; | |
const float Derivative = (Error - LastError) / DeltaSeconds; | |
const float Output = ( | |
ProportionalMultiplier * Error | |
+ IntegralMultiplier * Integral | |
+ DerivativeMultiplier * Derivative | |
+ Bias | |
); | |
LastError = Error; | |
LastIntegral = Integral; | |
return Output; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment