Class LimitedPID

java.lang.Object
frc.robot.helpers.LimitedPID

public class LimitedPID extends Object
Represents a PID-controlled subsystem with limit switches and position control.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    State of position knowledge for a subsystem.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LimitedPID(int canId, double conversionFactor, double minPosition, double maxPosition, PID pidConstants, int minLimitChannel, int maxLimitChannel, double tolerance, boolean isInverted, double rampRate, int currentLimit)
    Creates a new motor subsystem with position control and limit switches.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.revrobotics.spark.SparkMax
    Gets the motor controller for this subsystem.
    double
    Gets the current position of the mechanism.
    Gets the current state of the subsystem.
    boolean
    Checks if the mechanism is at the maximum limit.
    boolean
    Checks if the mechanism is at the minimum limit.
    void
    setPosition(double position)
    Sets the target position of the mechanism.
    void
    Updates the mechanism status by checking limit switches.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LimitedPID

      public LimitedPID(int canId, double conversionFactor, double minPosition, double maxPosition, PID pidConstants, int minLimitChannel, int maxLimitChannel, double tolerance, boolean isInverted, double rampRate, int currentLimit)
      Creates a new motor subsystem with position control and limit switches.
      Parameters:
      canId - CAN ID of the motor controller
      conversionFactor - Factor to convert motor rotations to position units
      minPosition - Minimum allowed position value
      maxPosition - Maximum allowed position value
      pidConstants - PID constants for control
      minLimitChannel - DIO channel for minimum position limit switch
      maxLimitChannel - DIO channel for maximum position limit switch
      tolerance - Tolerance for position offset
      isInverted - Whether the motor direction is inverted
      rampRate - Ramp rate in seconds from 0 to full throttle
      currentLimit - Maximum current limit in amps
  • Method Details

    • getState

      public LimitedPID.SubsystemState getState()
      Gets the current state of the subsystem.
      Returns:
      The current state of the subsystem.
    • getPosition

      public double getPosition()
      Gets the current position of the mechanism.
      Returns:
      current position in mechanism units
    • setPosition

      public void setPosition(double position)
      Sets the target position of the mechanism. Position is clamped to valid range.
      Parameters:
      position - target position in mechanism units
    • getMotor

      public com.revrobotics.spark.SparkMax getMotor()
      Gets the motor controller for this subsystem.
      Returns:
      the SparkMax motor controller
    • isAtMinLimit

      public boolean isAtMinLimit()
      Checks if the mechanism is at the minimum limit.
      Returns:
      true if at minimum limit, false otherwise
    • isAtMaxLimit

      public boolean isAtMaxLimit()
      Checks if the mechanism is at the maximum limit.
      Returns:
      true if at maximum limit, false otherwise
    • update

      public void update()
      Updates the mechanism status by checking limit switches.