Package ca.team3161.lib.robot.pid
Class AbstractPID<T extends edu.wpi.first.wpilibj.PIDSource,V extends java.lang.Number>
- java.lang.Object
-
- ca.team3161.lib.robot.pid.AbstractPID<T,V>
-
- Type Parameters:
T- the type of sensor used as input to this PID system.V- the type of value read from the sensor used as input to this PID system.
- All Implemented Interfaces:
PID<T,V>
- Direct Known Subclasses:
PIDulum,SimplePID,VelocityController
public abstract class AbstractPID<T extends edu.wpi.first.wpilibj.PIDSource,V extends java.lang.Number> extends java.lang.Object implements PID<T,V>
A PID loop, which uses a PIDSrc and a set of constants to iteratively determine output values with which a system can reach and maintain a target value.
-
-
Field Summary
Fields Modifier and Type Field Description protected floatdeadbandprotected intdeadbandPeriodprotected java.util.concurrent.TimeUnitdeadbandUnitprotected floatdeltaErrorprotected floatintegralErrorprotected floatkDprotected floatkIprotected floatkPprotected longlastTimeNotAtTargetprotected floatprevErrorprotected PIDSrc<T,V>sourceA PIDSrc sensor.
-
Constructor Summary
Constructors Constructor Description AbstractPID(PIDSrc<T,V> source, float deadband, int deadbandPeriod, java.util.concurrent.TimeUnit deadbandUnit, float kP, float kI, float kD)Create a new AbstractPID instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanatTarget()Check if this PID has reached its target value.voidclear()Reset the state of this PID loop.floatgetkD()Get the Derivative constant for this PID.floatgetkI()Get the Integral constant for this PID.floatgetkP()Get the Proportional constant for this PID.PIDSrc<T,V>getSrc()Get the source sensor of this PID.abstract Vpid(V target)Iterate the PID loop.voidsetkD(float kD)Set the Derivative constant for this PID.voidsetkI(float kI)Set the Integral constant for this PID.voidsetkP(float kP)Set the Proportional constant for this PID.
-
-
-
Field Detail
-
source
protected final PIDSrc<T extends edu.wpi.first.wpilibj.PIDSource,V extends java.lang.Number> source
A PIDSrc sensor.
-
deadband
protected volatile float deadband
-
kP
protected volatile float kP
-
kI
protected volatile float kI
-
kD
protected volatile float kD
-
integralError
protected volatile float integralError
-
prevError
protected volatile float prevError
-
deltaError
protected volatile float deltaError
-
deadbandPeriod
protected volatile int deadbandPeriod
-
deadbandUnit
protected volatile java.util.concurrent.TimeUnit deadbandUnit
-
lastTimeNotAtTarget
protected volatile long lastTimeNotAtTarget
-
-
Constructor Detail
-
AbstractPID
public AbstractPID(PIDSrc<T,V> source, float deadband, int deadbandPeriod, java.util.concurrent.TimeUnit deadbandUnit, float kP, float kI, float kD)
Create a new AbstractPID instance.- Parameters:
source- the PIDSrc source sensordeadband- filter value - do not act when current error is within this bound. This can be disabled by passing a negative valuedeadbandPeriod- the amount of time to remain within acceptable error of the target value before claiming to actually be at the targetdeadbandUnit- the units for deadbandPeriodkP- P constantkI- I constantkD- D constant
-
-
Method Detail
-
clear
public final void clear()
Reset the state of this PID loop.
-
atTarget
public final boolean atTarget()
Check if this PID has reached its target value.
-
setkP
public void setkP(float kP)
Set the Proportional constant for this PID.
-
getkP
public float getkP()
Get the Proportional constant for this PID.
-
setkI
public void setkI(float kI)
Set the Integral constant for this PID.
-
getkI
public float getkI()
Get the Integral constant for this PID.
-
setkD
public void setkD(float kD)
Set the Derivative constant for this PID.
-
-