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 float
deadband
protected int
deadbandPeriod
protected java.util.concurrent.TimeUnit
deadbandUnit
protected float
deltaError
protected float
integralError
protected float
kD
protected float
kI
protected float
kP
protected long
lastTimeNotAtTarget
protected float
prevError
protected PIDSrc<T,V>
source
A 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 boolean
atTarget()
Check if this PID has reached its target value.void
clear()
Reset the state of this PID loop.float
getkD()
Get the Derivative constant for this PID.float
getkI()
Get the Integral constant for this PID.float
getkP()
Get the Proportional constant for this PID.PIDSrc<T,V>
getSrc()
Get the source sensor of this PID.abstract V
pid(V target)
Iterate the PID loop.void
setkD(float kD)
Set the Derivative constant for this PID.void
setkI(float kI)
Set the Integral constant for this PID.void
setkP(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.
-
-