Package frc.robot.helpers
Class LimitedPID
java.lang.Object
frc.robot.helpers.LimitedPID
Represents a PID-controlled subsystem with limit switches and position control.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
State of position knowledge for a subsystem.Constructor Summary
ConstructorsConstructorDescriptionLimitedPID
(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 TypeMethodDescriptioncom.revrobotics.spark.SparkMax
getMotor()
Gets the motor controller for this subsystem.double
Gets the current position of the mechanism.getState()
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
update()
Updates the mechanism status by checking limit switches.
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 controllerconversionFactor
- Factor to convert motor rotations to position unitsminPosition
- Minimum allowed position valuemaxPosition
- Maximum allowed position valuepidConstants
- PID constants for controlminLimitChannel
- DIO channel for minimum position limit switchmaxLimitChannel
- DIO channel for maximum position limit switchtolerance
- Tolerance for position offsetisInverted
- Whether the motor direction is invertedrampRate
- Ramp rate in seconds from 0 to full throttlecurrentLimit
- Maximum current limit in amps
Method Details
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.