From ccb53c1383e3476617353d91ae3fa3918f88b33f Mon Sep 17 00:00:00 2001 From: SketchyBoi Date: Tue, 1 Nov 2022 17:03:27 -0700 Subject: [PATCH 1/4] remove shooter --- src/main/java/frc/robot/Constants.java | 5 +-- src/main/java/frc/robot/RobotContainer.java | 4 +- .../java/frc/robot/commands/UpperShoot.java | 40 ------------------- .../java/frc/robot/subsystems/Shooter.java | 22 ---------- 4 files changed, 2 insertions(+), 69 deletions(-) delete mode 100644 src/main/java/frc/robot/commands/UpperShoot.java delete mode 100644 src/main/java/frc/robot/subsystems/Shooter.java diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 0a6876c..0769bae 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -14,9 +14,6 @@ */ public final class Constants { public static final class Shooter { - public static final int right_shooter_motor = 15; - public static final int left_shooter_motor = 16; - public static final double upper_speed = 0.5; - public static final double lower_speed = 0.2; + } } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 92b59e2..e5abd4e 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -39,9 +39,7 @@ public RobotContainer() { * edu.wpi.first.wpilibj2.command.button.JoystickButton}. */ private void configureButtonBindings() { - XboxController exBox = new XboxController(0); - JoystickButton joySteck = new JoystickButton(exBox, Button.kY.value); - joySteck.whenHeld(shooterCommand); + } /** diff --git a/src/main/java/frc/robot/commands/UpperShoot.java b/src/main/java/frc/robot/commands/UpperShoot.java deleted file mode 100644 index b6741b5..0000000 --- a/src/main/java/frc/robot/commands/UpperShoot.java +++ /dev/null @@ -1,40 +0,0 @@ -package frc.robot.commands; - -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj2.command.CommandBase; -import frc.robot.Constants; -import frc.robot.subsystems.Shooter; - -public class UpperShoot extends CommandBase{ - private Shooter shot; - Timer timeIt = new Timer(); - public UpperShoot(Shooter asdf) { - shot = asdf; - } - @Override - public void initialize() { - shot.setSpeed(0); - timeIt.start(); - } - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - shot.setSpeed(Constants.Shooter.upper_speed); - } - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) { - shot.setSpeed(0); - } - - // Returns true when the command should end. - @Override - public boolean isFinished() { - if (timeIt.get() > 5) - { - return true; - } - return false; - } -} diff --git a/src/main/java/frc/robot/subsystems/Shooter.java b/src/main/java/frc/robot/subsystems/Shooter.java deleted file mode 100644 index a8adc86..0000000 --- a/src/main/java/frc/robot/subsystems/Shooter.java +++ /dev/null @@ -1,22 +0,0 @@ -package frc.robot.subsystems; - -import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; -import edu.wpi.first.wpilibj2.command.SubsystemBase; -import frc.robot.Constants; -import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; - -public class Shooter extends SubsystemBase { - private WPI_TalonFX leftMotor = new WPI_TalonFX(Constants.Shooter.left_shooter_motor); - private WPI_TalonFX rightMotor = new WPI_TalonFX(Constants.Shooter.right_shooter_motor); - //class name is same as setter - public Shooter() { - leftMotor.setInverted(true); - rightMotor.setInverted(false); - } - - private MotorControllerGroup shoot = new MotorControllerGroup(rightMotor, leftMotor); - public void setSpeed (double speed) - { - shoot.set(speed); - } -} From 6b67cff571e9550c13839e45c3d973de6d5d361d Mon Sep 17 00:00:00 2001 From: SketchyBoi Date: Tue, 1 Nov 2022 17:04:35 -0700 Subject: [PATCH 2/4] remove the shooter class from constants --- src/main/java/frc/robot/Constants.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 0769bae..5881026 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -13,7 +13,5 @@ * constants are needed, to reduce verbosity. */ public final class Constants { - public static final class Shooter { - } } From 981e272a3896dbd2561dbd3da608cd85be8299ba Mon Sep 17 00:00:00 2001 From: SketchyBoi Date: Wed, 2 Nov 2022 17:32:02 -0700 Subject: [PATCH 3/4] Set speed of left and right motors, bind joystick to movements of motors --- src/main/java/frc/robot/Constants.java | 9 ++- src/main/java/frc/robot/RobotContainer.java | 23 ++++---- .../java/frc/robot/commands/TankDrive.java | 55 +++++++++++++++++++ .../java/frc/robot/subsystems/Drivetrain.java | 35 ++++++++++++ .../robot/subsystems/ExampleSubsystem.java | 3 +- 5 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 src/main/java/frc/robot/commands/TankDrive.java create mode 100644 src/main/java/frc/robot/subsystems/Drivetrain.java diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 5881026..0185305 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -13,5 +13,12 @@ * constants are needed, to reduce verbosity. */ public final class Constants { - + public static final class Drivetrain + { + public static final int right_front = 13; + public static final int left_front = 11; + public static final int right_back = 14; + public static final int left_back = 12; + public static final int drive_speed = 1; + } } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index e5abd4e..6999772 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -4,13 +4,14 @@ package frc.robot; +import javax.naming.ConfigurationException; + import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.XboxController.Button; -import frc.robot.commands.ExampleCommand; -import frc.robot.commands.UpperShoot; -import frc.robot.subsystems.ExampleSubsystem; -import frc.robot.subsystems.Shooter; +import frc.robot.Constants; +import frc.robot.commands.TankDrive; +import frc.robot.subsystems.Drivetrain; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.button.JoystickButton; @@ -21,14 +22,10 @@ * subsystems, commands, and button mappings) should be declared here. */ public class RobotContainer { - // The robot's subsystems and commands are defined here... - private final Shooter shooterSubsystem = new Shooter(); - - private final UpperShoot shooterCommand = new UpperShoot(shooterSubsystem); - /** The container for the robot. Contains subsystems, OI devices, and commands. */ + // rename o drivetrain (f2 shortcut) + private final Drivetrain drivetrainSubsystem = new Drivetrain(); public RobotContainer() { - // Configure the button bindings configureButtonBindings(); } @@ -37,9 +34,11 @@ public RobotContainer() { * instantiating a {@link GenericHID} or one of its subclasses ({@link * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link * edu.wpi.first.wpilibj2.command.button.JoystickButton}. - */ + */ private void configureButtonBindings() { - + XboxController pilot = new XboxController(0); + + drivetrainSubsystem.setDefaultCommand(new TankDrive(drivetrainSubsystem, pilot::getLeftY, pilot::getRightY)); } /** diff --git a/src/main/java/frc/robot/commands/TankDrive.java b/src/main/java/frc/robot/commands/TankDrive.java new file mode 100644 index 0000000..6c27334 --- /dev/null +++ b/src/main/java/frc/robot/commands/TankDrive.java @@ -0,0 +1,55 @@ +package frc.robot.commands; + +import java.util.function.DoublePredicate; +import java.util.function.DoubleSupplier; + +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.Constants; +import frc.robot.subsystems.Drivetrain; + +public class TankDrive extends CommandBase { + @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) + private final Drivetrain drivetrain; + private DoubleSupplier left; + private DoubleSupplier right; + + /** + * Creates a new ExampleCommand. + * + * @param subsystem The subsystem used by this command. + */ + + // bcz this keyword, u can use left and right in params + public TankDrive(Drivetrain drivetrainl, DoubleSupplier leftl, DoubleSupplier rightl) { + this.drivetrain = drivetrainl; + this.left = leftl; + this.right = rightl; + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(drivetrainl); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + drivetrain.setSpeed(0, 0); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + drivetrain.setSpeed(left.getAsDouble(), right.getAsDouble()); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + drivetrain.setSpeed(0, 0); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } + } diff --git a/src/main/java/frc/robot/subsystems/Drivetrain.java b/src/main/java/frc/robot/subsystems/Drivetrain.java new file mode 100644 index 0000000..de6685e --- /dev/null +++ b/src/main/java/frc/robot/subsystems/Drivetrain.java @@ -0,0 +1,35 @@ +package frc.robot.subsystems; + +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.Constants; + +import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; + +public class Drivetrain extends SubsystemBase{ + private WPI_TalonFX rightFrontMotor = new WPI_TalonFX(Constants.Drivetrain.right_front); + private WPI_TalonFX leftFrontMotor = new WPI_TalonFX(Constants.Drivetrain.left_front); + private WPI_TalonFX rightBackMotor = new WPI_TalonFX(Constants.Drivetrain.right_back); + private WPI_TalonFX leftBackMotor = new WPI_TalonFX(Constants.Drivetrain.left_back); + + + public Drivetrain () + { + // use motorcontroller groups for inversions + rightFrontMotor.setInverted(true); + leftFrontMotor.setInverted(false); + rightBackMotor.setInverted(true); + leftBackMotor.setInverted(false); + } + + // move to above constructor (alt arrows) + private MotorControllerGroup leftDrive = new MotorControllerGroup(leftFrontMotor, leftBackMotor); + private MotorControllerGroup rightDrive = new MotorControllerGroup(rightFrontMotor, rightBackMotor); + + // speed & speed2 should be more specific + public void setSpeed (double speed, double speed2) + { + leftDrive.set(speed); + rightDrive.set(speed2); + } +} diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem.java index f5e9470..572ac64 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem.java @@ -4,11 +4,12 @@ package frc.robot.subsystems; +import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; +import frc.robot.Constants; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class ExampleSubsystem extends SubsystemBase { /** Creates a new ExampleSubsystem. */ - public ExampleSubsystem() {} @Override public void periodic() { From 0b89cfdb35d61458ded9c402a8ff67cfdf3c7b97 Mon Sep 17 00:00:00 2001 From: SketchyBoi Date: Wed, 2 Nov 2022 17:39:11 -0700 Subject: [PATCH 4/4] Changed name for drivetrainsubsystem, move motorcontrollergroup up --- src/main/java/frc/robot/RobotContainer.java | 4 ++-- .../java/frc/robot/subsystems/Drivetrain.java | 23 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 6999772..84456d7 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -24,7 +24,7 @@ public class RobotContainer { // rename o drivetrain (f2 shortcut) - private final Drivetrain drivetrainSubsystem = new Drivetrain(); + private final Drivetrain drivetrain = new Drivetrain(); public RobotContainer() { configureButtonBindings(); } @@ -38,7 +38,7 @@ public RobotContainer() { private void configureButtonBindings() { XboxController pilot = new XboxController(0); - drivetrainSubsystem.setDefaultCommand(new TankDrive(drivetrainSubsystem, pilot::getLeftY, pilot::getRightY)); + drivetrain.setDefaultCommand(new TankDrive(drivetrain, pilot::getLeftY, pilot::getRightY)); } /** diff --git a/src/main/java/frc/robot/subsystems/Drivetrain.java b/src/main/java/frc/robot/subsystems/Drivetrain.java index de6685e..0d9db84 100644 --- a/src/main/java/frc/robot/subsystems/Drivetrain.java +++ b/src/main/java/frc/robot/subsystems/Drivetrain.java @@ -11,25 +11,18 @@ public class Drivetrain extends SubsystemBase{ private WPI_TalonFX leftFrontMotor = new WPI_TalonFX(Constants.Drivetrain.left_front); private WPI_TalonFX rightBackMotor = new WPI_TalonFX(Constants.Drivetrain.right_back); private WPI_TalonFX leftBackMotor = new WPI_TalonFX(Constants.Drivetrain.left_back); - + + private MotorControllerGroup leftDrive = new MotorControllerGroup(leftFrontMotor, leftBackMotor); + private MotorControllerGroup rightDrive = new MotorControllerGroup(rightFrontMotor, rightBackMotor); public Drivetrain () { - // use motorcontroller groups for inversions - rightFrontMotor.setInverted(true); - leftFrontMotor.setInverted(false); - rightBackMotor.setInverted(true); - leftBackMotor.setInverted(false); + rightDrive.setInverted(true); + leftDrive.setInverted(false); } - - // move to above constructor (alt arrows) - private MotorControllerGroup leftDrive = new MotorControllerGroup(leftFrontMotor, leftBackMotor); - private MotorControllerGroup rightDrive = new MotorControllerGroup(rightFrontMotor, rightBackMotor); - - // speed & speed2 should be more specific - public void setSpeed (double speed, double speed2) + public void setSpeed (double leftSpeed, double rightSpeed) { - leftDrive.set(speed); - rightDrive.set(speed2); + leftDrive.set(leftSpeed); + rightDrive.set(rightSpeed); } }