From 8599343ac989e548b02aaa8be3dd03fb28d95025 Mon Sep 17 00:00:00 2001 From: 73anthonyL <73anthony.lu@gmail.com> Date: Tue, 1 Jul 2025 21:30:35 -0700 Subject: [PATCH 1/2] first commit --- .../frc/robot/subsystems/TankDriveSubsystem.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/frc/robot/subsystems/TankDriveSubsystem.java diff --git a/src/main/java/frc/robot/subsystems/TankDriveSubsystem.java b/src/main/java/frc/robot/subsystems/TankDriveSubsystem.java new file mode 100644 index 0000000..76a05cb --- /dev/null +++ b/src/main/java/frc/robot/subsystems/TankDriveSubsystem.java @@ -0,0 +1,14 @@ +// Instructions: +// 1. create a branch off of this branch and title it firstname-lastname-week-4 +// 2. you are responsible for instantiating the two motors for this subsystem +// 3. you are responsible for applying stator and supply current limits +// for each of the motors (recommended 65 Amp stator current limits & 30 Amp limit for supply) +// 4. use the appropriate control mode for running the Tank Drive (and leave a comment for why you are using it) +// Hint: besides defining the motors in the constructor, the main method that your Tank Drive +// needs takes in input to drive the left and right motors each with a control request + +package frc.robot.subsystems; + +public class TankDriveSubsystem { + +} From df50c2ab530c6263962ac69aed8ec2b8b78a9ceb Mon Sep 17 00:00:00 2001 From: Violet Su Date: Mon, 7 Jul 2025 16:41:15 -0700 Subject: [PATCH 2/2] violet su week 4 hw --- .../robot/subsystems/TankDriveSubsystem.java | 54 +++++++++++++++---- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/TankDriveSubsystem.java b/src/main/java/frc/robot/subsystems/TankDriveSubsystem.java index 76a05cb..b5e3b4a 100644 --- a/src/main/java/frc/robot/subsystems/TankDriveSubsystem.java +++ b/src/main/java/frc/robot/subsystems/TankDriveSubsystem.java @@ -1,14 +1,46 @@ -// Instructions: -// 1. create a branch off of this branch and title it firstname-lastname-week-4 -// 2. you are responsible for instantiating the two motors for this subsystem -// 3. you are responsible for applying stator and supply current limits -// for each of the motors (recommended 65 Amp stator current limits & 30 Amp limit for supply) -// 4. use the appropriate control mode for running the Tank Drive (and leave a comment for why you are using it) -// Hint: besides defining the motors in the constructor, the main method that your Tank Drive -// needs takes in input to drive the left and right motors each with a control request - package frc.robot.subsystems; -public class TankDriveSubsystem { - +import com.ctre.phoenix6.configs.CurrentLimitsConfigs; +import com.ctre.phoenix6.hardware.TalonFX; +import com.ctre.phoenix6.controls.DutyCycleOut; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class TankDriveSubsystem extends SubsystemBase { + + private final TalonFX leftDriveMotor; + private final TalonFX rightDriveMotor; + + private final DutyCycleOut tankDriveControl = new DutyCycleOut(0.0); + + public TankDriveSubsystem() { + leftDriveMotor = new TalonFX(1); + rightDriveMotor = new TalonFX(2); + + CurrentLimitsConfigs currentLimitConfig = new CurrentLimitsConfigs() + .withStatorCurrentLimitEnable(true) + .withStatorCurrentLimit(65) + .withSupplyCurrentLimitEnable(true) + .withSupplyCurrentLimit(30); + + leftDriveMotor.getConfigurator().apply(currentLimitConfig); + rightDriveMotor.getConfigurator().apply(currentLimitConfig); + } + + public void tankDrive(double leftPower, double rightPower) { + leftDriveMotor.setControl(tankDriveControl.withOutput(leftPower)); + rightDriveMotor.setControl(tankDriveControl.withOutput(rightPower)); + } + + public void resetEncoders() { + leftDriveMotor.setPosition(0.0); + rightDriveMotor.setPosition(0.0); + } + + public double getLeftEncoder() { + return leftDriveMotor.getPosition().getValueAsDouble(); + } + + public double getRightEncoder() { + return rightDriveMotor.getPosition().getValueAsDouble(); + } }