From caff02b0e5fd3fb81e103835e0f80aa502d8dfc1 Mon Sep 17 00:00:00 2001 From: Arenacloserr <162641455+Arenacloserr@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:46:58 -0400 Subject: [PATCH 1/6] Intake base --- src/main/java/frc/robot/Robot.java | 4 ++- .../frc/robot/subsystems/intake/Intake.java | 35 +++++++++++++++++++ .../subsystems/intake/IntakeConstants.java | 6 ++++ .../frc/robot/subsystems/intake/IntakeIO.java | 15 ++++++++ .../robot/subsystems/intake/IntakeIOReal.java | 22 ++++++++++++ .../robot/subsystems/intake/IntakeIOSim.java | 3 ++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/java/frc/robot/subsystems/intake/Intake.java create mode 100644 src/main/java/frc/robot/subsystems/intake/IntakeConstants.java create mode 100644 src/main/java/frc/robot/subsystems/intake/IntakeIO.java create mode 100644 src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java create mode 100644 src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index ea47d35..40e9df1 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -39,11 +39,13 @@ public class Robot extends LoggedRobot { @Override public void robotInit() { // Record metadata + /* Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME); Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE); Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA); Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE); Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH); + switch (BuildConstants.DIRTY) { case 0: Logger.recordMetadata("GitDirty", "All changes committed"); @@ -54,7 +56,7 @@ public void robotInit() { default: Logger.recordMetadata("GitDirty", "Unknown"); break; - } + } */ // Set up data receivers & replay source switch (Constants.currentMode) { diff --git a/src/main/java/frc/robot/subsystems/intake/Intake.java b/src/main/java/frc/robot/subsystems/intake/Intake.java new file mode 100644 index 0000000..b7be24d --- /dev/null +++ b/src/main/java/frc/robot/subsystems/intake/Intake.java @@ -0,0 +1,35 @@ +package frc.robot.subsystems.intake; + +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class Intake extends SubsystemBase { + private IntakeIO io; + private IntakeIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged(); + private static Intake instance; + public double intakespd; + + private Intake(IntakeIO IO) { + io = IO; + } + + public static Intake getInstance() { + return instance; + } + + public static Intake initialize(IntakeIO io) { + if (instance == null) { + instance = new Intake(io); + } + return instance; + } + + public void setIntakeSpeed(double speed){ + intakespd = speed; + } + + @Override + public void periodic() { + io.updateInputs(inputs); + io.setMotorSpeed(intakespd); + } +} diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java new file mode 100644 index 0000000..78c2851 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java @@ -0,0 +1,6 @@ +package frc.robot.subsystems.intake; + +public class IntakeConstants { + public static final int CanID = 2; // .. + public static final int currentLimit = 60; // vortex +} diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java new file mode 100644 index 0000000..7a9bdb0 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java @@ -0,0 +1,15 @@ +package frc.robot.subsystems.intake; + +import org.littletonrobotics.junction.AutoLog; + +public interface IntakeIO { + @AutoLog + public static class IntakeIOInputs { + public double voltage = 0.0; // .. + } + + public default void updateInputs(IntakeIOInputs inputs) {} + + public default void setMotorSpeed(double speed) {} + +} diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java new file mode 100644 index 0000000..3ae0fe8 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java @@ -0,0 +1,22 @@ +package frc.robot.subsystems.intake; + +import com.revrobotics.CANSparkLowLevel.MotorType; +import com.revrobotics.CANSparkMax; + +public class IntakeIOReal implements IntakeIO { + private CANSparkMax IntakeMotor = new CANSparkMax(IntakeConstants.CanID, MotorType.kBrushless); + + public IntakeIOReal() { + IntakeMotor.setSmartCurrentLimit(IntakeConstants.currentLimit); + IntakeMotor.burnFlash(); + } + + @Override + public void setMotorSpeed(double speed) { + IntakeMotor.set(speed); + } + + @Override + public void updateInputs(IntakeIOInputs inputs) {} + +} diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java b/src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java new file mode 100644 index 0000000..76ae0d8 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java @@ -0,0 +1,3 @@ +package frc.robot.subsystems.intake; + +public class IntakeIOSim {} From c7c2541938e943e3a47916cde3828485690d3b81 Mon Sep 17 00:00:00 2001 From: Arenacloserr <162641455+Arenacloserr@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:04:19 -0400 Subject: [PATCH 2/6] intake updates --- .../frc/robot/subsystems/intake/Intake.java | 19 ++++++++++++++++--- .../subsystems/intake/IntakeConstants.java | 1 + .../frc/robot/subsystems/intake/IntakeIO.java | 3 ++- .../robot/subsystems/intake/IntakeIOReal.java | 5 ++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/intake/Intake.java b/src/main/java/frc/robot/subsystems/intake/Intake.java index b7be24d..28872fc 100644 --- a/src/main/java/frc/robot/subsystems/intake/Intake.java +++ b/src/main/java/frc/robot/subsystems/intake/Intake.java @@ -1,12 +1,13 @@ package frc.robot.subsystems.intake; +import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Intake extends SubsystemBase { private IntakeIO io; private IntakeIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged(); private static Intake instance; - public double intakespd; + public double intakeSpeed; private Intake(IntakeIO IO) { io = IO; @@ -24,12 +25,24 @@ public static Intake initialize(IntakeIO io) { } public void setIntakeSpeed(double speed){ - intakespd = speed; + intakeSpeed = speed; + } + + public boolean bool() { // .. + return inputs.Amps > IntakeConstants.current; + } + + public Command intake() { + return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); + } + + public Command reverse() { + return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); } @Override public void periodic() { io.updateInputs(inputs); - io.setMotorSpeed(intakespd); + io.setMotorSpeed(intakeSpeed); } } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java index 78c2851..695468c 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java @@ -3,4 +3,5 @@ public class IntakeConstants { public static final int CanID = 2; // .. public static final int currentLimit = 60; // vortex + public static final int current = 10; // .. } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java index 7a9bdb0..6c15f5f 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java @@ -5,7 +5,8 @@ public interface IntakeIO { @AutoLog public static class IntakeIOInputs { - public double voltage = 0.0; // .. + public double Voltage = 0.0; // .. + public double Amps = 0.0; } public default void updateInputs(IntakeIOInputs inputs) {} diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java index 3ae0fe8..1ef4d18 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java @@ -17,6 +17,9 @@ public void setMotorSpeed(double speed) { } @Override - public void updateInputs(IntakeIOInputs inputs) {} + public void updateInputs(IntakeIOInputs inputs) { + inputs.Voltage = IntakeMotor.getBusVoltage(); + inputs.Amps = IntakeMotor.getOutputCurrent(); + } } From 2bf52e6f956ae49851debac0ec5292476e4dde24 Mon Sep 17 00:00:00 2001 From: Arenacloserr <162641455+Arenacloserr@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:23:34 -0400 Subject: [PATCH 3/6] fix gradle --- build.gradle | 21 ++--- gradlew | 2 +- gradlew.bat | 2 +- src/main/java/frc/robot/Robot.java | 2 +- .../frc/robot/subsystems/intake/Intake.java | 82 +++++++++---------- .../subsystems/intake/IntakeConstants.java | 6 +- .../frc/robot/subsystems/intake/IntakeIO.java | 15 ++-- .../robot/subsystems/intake/IntakeIOReal.java | 29 ++++--- 8 files changed, 79 insertions(+), 80 deletions(-) diff --git a/build.gradle b/build.gradle index 51a55b2..3f19740 100644 --- a/build.gradle +++ b/build.gradle @@ -133,16 +133,17 @@ tasks.withType(JavaCompile) { } // Create version file -project.compileJava.dependsOn(createVersionFile) -gversion { - srcDir = "src/main/java/" - classPackage = "frc.robot" - className = "BuildConstants" - dateFormat = "yyyy-MM-dd HH:mm:ss z" - timeZone = "America/New_York" - indent = " " -} - +/* + project.compileJava.dependsOn(createVersionFile) + gversion { + srcDir = "src/main/java/" + classPackage = "frc.robot" + className = "BuildConstants" + dateFormat = "yyyy-MM-dd HH:mm:ss z" + timeZone = "America/New_York" + indent = " " + } + */ // Spotless formatting project.compileJava.dependsOn(spotlessApply) spotless { diff --git a/gradlew b/gradlew index 1aa94a4..31042a6 100644 --- a/gradlew +++ b/gradlew @@ -246,4 +246,4 @@ eval "set -- $( tr '\n' ' ' )" '"$@"' -exec "$JAVACMD" "$@" +exec "$JAVACMD" "$@" \ No newline at end of file diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..2578005 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -89,4 +89,4 @@ exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal -:omega +:omega \ No newline at end of file diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 40e9df1..29da16b 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -45,7 +45,7 @@ public void robotInit() { Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA); Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE); Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH); - + switch (BuildConstants.DIRTY) { case 0: Logger.recordMetadata("GitDirty", "All changes committed"); diff --git a/src/main/java/frc/robot/subsystems/intake/Intake.java b/src/main/java/frc/robot/subsystems/intake/Intake.java index 28872fc..2626a57 100644 --- a/src/main/java/frc/robot/subsystems/intake/Intake.java +++ b/src/main/java/frc/robot/subsystems/intake/Intake.java @@ -4,45 +4,45 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Intake extends SubsystemBase { - private IntakeIO io; - private IntakeIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged(); - private static Intake instance; - public double intakeSpeed; - - private Intake(IntakeIO IO) { - io = IO; - } - - public static Intake getInstance() { - return instance; - } - - public static Intake initialize(IntakeIO io) { - if (instance == null) { - instance = new Intake(io); - } - return instance; - } - - public void setIntakeSpeed(double speed){ - intakeSpeed = speed; - } - - public boolean bool() { // .. - return inputs.Amps > IntakeConstants.current; - } - - public Command intake() { - return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); - } - - public Command reverse() { - return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); - } - - @Override - public void periodic() { - io.updateInputs(inputs); - io.setMotorSpeed(intakeSpeed); - } + private IntakeIO io; + private IntakeIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged(); + private static Intake instance; + public double intakeSpeed; + + private Intake(IntakeIO IO) { + io = IO; + } + + public static Intake getInstance() { + return instance; + } + + public static Intake initialize(IntakeIO io) { + if (instance == null) { + instance = new Intake(io); + } + return instance; + } + + public void setIntakeSpeed(double speed) { + intakeSpeed = speed; + } + + public boolean bool() { // .. + return inputs.Amps > IntakeConstants.current; + } + + public Command intake() { + return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); + } + + public Command reverse() { + return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); + } + + @Override + public void periodic() { + io.updateInputs(inputs); + io.setMotorSpeed(intakeSpeed); + } } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java index 695468c..63c7e25 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java @@ -1,7 +1,7 @@ package frc.robot.subsystems.intake; public class IntakeConstants { - public static final int CanID = 2; // .. - public static final int currentLimit = 60; // vortex - public static final int current = 10; // .. + public static final int CanID = 2; // .. + public static final int currentLimit = 60; // vortex + public static final int current = 10; // .. } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java index 6c15f5f..0b783dc 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java @@ -3,14 +3,13 @@ import org.littletonrobotics.junction.AutoLog; public interface IntakeIO { - @AutoLog - public static class IntakeIOInputs { - public double Voltage = 0.0; // .. - public double Amps = 0.0; - } + @AutoLog + public static class IntakeIOInputs { + public double Voltage = 0.0; // .. + public double Amps = 0.0; + } - public default void updateInputs(IntakeIOInputs inputs) {} - - public default void setMotorSpeed(double speed) {} + public default void updateInputs(IntakeIOInputs inputs) {} + public default void setMotorSpeed(double speed) {} } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java index 1ef4d18..182d7cd 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java @@ -4,22 +4,21 @@ import com.revrobotics.CANSparkMax; public class IntakeIOReal implements IntakeIO { - private CANSparkMax IntakeMotor = new CANSparkMax(IntakeConstants.CanID, MotorType.kBrushless); + private CANSparkMax IntakeMotor = new CANSparkMax(IntakeConstants.CanID, MotorType.kBrushless); - public IntakeIOReal() { - IntakeMotor.setSmartCurrentLimit(IntakeConstants.currentLimit); - IntakeMotor.burnFlash(); - } + public IntakeIOReal() { + IntakeMotor.setSmartCurrentLimit(IntakeConstants.currentLimit); + IntakeMotor.burnFlash(); + } - @Override - public void setMotorSpeed(double speed) { - IntakeMotor.set(speed); - } - - @Override - public void updateInputs(IntakeIOInputs inputs) { - inputs.Voltage = IntakeMotor.getBusVoltage(); - inputs.Amps = IntakeMotor.getOutputCurrent(); - } + @Override + public void setMotorSpeed(double speed) { + IntakeMotor.set(speed); + } + @Override + public void updateInputs(IntakeIOInputs inputs) { + inputs.Voltage = IntakeMotor.getBusVoltage(); + inputs.Amps = IntakeMotor.getOutputCurrent(); + } } From 16a3dfcbf8a5a88d396779541b8e2cf0cf97e932 Mon Sep 17 00:00:00 2001 From: Arenacloserr <162641455+Arenacloserr@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:15:38 -0400 Subject: [PATCH 4/6] sim update --- logs/Log_453809fd5c0e7d60.wpilog | Bin 0 -> 87 bytes networktables.json | 1 + src/main/java/frc/robot/Constants.java | 2 +- .../robot/subsystems/intake/IntakeIOSim.java | 19 +++++++++++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 logs/Log_453809fd5c0e7d60.wpilog create mode 100644 networktables.json diff --git a/logs/Log_453809fd5c0e7d60.wpilog b/logs/Log_453809fd5c0e7d60.wpilog new file mode 100644 index 0000000000000000000000000000000000000000..670e6e4945aeb919a2942eb55d2a2ed339540073 GIT binary patch literal 87 zcmWF!@bvL_XJF)EU|?`eDND>NNlZ`m&MZ-2uv})t#lQ#@<^p2 Date: Thu, 10 Oct 2024 00:29:47 -0400 Subject: [PATCH 5/6] Intake update --- .../frc/robot/subsystems/intake/Intake.java | 27 ++++++++++++++++--- .../subsystems/intake/IntakeConstants.java | 2 +- .../frc/robot/subsystems/intake/IntakeIO.java | 1 + .../robot/subsystems/intake/IntakeIOReal.java | 5 ++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/intake/Intake.java b/src/main/java/frc/robot/subsystems/intake/Intake.java index 2626a57..e3ee678 100644 --- a/src/main/java/frc/robot/subsystems/intake/Intake.java +++ b/src/main/java/frc/robot/subsystems/intake/Intake.java @@ -1,13 +1,17 @@ package frc.robot.subsystems.intake; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Intake extends SubsystemBase { + private Timer noteTime = new Timer(); private IntakeIO io; private IntakeIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged(); private static Intake instance; public double intakeSpeed; + public static double time1 = 0; // static + public static boolean flag = false; private Intake(IntakeIO IO) { io = IO; @@ -28,16 +32,31 @@ public void setIntakeSpeed(double speed) { intakeSpeed = speed; } - public boolean bool() { // .. - return inputs.Amps > IntakeConstants.current; + public boolean noteNotInIntake() { // .. + if (inputs.Amps < IntakeConstants.current) { + noteTime.start(); + flag = true; + return inputs.Amps < IntakeConstants.current; + } else { + if (flag) { + time1 = noteTime.get(); + noteTime.stop(); + noteTime.reset(); + } + return inputs.Amps < IntakeConstants.current; + } } public Command intake() { - return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); + return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)).onlyWhile(() -> noteNotInIntake()); + // return (startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)).onlyWhile(() -> + // noteNotInIntake())).alongWith(startEnd(() -> setIntakeSpeed(0.1), () -> + // setIntakeSpeed(0)).onlyIf(() -> noteNotInIntake() == true).onlyWhile(() -> noteNotInIntake() + // == true)); } public Command reverse() { - return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)); + return startEnd(() -> setIntakeSpeed(-1), () -> setIntakeSpeed(0)); } @Override diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java index 63c7e25..3ac7650 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeConstants.java @@ -2,6 +2,6 @@ public class IntakeConstants { public static final int CanID = 2; // .. - public static final int currentLimit = 60; // vortex + public static final int currentLimit = 40; // vortex public static final int current = 10; // .. } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java index 0b783dc..23cc17e 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java @@ -7,6 +7,7 @@ public interface IntakeIO { public static class IntakeIOInputs { public double Voltage = 0.0; // .. public double Amps = 0.0; + public double noteTime = 0.0; } public default void updateInputs(IntakeIOInputs inputs) {} diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java index 182d7cd..589f255 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIOReal.java @@ -2,9 +2,11 @@ import com.revrobotics.CANSparkLowLevel.MotorType; import com.revrobotics.CANSparkMax; +import com.revrobotics.RelativeEncoder; public class IntakeIOReal implements IntakeIO { private CANSparkMax IntakeMotor = new CANSparkMax(IntakeConstants.CanID, MotorType.kBrushless); + private final RelativeEncoder IntakEncoder = IntakeMotor.getEncoder(); public IntakeIOReal() { IntakeMotor.setSmartCurrentLimit(IntakeConstants.currentLimit); @@ -18,7 +20,10 @@ public void setMotorSpeed(double speed) { @Override public void updateInputs(IntakeIOInputs inputs) { + inputs.angularVelocityRPM = IntakEncoder.getVelocity(); + inputs.angularPositionRot = IntakEncoder.getPosition(); inputs.Voltage = IntakeMotor.getBusVoltage(); inputs.Amps = IntakeMotor.getOutputCurrent(); + inputs.noteTime = Intake.time1; } } From d80f603feba4131bdb4020be00ffccc7f09d8be5 Mon Sep 17 00:00:00 2001 From: Arenacloserr <162641455+Arenacloserr@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:16:47 -0400 Subject: [PATCH 6/6] Intake Timer --- src/main/java/frc/robot/RobotContainer.java | 8 ++++++++ .../frc/robot/subsystems/intake/Intake.java | 17 +++++++++++++---- .../frc/robot/subsystems/intake/IntakeIO.java | 2 ++ .../robot/subsystems/intake/IntakeIOSim.java | 5 ++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 8159492..173f7d4 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -34,6 +34,9 @@ import frc.robot.subsystems.flywheel.FlywheelIO; import frc.robot.subsystems.flywheel.FlywheelIOSim; import frc.robot.subsystems.flywheel.FlywheelIOSparkMax; +import frc.robot.subsystems.intake.Intake; +import frc.robot.subsystems.intake.IntakeIOReal; +import frc.robot.subsystems.intake.IntakeIOSim; import org.littletonrobotics.junction.networktables.LoggedDashboardChooser; import org.littletonrobotics.junction.networktables.LoggedDashboardNumber; @@ -69,6 +72,7 @@ public RobotContainer() { new ModuleIOSparkMax(2), new ModuleIOSparkMax(3)); flywheel = new Flywheel(new FlywheelIOSparkMax()); + Intake.initialize(new IntakeIOReal()); // drive = new Drive( // new GyroIOPigeon2(), // new ModuleIOTalonFX(0), @@ -88,6 +92,8 @@ public RobotContainer() { new ModuleIOSim(), new ModuleIOSim()); flywheel = new Flywheel(new FlywheelIOSim()); + Intake.initialize(new IntakeIOSim()); + break; default: @@ -165,6 +171,8 @@ private void configureButtonBindings() { .whileTrue( Commands.startEnd( () -> flywheel.runVelocity(flywheelSpeedInput.get()), flywheel::stop, flywheel)); + controller.leftTrigger().whileTrue(Intake.getInstance().intake()); + // controller.rightTrigger().whileTrue(Intake.getInstance().spike()); } /** diff --git a/src/main/java/frc/robot/subsystems/intake/Intake.java b/src/main/java/frc/robot/subsystems/intake/Intake.java index e3ee678..adc7444 100644 --- a/src/main/java/frc/robot/subsystems/intake/Intake.java +++ b/src/main/java/frc/robot/subsystems/intake/Intake.java @@ -3,14 +3,16 @@ import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import org.littletonrobotics.junction.Logger; public class Intake extends SubsystemBase { private Timer noteTime = new Timer(); private IntakeIO io; - private IntakeIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged(); + private final IntakeIOInputsAutoLogged inputs = new IntakeIOInputsAutoLogged(); private static Intake instance; public double intakeSpeed; public static double time1 = 0; // static + private double testamps = 0; public static boolean flag = false; private Intake(IntakeIO IO) { @@ -48,20 +50,27 @@ public boolean noteNotInIntake() { // .. } public Command intake() { - return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)).onlyWhile(() -> noteNotInIntake()); + return startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)) + .onlyWhile(() -> noteNotInIntake()); // return (startEnd(() -> setIntakeSpeed(1), () -> setIntakeSpeed(0)).onlyWhile(() -> // noteNotInIntake())).alongWith(startEnd(() -> setIntakeSpeed(0.1), () -> // setIntakeSpeed(0)).onlyIf(() -> noteNotInIntake() == true).onlyWhile(() -> noteNotInIntake() // == true)); } - +/* + public Command spike() { + return startEnd(() -> testamps = 150, () -> testamps = 0); + } +*/ public Command reverse() { return startEnd(() -> setIntakeSpeed(-1), () -> setIntakeSpeed(0)); } @Override public void periodic() { - io.updateInputs(inputs); + Logger.recordOutput("Intake/testamps", testamps); io.setMotorSpeed(intakeSpeed); + io.updateInputs(inputs); + Logger.processInputs("Intake", inputs); } } diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java index 23cc17e..9289b8f 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIO.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIO.java @@ -5,6 +5,8 @@ public interface IntakeIO { @AutoLog public static class IntakeIOInputs { + public double angularVelocityRPM = 0.0; + public double angularPositionRot = 0.0; public double Voltage = 0.0; // .. public double Amps = 0.0; public double noteTime = 0.0; diff --git a/src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java b/src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java index 07bf5c4..7e878ba 100644 --- a/src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java +++ b/src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java @@ -8,9 +8,12 @@ public class IntakeIOSim implements IntakeIO { @Override public void updateInputs(IntakeIOInputs inputs) { - motor.update(0.01); + motor.update(0.02); + inputs.angularPositionRot = motor.getAngularPositionRotations(); + inputs.angularVelocityRPM = motor.getAngularVelocityRPM(); inputs.Amps = motor.getCurrentDrawAmps(); + inputs.noteTime = Intake.time1; } @Override