From 8deefed69056bc184304c1e0ddc2364d896c0608 Mon Sep 17 00:00:00 2001 From: eerinn Date: Tue, 19 Nov 2024 16:12:22 -0800 Subject: [PATCH 1/7] elevatory --- gradlew | 0 src/main/java/frc/robot/RobotContainer.java | 18 +++++ .../robot/subsystems/ElevatorSubsystem.java | 50 +++++++++++++ vendordeps/REVLib.json | 74 +++++++++++++++++++ 4 files changed, 142 insertions(+) mode change 100644 => 100755 gradlew create mode 100644 src/main/java/frc/robot/subsystems/ElevatorSubsystem.java create mode 100644 vendordeps/REVLib.json diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 96428cb..3d7f174 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -6,7 +6,10 @@ import frc.robot.Constants.OperatorConstants; import frc.robot.subsystems.DriveSubsystem; +import frc.robot.subsystems.ElevatorSubsystem; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.ConditionalCommand; +import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.button.Trigger; @@ -18,16 +21,22 @@ * subsystems, commands, and trigger mappings) should be declared here. */ public class RobotContainer { + + private double upPosition; // The robot's subsystems and commands are defined here... private final DriveSubsystem driveSubsystem; // Replace with CommandPS4Controller or CommandJoystick if needed private final CommandXboxController driverController = new CommandXboxController(OperatorConstants.kDriverControllerPort); + + private final CommandXboxController mechController= new CommandXboxController(0); + private Trigger rightBumper = mechController.rightBumper(); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { driveSubsystem = new DriveSubsystem(); + // Configure the trigger bindings configureBindings(); } @@ -46,6 +55,15 @@ private void configureBindings() { driveSubsystem.setDrivePowers(driverController.getLeftY(), driverController.getRightY()); }, driveSubsystem)); + // rightBumper.onTrue( + // new ConditionalCommand( + + + + // ) + // ) + + } /** diff --git a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java new file mode 100644 index 0000000..e590f9d --- /dev/null +++ b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java @@ -0,0 +1,50 @@ +package frc.robot.subsystems; + + +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import com.revrobotics.CANSparkMax; +import com.revrobotics.RelativeEncoder; +import com.revrobotics.CANSparkBase; +import com.revrobotics.CANSparkLowLevel.MotorType; +import com.revrobotics.SparkPIDController; +import edu.wpi.first.wpilibj.DigitalInput; + +public class ElevatorSubsystem extends SubsystemBase{ + private CANSparkMax leftelevator; + private CANSparkMax rightelevator; + private SparkPIDController elevatorpid; + private DigitalInput limitSwitch; + private RelativeEncoder encoder; + + public ElevatorSubsystem (){ + leftelevator = new CANSparkMax (2, MotorType.kBrushless); + rightelevator = new CANSparkMax(3, MotorType.kBrushless); + elevatorpid = leftelevator.getPIDController(); + limitSwitch = new DigitalInput (0); + encoder = leftelevator.getEncoder(); + + elevatorpid.setP(0); + elevatorpid.setI(0); + elevatorpid.setD(0); + + encoder.setPosition(0); + encoder.setPositionConversionFactor(0); + encoder.setVelocityConversionFactor(0); + + + rightelevator.follow(leftelevator); + } + + public void setElevatorState(double state){ + + elevatorpid.setReference(state, CANSparkBase.ControlType.kPosition); + } + + public boolean atFloor(){ + return limitSwitch.get(); + } + + public double position(){ + return encoder.getPosition(); + } +} diff --git a/vendordeps/REVLib.json b/vendordeps/REVLib.json new file mode 100644 index 0000000..f85acd4 --- /dev/null +++ b/vendordeps/REVLib.json @@ -0,0 +1,74 @@ +{ + "fileName": "REVLib.json", + "name": "REVLib", + "version": "2024.2.4", + "frcYear": "2024", + "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", + "mavenUrls": [ + "https://maven.revrobotics.com/" + ], + "jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2024.json", + "javaDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-java", + "version": "2024.2.4" + } + ], + "jniDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-driver", + "version": "2024.2.4", + "skipInvalidPlatforms": true, + "isJar": false, + "validPlatforms": [ + "windowsx86-64", + "windowsx86", + "linuxarm64", + "linuxx86-64", + "linuxathena", + "linuxarm32", + "osxuniversal" + ] + } + ], + "cppDependencies": [ + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-cpp", + "version": "2024.2.4", + "libName": "REVLib", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "windowsx86", + "linuxarm64", + "linuxx86-64", + "linuxathena", + "linuxarm32", + "osxuniversal" + ] + }, + { + "groupId": "com.revrobotics.frc", + "artifactId": "REVLib-driver", + "version": "2024.2.4", + "libName": "REVLibDriver", + "headerClassifier": "headers", + "sharedLibrary": false, + "skipInvalidPlatforms": true, + "binaryPlatforms": [ + "windowsx86-64", + "windowsx86", + "linuxarm64", + "linuxx86-64", + "linuxathena", + "linuxarm32", + "osxuniversal" + ] + } + ] +} \ No newline at end of file From 97255e1f7d347822f22b2613985da6f577adcdf1 Mon Sep 17 00:00:00 2001 From: eerinn Date: Thu, 21 Nov 2024 14:58:34 -0800 Subject: [PATCH 2/7] elevator --- src/main/java/frc/robot/RobotContainer.java | 18 +++++++++++------- .../robot/subsystems/ElevatorSubsystem.java | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 3d7f174..648fad6 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -14,6 +14,7 @@ import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.button.Trigger; + /** * This class is where the bulk of the robot should be declared. Since Command-based is a * "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot} @@ -25,6 +26,7 @@ public class RobotContainer { private double upPosition; // The robot's subsystems and commands are defined here... private final DriveSubsystem driveSubsystem; + private final ElevatorSubsystem elevatorSubsystem; // Replace with CommandPS4Controller or CommandJoystick if needed private final CommandXboxController driverController = @@ -36,6 +38,7 @@ public class RobotContainer { /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { driveSubsystem = new DriveSubsystem(); + elevatorSubsystem = new ElevatorSubsystem(); // Configure the trigger bindings configureBindings(); @@ -55,13 +58,14 @@ private void configureBindings() { driveSubsystem.setDrivePowers(driverController.getLeftY(), driverController.getRightY()); }, driveSubsystem)); - // rightBumper.onTrue( - // new ConditionalCommand( - - - - // ) - // ) + rightBumper.onTrue( + new ConditionalCommand( + new InstantCommand(()-> elevatorSubsystem.setElevatorState(upPosition)), + new InstantCommand(()-> elevatorSubsystem.setElevatorState(0)), + ()->elevatorSubsystem.atFloor() + ) + ); + } diff --git a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java index e590f9d..4cd4f1c 100644 --- a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java @@ -1,6 +1,7 @@ package frc.robot.subsystems; +import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; import com.revrobotics.CANSparkMax; import com.revrobotics.RelativeEncoder; @@ -16,6 +17,8 @@ public class ElevatorSubsystem extends SubsystemBase{ private DigitalInput limitSwitch; private RelativeEncoder encoder; + + public ElevatorSubsystem (){ leftelevator = new CANSparkMax (2, MotorType.kBrushless); rightelevator = new CANSparkMax(3, MotorType.kBrushless); @@ -41,6 +44,7 @@ public void setElevatorState(double state){ } public boolean atFloor(){ + return limitSwitch.get(); } From 48477dab0045a558ae3abe9fb5a3f0fe7badaf17 Mon Sep 17 00:00:00 2001 From: eerinn Date: Thu, 21 Nov 2024 15:39:02 -0800 Subject: [PATCH 3/7] delete --- src/main/java/frc/robot/subsystems/ElevatorSubsystem.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java index 4cd4f1c..81ba486 100644 --- a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java @@ -30,10 +30,6 @@ public ElevatorSubsystem (){ elevatorpid.setI(0); elevatorpid.setD(0); - encoder.setPosition(0); - encoder.setPositionConversionFactor(0); - encoder.setVelocityConversionFactor(0); - rightelevator.follow(leftelevator); } From 2fa1dad225819f0fff8357503291cae640aaa798 Mon Sep 17 00:00:00 2001 From: eerinn Date: Thu, 21 Nov 2024 16:02:52 -0800 Subject: [PATCH 4/7] update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c73a804..462fb1d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2024.1.1" + id "edu.wpi.first.GradleRIO" version "2024.3.2" } java { From 2b07fcd81ccc6ed694ba59a392c5fefd3d2f925f Mon Sep 17 00:00:00 2001 From: eerinn Date: Wed, 4 Dec 2024 16:52:37 -0800 Subject: [PATCH 5/7] constants --- src/main/java/frc/robot/Constants.java | 10 ++++++++ .../robot/subsystems/ElevatorSubsystem.java | 25 ++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index c50ba05..2a14558 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -15,5 +15,15 @@ public final class Constants { public static class OperatorConstants { public static final int kDriverControllerPort = 0; + + public static final int leftelevator = 6; + public static final int rightelevator = 7; + public static final int elevatorpid = 8; + public static final int limitSwitch = 9; + + public static final int elevatorP = 0; + public static final int elevatorI = 0; + public static final int elevatorD =0; + } } diff --git a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java index 81ba486..d928cd2 100644 --- a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java @@ -3,6 +3,8 @@ import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.Constants.OperatorConstants; + import com.revrobotics.CANSparkMax; import com.revrobotics.RelativeEncoder; import com.revrobotics.CANSparkBase; @@ -20,15 +22,15 @@ public class ElevatorSubsystem extends SubsystemBase{ public ElevatorSubsystem (){ - leftelevator = new CANSparkMax (2, MotorType.kBrushless); - rightelevator = new CANSparkMax(3, MotorType.kBrushless); + leftelevator = new CANSparkMax (OperatorConstants.leftelevator, MotorType.kBrushless); + rightelevator = new CANSparkMax(OperatorConstants.rightelevator, MotorType.kBrushless); elevatorpid = leftelevator.getPIDController(); - limitSwitch = new DigitalInput (0); + limitSwitch = new DigitalInput (OperatorConstants.limitSwitch); encoder = leftelevator.getEncoder(); - elevatorpid.setP(0); - elevatorpid.setI(0); - elevatorpid.setD(0); + elevatorpid.setP(OperatorConstants.elevatorP); + elevatorpid.setI(OperatorConstants.elevatorI); + elevatorpid.setD(OperatorConstants.elevatorD); rightelevator.follow(leftelevator); @@ -47,4 +49,15 @@ public boolean atFloor(){ public double position(){ return encoder.getPosition(); } + + public void resetEncoder(){ + encoder.setPosition(0); + } + + @Override + public void periodic() { + if (atFloor()){ + resetEncoder(); + } + } } From 53579757304580b3a96607d1a6ddb98db4642474 Mon Sep 17 00:00:00 2001 From: eerinn Date: Thu, 12 Dec 2024 16:50:41 -0800 Subject: [PATCH 6/7] change elevator to 1 motor --- src/main/java/frc/robot/Constants.java | 1 - src/main/java/frc/robot/subsystems/ElevatorSubsystem.java | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 2a14558..2c979e4 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -17,7 +17,6 @@ public static class OperatorConstants { public static final int kDriverControllerPort = 0; public static final int leftelevator = 6; - public static final int rightelevator = 7; public static final int elevatorpid = 8; public static final int limitSwitch = 9; diff --git a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java index d928cd2..90a34d7 100644 --- a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java @@ -14,7 +14,6 @@ public class ElevatorSubsystem extends SubsystemBase{ private CANSparkMax leftelevator; - private CANSparkMax rightelevator; private SparkPIDController elevatorpid; private DigitalInput limitSwitch; private RelativeEncoder encoder; @@ -22,8 +21,7 @@ public class ElevatorSubsystem extends SubsystemBase{ public ElevatorSubsystem (){ - leftelevator = new CANSparkMax (OperatorConstants.leftelevator, MotorType.kBrushless); - rightelevator = new CANSparkMax(OperatorConstants.rightelevator, MotorType.kBrushless); + leftelevator = new CANSparkMax (OperatorConstants.leftelevator, MotorType.kBrushless); elevatorpid = leftelevator.getPIDController(); limitSwitch = new DigitalInput (OperatorConstants.limitSwitch); encoder = leftelevator.getEncoder(); @@ -31,9 +29,6 @@ public ElevatorSubsystem (){ elevatorpid.setP(OperatorConstants.elevatorP); elevatorpid.setI(OperatorConstants.elevatorI); elevatorpid.setD(OperatorConstants.elevatorD); - - - rightelevator.follow(leftelevator); } public void setElevatorState(double state){ From 846b9b601c8e8e4c9a4403ec9429abbf236493d6 Mon Sep 17 00:00:00 2001 From: CrolineCrois Date: Fri, 13 Dec 2024 16:12:43 -0800 Subject: [PATCH 7/7] trst cases --- src/main/java/frc/robot/Constants.java | 1 - src/main/java/frc/robot/RobotContainer.java | 10 +++++++--- .../java/frc/robot/subsystems/ElevatorSubsystem.java | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 2c979e4..5eb9022 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -17,7 +17,6 @@ public static class OperatorConstants { public static final int kDriverControllerPort = 0; public static final int leftelevator = 6; - public static final int elevatorpid = 8; public static final int limitSwitch = 9; public static final int elevatorP = 0; diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 648fad6..9c6fa5d 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -54,9 +54,9 @@ public RobotContainer() { * joysticks}. */ private void configureBindings() { - driveSubsystem.setDefaultCommand(new RunCommand(() -> { - driveSubsystem.setDrivePowers(driverController.getLeftY(), driverController.getRightY()); - }, driveSubsystem)); + // driveSubsystem.setDefaultCommand(new RunCommand(() -> { + // driveSubsystem.setDrivePowers(driverController.getLeftY(), driverController.getRightY()); + // }, driveSubsystem)); rightBumper.onTrue( new ConditionalCommand( @@ -65,6 +65,10 @@ private void configureBindings() { ()->elevatorSubsystem.atFloor() ) ); + + elevatorSubsystem.setDefaultCommand(new InstantCommand( () -> { + elevatorSubsystem.setPower(mechController.getLeftTriggerAxis()-mechController.getRightTriggerAxis()); + })); diff --git a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java index 90a34d7..00cf172 100644 --- a/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ElevatorSubsystem.java @@ -10,6 +10,8 @@ import com.revrobotics.CANSparkBase; import com.revrobotics.CANSparkLowLevel.MotorType; import com.revrobotics.SparkPIDController; + +import edu.wpi.first.math.proto.System; import edu.wpi.first.wpilibj.DigitalInput; public class ElevatorSubsystem extends SubsystemBase{ @@ -25,6 +27,7 @@ public ElevatorSubsystem (){ elevatorpid = leftelevator.getPIDController(); limitSwitch = new DigitalInput (OperatorConstants.limitSwitch); encoder = leftelevator.getEncoder(); + encoder.setPosition(0); elevatorpid.setP(OperatorConstants.elevatorP); elevatorpid.setI(OperatorConstants.elevatorI); @@ -49,6 +52,10 @@ public void resetEncoder(){ encoder.setPosition(0); } + public void setPower(double speed) { + leftelevator.set(speed); + } + @Override public void periodic() { if (atFloor()){