From: eileha Date: Wed, 4 Feb 2026 01:01:02 +0000 (-0800) Subject: pid X-Git-Url: https://git.taranathan.com/?a=commitdiff_plain;h=05d0d09b00a5635b58828a7a62264a9b4930a246;p=FRC2026.git pid --- diff --git a/src/main/java/frc/robot/subsystems/Intake/Intake.java b/src/main/java/frc/robot/subsystems/Intake/Intake.java index 00b27f1..e74deea 100644 --- a/src/main/java/frc/robot/subsystems/Intake/Intake.java +++ b/src/main/java/frc/robot/subsystems/Intake/Intake.java @@ -2,6 +2,9 @@ package frc.robot.subsystems.Intake; import com.ctre.phoenix6.hardware.TalonFX; +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.controller.PIDController; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.SubsystemBase; @@ -15,33 +18,51 @@ public class Intake extends SubsystemBase { private double position; private double maxExtension; private double current; + private PIDController pid; + private double gearRatio; public Intake() { // set actual IDs rollerMotor = new TalonFX(0); rightMotor = new TalonFX(0); leftMotor = new TalonFX(0); + pid = new PIDController(0, 0, 0); } + public void periodic() { // current threshold + PID stuff + double motorPosition = getPosition(); + double currentPosition = Units.rotationsToRadians(motorPosition/gearRatio); + double power = pid.calculate(currentPosition); + + rollerMotor.set(MathUtil.clamp(power, -1, 1)); } + public void simulationPeriodic(){ } + public void setPosition(double position) { } + + public double getPosition(){ + // position is in rotations + double position = rollerMotor.getPosition().getValueAsDouble(); + return position; + } + public void spin(double speed) { rollerMotor.set(0.2); } - public void extend() { setPosition(maxExtension); } + public void retract(){ setPosition(0);