# Implementation of a PID Controller

I've implemented a PID controller, but seeing as I'm not an expert in control theory, have I missed any edge cases?

public class PIDController
{
public enum PIDMode
{
Manual,
Auto,
}

public enum PIDAction
{
Indirect,
Direct,
}

public PIDMode Mode { get; set; }
public PIDAction Action { get; set; }

public double Proportional { get; set; }
public double Integral { get; set; }
public double Derivative { get; set; }

public double Minimum { get; set; }
public double Maximum { get; set; }

public double DeltaMinimum { get; set; }
public double DeltaMaximum { get; set; }

private double _ProportionalTerm;
private double _Integrator;
private double _Derivator;

public double Setpoint { get; set; }

private double _Feedback;
public double Feedback
{
get
{
return _Feedback;
}
}

public void Calculate(double Input, long Time)
{
double output;

// Compute the error value
double Error = Setpoint - Input;

if (Mode == PIDMode.Auto)
{
if (Action == PIDAction.Direct)
Error = 0 - Error;

// Compute the proportional component
_ProportionalTerm = 1000.0f * (Error - _Derivator) / (double)Time;

// Compute the integrator component, clamped to min/max delta movement
_Integrator += (float)Error * (float)Time / 1000.0f;
if (_Integrator < DeltaMinimum)
_Integrator = DeltaMinimum;
if (_Integrator > DeltaMaximum)
_Integrator = DeltaMaximum;

output = (Proportional * Error);

output += Integral * _Integrator;

output += Derivative * _ProportionalTerm;

// Clamp output to min/max
if (output < Minimum)
output = Minimum;
if (output > Maximum)
output = Maximum;
}
else
{
output = Input;
}

// Store values
_Derivator = Error;

// Returns the result
_Feedback = output;
}
}