<s> class PIDController ( object ) : <EOL> Kp = <NUM_LIT> <EOL> Ki = <NUM_LIT> <EOL> Kd = <NUM_LIT:1> <EOL> K = <NUM_LIT> <EOL> GUARD_GAIN = <NUM_LIT:10> <EOL> def __init__ ( self ) : <EOL> self . totalError = <NUM_LIT:0> <EOL> self . lastError = <NUM_LIT:0> <EOL> def calculateSpeed ( self , targetPosition , currentPosition ) : <EOL> error = targetPosition - currentPosition <EOL> proportionalTerm = PIDController . Kp * error <EOL> self . totalError = self . totalError + error <EOL> integralTerm = PIDController . Ki * max ( min ( PIDController . GUARD_GAIN , self . totalError ) , - PIDController . GUARD_GAIN ) <EOL> derivativeTerm = PIDController . Kd * ( error - self . lastError ) <EOL> return max ( min ( PIDController . K * ( proportionalTerm + integralTerm + derivativeTerm ) , <NUM_LIT:50> ) , - <NUM_LIT:50> ) </s>
