PIDController

class wpilib.PIDController(*args, **kwargs)[source]

Bases: wpilib.LiveWindowSendable

Can be used to control devices via a PID Control Loop.

Creates a separate thread which reads the given PIDSource and takes care of the integral calculations, as well as writing the given PIDOutput.

Allocate a PID object with the given constants for P, I, D, and F

Arguments can be structured as follows:

  • Kp, Ki, Kd, Kf, PIDSource, PIDOutput, period
  • Kp, Ki, Kd, PIDSource, PIDOutput, period
  • Kp, Ki, Kd, PIDSource, PIDOutput
  • Kp, Ki, Kd, Kf, PIDSource, PIDOutput
Parameters:
  • Kp (float or int) – the proportional coefficient
  • Ki (float or int) – the integral coefficient
  • Kd (float or int) – the derivative coefficient
  • Kf (float or int) – the feed forward term
  • source (A function, or an object that implements PIDSource) – Called to get values
  • output (A function, or an object that implements PIDOutput) – Receives the output percentage
  • period (float or int) – the loop time for doing calculations. This particularly effects calculations of the integral and differential terms. The default is 50ms.
AbsoluteTolerance_onTarget(value)[source]
PercentageTolerance_onTarget(percentage)[source]
calculate()[source]

Read the input, calculate the output accordingly, and write to the output. This should only be called by the PIDTask and is created during initialization.

disable()[source]

Stop running the PIDController, this sets the output to zero before stopping.

enable()[source]

Begin running the PIDController.

free()[source]

Free the PID object

get()[source]

Return the current PID result. This is always centered on zero and constrained the the max and min outs.

Returns:the latest calculated output
getD()[source]

Get the Differential coefficient.

Returns:differential coefficient
getError()[source]

Returns the current difference of the input from the setpoint.

Returns:the current error
getF()[source]

Get the Feed forward coefficient.

Returns:feed forward coefficient
getI()[source]

Get the Integral coefficient

Returns:integral coefficient
getP()[source]

Get the Proportional coefficient.

Returns:proportional coefficient
getSetpoint()[source]

Returns the current setpoint of the PIDController.

Returns:the current setpoint
instances = 0
isEnable()[source]

Return True if PIDController is enabled.

kDefaultPeriod = 0.05
onTarget()[source]

Return True if the error is within the percentage of the total input range, determined by setTolerance. This assumes that the maximum and minimum input were set using setInput().

Returns:True if the error is less than the tolerance
reset()[source]

Reset the previous error, the integral term, and disable the controller.

setAbsoluteTolerance(absvalue)[source]

Set the absolute error which is considered tolerable for use with onTarget().

Parameters:absvalue – absolute error which is tolerable in the units of the input object
setContinuous(continuous=True)[source]

Set the PID controller to consider the input to be continuous. Rather then using the max and min in as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.

Parameters:continuous – Set to True turns on continuous, False turns off continuous
setInputRange(minimumInput, maximumInput)[source]

Sets the maximum and minimum values expected from the input.

Parameters:
  • minimumInput – the minimum percentage expected from the input
  • maximumInput – the maximum percentage expected from the output
setOutputRange(minimumOutput, maximumOutput)[source]

Sets the minimum and maximum values to write.

Parameters:
  • minimumOutput – the minimum percentage to write to the output
  • maximumOutput – the maximum percentage to write to the output
setPID(p, i, d, f=None)[source]

Set the PID Controller gain parameters. Set the proportional, integral, and differential coefficients.

Parameters:
  • p – Proportional coefficient
  • i – Integral coefficient
  • d – Differential coefficient
  • f – Feed forward coefficient (optional)
setPercentTolerance(percentage)[source]

Set the percentage error which is considered tolerable for use with onTarget(). (Input of 15.0 = 15 percent)

Parameters:percentage – percent error which is tolerable
setSetpoint(setpoint)[source]

Set the setpoint for the PIDController.

Parameters:setpoint – the desired setpoint
setTolerance(percent)[source]

Set the percentage error which is considered tolerable for use with onTarget(). (Input of 15.0 = 15 percent)

Parameters:percent – error which is tolerable

Deprecated since version 2015.1: Use setPercentTolerance() or setAbsoluteTolerance() instead.