Package frc.lib5k.control
Class PIDv2
- java.lang.Object
-
- frc.lib5k.control.PIDv2
-
- All Implemented Interfaces:
edu.wpi.first.wpilibj.Sendable
public class PIDv2 extends java.lang.Object implements edu.wpi.first.wpilibj.Sendable
An implementation of team 1114's SimPID, that works with lib5k's kinematics systems, and provides telemetry
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
debug
protected double
previousError
-
Constructor Summary
Constructors Constructor Description PIDv2(double p, double i, double d)
Create a PIDv2 object using gainsPIDv2(PIDProfile profile)
Create a PIDv2 object using a PIDProfile
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
calculate(double error)
Calculate a system output with a custom error valuevoid
config(double p, double i, double d)
Configure the PID controller with new gainsvoid
config(PIDProfile profile)
Configure the PID controller with a new PIDProfiledouble
feed(double current)
Feed the system with the current sensor readingdouble
getIRange()
double
getSetpoint()
void
initSendable(edu.wpi.first.wpilibj.smartdashboard.SendableBuilder builder)
This is for use by WPIlib.boolean
isFinished(double epsilon)
Check if the system is finishedvoid
reset()
Reset the system (effective next cycle)void
resetErrorSum()
void
setIRange(double iRange)
void
setOutputConstraints(double max)
Set a maximum output valuevoid
setOutputConstraints(double min, double max)
Set both a maximum, and minimum output valuevoid
setRestPeriod(int num)
Set the number of cycles the PID controller should wait before declaiming the system "finished"void
setSetpoint(double setpoint)
Set the PID controller's setpoint (goal position)
-
-
-
Constructor Detail
-
PIDv2
public PIDv2(PIDProfile profile)
Create a PIDv2 object using a PIDProfile- Parameters:
profile
- PIDProfile containing gains
-
PIDv2
public PIDv2(double p, double i, double d)
Create a PIDv2 object using gains- Parameters:
p
- P gaini
- I gaind
- D gain
-
-
Method Detail
-
config
public void config(PIDProfile profile)
Configure the PID controller with a new PIDProfile- Parameters:
profile
- New PIDProfile contaning PID gains
-
config
public void config(double p, double i, double d)
Configure the PID controller with new gains- Parameters:
p
- P gaini
- I gaind
- D gain
-
setSetpoint
public void setSetpoint(double setpoint)
Set the PID controller's setpoint (goal position)- Parameters:
setpoint
-
-
setOutputConstraints
public void setOutputConstraints(double max)
Set a maximum output value- Parameters:
max
- Maximum output
-
setOutputConstraints
public void setOutputConstraints(double min, double max)
Set both a maximum, and minimum output value- Parameters:
min
- Maximum outputmax
- Minimum output
-
setRestPeriod
public void setRestPeriod(int num)
Set the number of cycles the PID controller should wait before declaiming the system "finished"- Parameters:
num
- Number of cycles to wait
-
resetErrorSum
public void resetErrorSum()
-
getSetpoint
public double getSetpoint()
-
setIRange
public void setIRange(double iRange)
-
getIRange
public double getIRange()
-
feed
public double feed(double current)
Feed the system with the current sensor reading- Parameters:
current
- Current sensor reading- Returns:
- System output
-
calculate
public double calculate(double error)
Calculate a system output with a custom error value- Parameters:
error
- Error value- Returns:
- System output
-
isFinished
public boolean isFinished(double epsilon)
Check if the system is finished- Parameters:
epsilon
- Acceptable error in the system- Returns:
- Has the system finished?
-
reset
public void reset()
Reset the system (effective next cycle)
-
initSendable
public void initSendable(edu.wpi.first.wpilibj.smartdashboard.SendableBuilder builder)
This is for use by WPIlib. Basically tricking it into thinking this is a built-in class.- Specified by:
initSendable
in interfaceedu.wpi.first.wpilibj.Sendable
-
-