Class 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 gains
      PIDv2​(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 value
      void config​(double p, double i, double d)
      Configure the PID controller with new gains
      void config​(PIDProfile profile)
      Configure the PID controller with a new PIDProfile
      double feed​(double current)
      Feed the system with the current sensor reading
      double 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 finished
      void reset()
      Reset the system (effective next cycle)
      void resetErrorSum()  
      void setIRange​(double iRange)  
      void setOutputConstraints​(double max)
      Set a maximum output value
      void setOutputConstraints​(double min, double max)
      Set both a maximum, and minimum output value
      void 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)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface edu.wpi.first.wpilibj.Sendable

        addChild, getName, getSubsystem, setName, setName, setName, setName, setSubsystem
    • Field Detail

      • previousError

        protected double previousError
      • debug

        protected boolean debug
    • 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 gain
        i - I gain
        d - 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 gain
        i - I gain
        d - 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 output
        max - 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 interface edu.wpi.first.wpilibj.Sendable