- class wpilib.PIDController(*args, **kwargs)¶
Can be used to control devices via a PID Control Loop.
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
- 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.
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.
Stop running the PIDController, this sets the output to zero before stopping.
Begin running the PIDController.
Free the PID object
Return the current PID result. This is always centered on zero and constrained the the max and min outs.
Returns: the latest calculated output
Get the Differential coefficient.
Returns: differential coefficient
Returns the current difference of the input from the setpoint.
Returns: the current error
Get the Feed forward coefficient.
Returns: feed forward coefficient
Get the Integral coefficient
Returns: integral coefficient
Get the Proportional coefficient.
Returns: proportional coefficient
Returns the current setpoint of the PIDController.
Returns: the current setpoint
- instances = 0¶
Return True if PIDController is enabled.
- kDefaultPeriod = 0.05¶
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 the previous error, the integral term, and disable the controller.
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
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)¶
Sets the maximum and minimum values expected from the input.
- minimumInput – the minimum percentage expected from the input
- maximumInput – the maximum percentage expected from the output
- setOutputRange(minimumOutput, maximumOutput)¶
Sets the minimum and maximum values to write.
- minimumOutput – the minimum percentage to write to the output
- maximumOutput – the maximum percentage to write to the output
- setPID(p, i, d, f=None)¶
Set the PID Controller gain parameters. Set the proportional, integral, and differential coefficients.
- p – Proportional coefficient
- i – Integral coefficient
- d – Differential coefficient
- f – Feed forward coefficient (optional)
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
Set the setpoint for the PIDController.
Parameters: setpoint – the desired setpoint