public class PIDController
extends java.lang.Object
implements java.lang.Runnable
Constructor and Description |
---|
PIDController(edu.wpi.first.wpilibj.SpeedController m,
PIDSource s,
double kP,
double kI,
double kD)
Creates a new
PIDController object with given values, using the defaults for min and max
motor target. |
PIDController(edu.wpi.first.wpilibj.SpeedController m,
PIDSource s,
double kP,
double kI,
double kD,
double min,
double max)
Creates a new
PIDController object with given values. |
Modifier and Type | Method and Description |
---|---|
void |
disable()
Disables controllers of the motor.
|
void |
enable()
Enables controllers of the motor.
|
double |
getCurrentError()
Get the difference between the target and the current position, in encoder clicks.
|
double |
getCurrentSourceValue()
Gets the current value of the PID source.
|
double |
getMotorPower()
Get the power that is currently being sent to the motor.
|
double |
getTarget()
Get the currently set target.
|
boolean |
isDone()
Checks if this PIDController is done.
|
boolean |
isEnabled()
Checks if this PIDController is enabled.
|
void |
log() |
void |
logVerbose() |
void |
resetSource()
Reset the encoder to zero.
|
void |
reTune(double kP,
double kI,
double kD)
On-the-fly re-tuning of the onLoop.
|
void |
run() |
void |
setExtraCode(java.lang.Runnable r)
Sets the code that is run every loop of the PID.
|
void |
setFinishedTolerance(double tolerance)
Set the tolerance for determining if the loop is finished.
|
PIDController |
setInputInverted(java.lang.Boolean inverted)
Set the PIDController to invert its input
|
PIDController |
setRotational(java.lang.Boolean isRotational)
Set the PIDController to invert its input
|
void |
setShouldInstaKill(java.lang.Boolean b) |
void |
setTarget(double target)
Set a new position target.
|
PIDController |
whenFinished(java.lang.Runnable r)
Defines code that runs when this PID loop is done.
|
public PIDController(edu.wpi.first.wpilibj.SpeedController m, PIDSource s, double kP, double kI, double kD)
PIDController
object with given values, using the defaults for min and max
motor target.m
- Motor to actuate.s
- Encoder to read.kP
- Proportional tuning variable. Set to 0 to disable the P term.kI
- Integral tuning variable. Set to 0 to disable to I term.kD
- Derivative tuning variable. Set to 0 to disable the D term.public PIDController(edu.wpi.first.wpilibj.SpeedController m, PIDSource s, double kP, double kI, double kD, double min, double max)
PIDController
object with given values.m
- Motor to actuate.s
- Encoder to read.kP
- Proportional tuning variable. Set to 0 to disable the P term.kI
- Integral tuning variable. Set to 0 to disable to I term.kD
- Derivative tuning variable. Set to 0 to disable the D term.min
- The minimum target to the motor. Values below this will be scaled down to 0.max
- The maximum target to the motor. Values above this will be scaled to this value.public void enable()
public void disable()
public boolean isEnabled()
public void setTarget(double target)
target
- Position target in encoder clicks from encoder zeropublic double getTarget()
public PIDController setInputInverted(java.lang.Boolean inverted)
inverted
- Whether the PIDController should invert its inputpublic PIDController setRotational(java.lang.Boolean isRotational)
isRotational
- Whether the PIDController should treat itself as rotationalpublic double getCurrentError()
public double getMotorPower()
public double getCurrentSourceValue()
public void resetSource()
NOTE: This will reset the encoder object EVERYWHERE it is used.
public void reTune(double kP, double kI, double kD)
PIDController
kP
- Proportional tuning variable. Set to 0 to disable the P term.kI
- Integral tuning variable. Set to 0 to disable to I term.kD
- Derivative tuning variable. Set to 0 to disable the D term.public void setFinishedTolerance(double tolerance)
tolerance
- The tolerance, in whatever units the PIDSource providespublic void setShouldInstaKill(java.lang.Boolean b)
public boolean isDone()
public PIDController whenFinished(java.lang.Runnable r)
r
- The code to be run.public void setExtraCode(java.lang.Runnable r)
r
- The code to run.public void log()
public void logVerbose()
public void run()
run
in interface java.lang.Runnable