From 3b0abebabd1c605394f516cc8940708fd8f77264 Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:21:14 -0600 Subject: [PATCH 1/9] Nuke the drive subsystem --- src/main/java/frc4388/robot/Constants.java | 10 --- .../java/frc4388/robot/RobotContainer.java | 9 -- src/main/java/frc4388/robot/RobotMap.java | 31 ------- .../java/frc4388/robot/subsystems/Drive.java | 85 ------------------- 4 files changed, 135 deletions(-) delete mode 100644 src/main/java/frc4388/robot/subsystems/Drive.java diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java index d92d66b..2b03c61 100644 --- a/src/main/java/frc4388/robot/Constants.java +++ b/src/main/java/frc4388/robot/Constants.java @@ -18,16 +18,6 @@ import frc4388.utility.LEDPatterns; * constants are needed, to reduce verbosity. */ public final class Constants { - public static final class DriveConstants { - public static final int DRIVE_LEFT_FRONT_CAN_ID = 2; - public static final int DRIVE_RIGHT_FRONT_CAN_ID = 4; - public static final int DRIVE_LEFT_BACK_CAN_ID = 3; - public static final int DRIVE_RIGHT_BACK_CAN_ID = 5; - - public static final int DRIVE_PIGEON_ID = 6; - - public static final int SMARTDASHBOARD_UPDATE_FRAME = 2; - } public static final class LEDConstants { public static final int LED_SPARK_ID = 0; diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index b7542bc..99f5cb1 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -13,7 +13,6 @@ import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.button.JoystickButton; import frc4388.robot.Constants.*; -import frc4388.robot.subsystems.Drive; import frc4388.robot.subsystems.LED; import frc4388.utility.LEDPatterns; import frc4388.utility.controller.IHandController; @@ -31,9 +30,6 @@ public class RobotContainer { private final RobotMap m_robotMap = new RobotMap(); /* Subsystems */ - private final Drive m_robotDrive = new Drive(m_robotMap.leftFrontMotor, m_robotMap.rightFrontMotor, - m_robotMap.leftBackMotor, m_robotMap.rightBackMotor, m_robotMap.driveTrain, m_robotMap.gyroDrive); - private final LED m_robotLED = new LED(m_robotMap.LEDController); /* Controllers */ @@ -48,9 +44,6 @@ public class RobotContainer { /* Default Commands */ // drives the robot with a two-axis input from the driver controller - m_robotDrive.setDefaultCommand( - new RunCommand(() -> m_robotDrive.driveWithInput(getDriverController().getLeftYAxis(), - getDriverController().getRightXAxis()), m_robotDrive)); // continually sends updates to the Blinkin LED controller to keep the lights on m_robotLED.setDefaultCommand(new RunCommand(() -> m_robotLED.updateLED(), m_robotLED)); } @@ -64,8 +57,6 @@ public class RobotContainer { private void configureButtonBindings() { /* Driver Buttons */ // test command to spin the robot while pressing A on the driver controller - new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON) - .whileHeld(() -> m_robotDrive.driveWithInput(0, 1)); /* Operator Buttons */ // activates "Lit Mode" diff --git a/src/main/java/frc4388/robot/RobotMap.java b/src/main/java/frc4388/robot/RobotMap.java index 3456b71..cd2ca95 100644 --- a/src/main/java/frc4388/robot/RobotMap.java +++ b/src/main/java/frc4388/robot/RobotMap.java @@ -36,36 +36,5 @@ public class RobotMap { } - /* Drive Subsystem */ - public final WPI_TalonFX leftFrontMotor = new WPI_TalonFX(DriveConstants.DRIVE_LEFT_FRONT_CAN_ID); - public final WPI_TalonFX rightFrontMotor = new WPI_TalonFX(DriveConstants.DRIVE_RIGHT_FRONT_CAN_ID); - public final WPI_TalonFX leftBackMotor = new WPI_TalonFX(DriveConstants.DRIVE_LEFT_BACK_CAN_ID); - public final WPI_TalonFX rightBackMotor = new WPI_TalonFX(DriveConstants.DRIVE_RIGHT_BACK_CAN_ID); - public final DifferentialDrive driveTrain = new DifferentialDrive(leftFrontMotor, rightFrontMotor); - public final RobotGyro gyroDrive = new RobotGyro(new PigeonIMU(DriveConstants.DRIVE_PIGEON_ID)); - void configureDriveMotorControllers() { - - /* factory default values */ - leftFrontMotor.configFactoryDefault(); - rightFrontMotor.configFactoryDefault(); - leftBackMotor.configFactoryDefault(); - rightBackMotor.configFactoryDefault(); - - /* set back motors as followers */ - leftBackMotor.follow(leftFrontMotor); - rightBackMotor.follow(rightFrontMotor); - - /* set neutral mode */ - leftFrontMotor.setNeutralMode(NeutralMode.Brake); - rightFrontMotor.setNeutralMode(NeutralMode.Brake); - leftFrontMotor.setNeutralMode(NeutralMode.Brake); - rightFrontMotor.setNeutralMode(NeutralMode.Brake); - - /* flip input so forward becomes back, etc */ - leftFrontMotor.setInverted(false); - rightFrontMotor.setInverted(false); - leftBackMotor.setInverted(InvertType.FollowMaster); - rightBackMotor.setInverted(InvertType.FollowMaster); - } } diff --git a/src/main/java/frc4388/robot/subsystems/Drive.java b/src/main/java/frc4388/robot/subsystems/Drive.java deleted file mode 100644 index 9bbdee7..0000000 --- a/src/main/java/frc4388/robot/subsystems/Drive.java +++ /dev/null @@ -1,85 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package frc4388.robot.subsystems; - -import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; - -import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -import frc4388.robot.Constants.DriveConstants; -import frc4388.utility.RobotGyro; -import frc4388.utility.RobotTime; - -/** - * Add your docs here. - */ -public class Drive extends SubsystemBase { - // Put methods for controlling this subsystem - // here. Call these from Commands. - - private RobotTime m_robotTime = RobotTime.getInstance(); - - private WPI_TalonFX m_leftFrontMotor; - private WPI_TalonFX m_rightFrontMotor; - private WPI_TalonFX m_leftBackMotor; - private WPI_TalonFX m_rightBackMotor; - private DifferentialDrive m_driveTrain; - private RobotGyro m_gyro; - - /** - * Add your docs here. - */ - public Drive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, - WPI_TalonFX rightBackMotor, DifferentialDrive driveTrain, RobotGyro gyro) { - - m_leftFrontMotor = leftFrontMotor; - m_rightFrontMotor = rightFrontMotor; - m_leftBackMotor = leftBackMotor; - m_rightBackMotor = rightBackMotor; - m_driveTrain = driveTrain; - m_gyro = gyro; - } - - @Override - public void periodic() { - m_gyro.updatePigeonDeltas(); - - if (m_robotTime.m_frameNumber % DriveConstants.SMARTDASHBOARD_UPDATE_FRAME == 0) { - updateSmartDashboard(); - } - } - - /** - * Add your docs here. - */ - public void driveWithInput(double move, double steer) { - m_driveTrain.arcadeDrive(move, steer); - } - - /** - * Add your docs here. - */ - public void tankDriveWithInput(double leftMove, double rightMove) { - m_leftFrontMotor.set(leftMove); - m_rightFrontMotor.set(rightMove); - } - - /** - * Add your docs here. - */ - private void updateSmartDashboard() { - - // Examples of the functionality of RobotGyro - SmartDashboard.putBoolean("Is Gyro a Pigeon?", m_gyro.m_isGyroAPigeon); - SmartDashboard.putNumber("Turn Rate", m_gyro.getRate()); - SmartDashboard.putNumber("Gyro Pitch", m_gyro.getPitch()); - SmartDashboard.putData(m_gyro); - } -} From 7a7f21c4622f2cb1b1b299cf4ab3ed2a0459d356 Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:24:48 -0600 Subject: [PATCH 2/9] fix bracket --- src/main/java/frc4388/robot/RobotMap.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/frc4388/robot/RobotMap.java b/src/main/java/frc4388/robot/RobotMap.java index cd2ca95..610b642 100644 --- a/src/main/java/frc4388/robot/RobotMap.java +++ b/src/main/java/frc4388/robot/RobotMap.java @@ -37,4 +37,5 @@ public class RobotMap { } void configureDriveMotorControllers() { + } } From fb99aa962c7586c17f55baa8369b5214f585ddb6 Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:34:58 -0600 Subject: [PATCH 3/9] fix importing somthing that doesn't exist --- src/main/java/frc4388/robot/RobotMap.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/frc4388/robot/RobotMap.java b/src/main/java/frc4388/robot/RobotMap.java index 610b642..4bec615 100644 --- a/src/main/java/frc4388/robot/RobotMap.java +++ b/src/main/java/frc4388/robot/RobotMap.java @@ -14,7 +14,6 @@ import com.ctre.phoenix.sensors.PigeonIMU; import edu.wpi.first.wpilibj.Spark; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import frc4388.robot.Constants.DriveConstants; import frc4388.robot.Constants.LEDConstants; import frc4388.utility.RobotGyro; From a157b06d4219e7eb9c79a7cce827e2f4674cdef3 Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:40:23 -0600 Subject: [PATCH 4/9] realize we need DriveConstants with a Pigeon id --- src/main/java/frc4388/robot/Constants.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java index 2b03c61..d50cd10 100644 --- a/src/main/java/frc4388/robot/Constants.java +++ b/src/main/java/frc4388/robot/Constants.java @@ -18,7 +18,12 @@ import frc4388.utility.LEDPatterns; * constants are needed, to reduce verbosity. */ public final class Constants { + public static final class DriveConstants { + public static final int DRIVE_PIGEON_ID = 6; + public static final int SMARTDASHBOARD_UPDATE_FRAME = 2; + } + public static final class LEDConstants { public static final int LED_SPARK_ID = 0; From c232f15f0a6b21acbadb9655a66f579a8414c53b Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Tue, 1 Nov 2022 16:38:27 -0600 Subject: [PATCH 5/9] DifferentalDrive.java --- .../robot/subsystems/DifferentialDrive.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/main/java/frc4388/robot/subsystems/DifferentialDrive.java diff --git a/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java b/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java new file mode 100644 index 0000000..9e849af --- /dev/null +++ b/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java @@ -0,0 +1,85 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.robot.subsystems; + +import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; + +import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +import frc4388.robot.Constants.DriveConstants; +import frc4388.utility.RobotGyro; +import frc4388.utility.RobotTime; + +/** + * Add your docs here. + */ +public class DifferentialDrive extends SubsystemBase { + // Put methods for controlling this subsystem + // here. Call these from Commands. + + private RobotTime m_robotTime = RobotTime.getInstance(); + + private WPI_TalonFX m_leftFrontMotor; + private WPI_TalonFX m_rightFrontMotor; + private WPI_TalonFX m_leftBackMotor; + private WPI_TalonFX m_rightBackMotor; + private DifferentialDrive m_driveTrain; + private RobotGyro m_gyro; + + /** + * Add your docs here. + */ + public Drive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, + WPI_TalonFX rightBackMotor, DifferentialDrive driveTrain, RobotGyro gyro) { + + m_leftFrontMotor = leftFrontMotor; + m_rightFrontMotor = rightFrontMotor; + m_leftBackMotor = leftBackMotor; + m_rightBackMotor = rightBackMotor; + m_driveTrain = driveTrain; + m_gyro = gyro; + } + + @Override + public void periodic() { + m_gyro.updatePigeonDeltas(); + + if (m_robotTime.m_frameNumber % DriveConstants.SMARTDASHBOARD_UPDATE_FRAME == 0) { + updateSmartDashboard(); + } + } + + /** + * Add your docs here. + */ + public void driveWithInput(double move, double steer) { + m_driveTrain.arcadeDrive(move, steer); + } + + /** + * Add your docs here. + */ + public void tankDriveWithInput(double leftMove, double rightMove) { + m_leftFrontMotor.set(leftMove); + m_rightFrontMotor.set(rightMove); + } + + /** + * Add your docs here. + */ + private void updateSmartDashboard() { + + // Examples of the functionality of RobotGyro + SmartDashboard.putBoolean("Is Gyro a Pigeon?", m_gyro.m_isGyroAPigeon); + SmartDashboard.putNumber("Turn Rate", m_gyro.getRate()); + SmartDashboard.putNumber("Gyro Pitch", m_gyro.getPitch()); + SmartDashboard.putData(m_gyro); + } +} From 453334d5155e9d480756c3d7f5ed42e854f9ece8 Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Tue, 1 Nov 2022 16:43:18 -0600 Subject: [PATCH 6/9] DifferentalDrive.java II --- src/main/java/frc4388/robot/subsystems/DifferentialDrive.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java b/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java index 9e849af..21c4083 100644 --- a/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java +++ b/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java @@ -36,7 +36,7 @@ public class DifferentialDrive extends SubsystemBase { /** * Add your docs here. */ - public Drive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, + public DifferentialDrive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, WPI_TalonFX rightBackMotor, DifferentialDrive driveTrain, RobotGyro gyro) { m_leftFrontMotor = leftFrontMotor; From 948dba2ab7627839c3e809ebf53e746e6dae37b7 Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Tue, 1 Nov 2022 16:48:00 -0600 Subject: [PATCH 7/9] DifDrive.java --- .../subsystems/{DifferentialDrive.java => DifDrive.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/java/frc4388/robot/subsystems/{DifferentialDrive.java => DifDrive.java} (93%) diff --git a/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java b/src/main/java/frc4388/robot/subsystems/DifDrive.java similarity index 93% rename from src/main/java/frc4388/robot/subsystems/DifferentialDrive.java rename to src/main/java/frc4388/robot/subsystems/DifDrive.java index 21c4083..c0b35fe 100644 --- a/src/main/java/frc4388/robot/subsystems/DifferentialDrive.java +++ b/src/main/java/frc4388/robot/subsystems/DifDrive.java @@ -20,7 +20,7 @@ import frc4388.utility.RobotTime; /** * Add your docs here. */ -public class DifferentialDrive extends SubsystemBase { +public class DifDrive extends SubsystemBase { // Put methods for controlling this subsystem // here. Call these from Commands. @@ -36,7 +36,7 @@ public class DifferentialDrive extends SubsystemBase { /** * Add your docs here. */ - public DifferentialDrive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, + public DifDrive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, WPI_TalonFX rightBackMotor, DifferentialDrive driveTrain, RobotGyro gyro) { m_leftFrontMotor = leftFrontMotor; From 7965a25392caf911871f940aa76d0f5d91d900e9 Mon Sep 17 00:00:00 2001 From: C4llSqin <83995467+C4llSqin@users.noreply.github.com> Date: Tue, 1 Nov 2022 17:15:52 -0600 Subject: [PATCH 8/9] DiffDrive.java --- .../robot/subsystems/{DifDrive.java => DiffDrive.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/java/frc4388/robot/subsystems/{DifDrive.java => DiffDrive.java} (94%) diff --git a/src/main/java/frc4388/robot/subsystems/DifDrive.java b/src/main/java/frc4388/robot/subsystems/DiffDrive.java similarity index 94% rename from src/main/java/frc4388/robot/subsystems/DifDrive.java rename to src/main/java/frc4388/robot/subsystems/DiffDrive.java index c0b35fe..a791913 100644 --- a/src/main/java/frc4388/robot/subsystems/DifDrive.java +++ b/src/main/java/frc4388/robot/subsystems/DiffDrive.java @@ -20,7 +20,7 @@ import frc4388.utility.RobotTime; /** * Add your docs here. */ -public class DifDrive extends SubsystemBase { +public class DiffDrive extends SubsystemBase { // Put methods for controlling this subsystem // here. Call these from Commands. @@ -36,7 +36,7 @@ public class DifDrive extends SubsystemBase { /** * Add your docs here. */ - public DifDrive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, + public DiffDrive(WPI_TalonFX leftFrontMotor, WPI_TalonFX rightFrontMotor, WPI_TalonFX leftBackMotor, WPI_TalonFX rightBackMotor, DifferentialDrive driveTrain, RobotGyro gyro) { m_leftFrontMotor = leftFrontMotor; From 37004be0ee93862b649606f6777aeeff2e1be817 Mon Sep 17 00:00:00 2001 From: Aarav Shah Date: Tue, 1 Nov 2022 17:32:01 -0600 Subject: [PATCH 9/9] Create RobotUnits.java --- src/main/java/frc4388/utility/RobotUnits.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/frc4388/utility/RobotUnits.java diff --git a/src/main/java/frc4388/utility/RobotUnits.java b/src/main/java/frc4388/utility/RobotUnits.java new file mode 100644 index 0000000..9e07312 --- /dev/null +++ b/src/main/java/frc4388/utility/RobotUnits.java @@ -0,0 +1,27 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package frc4388.utility; + +/** Aarav's good units class (better than WPILib) + * @author Aarav Shah */ + +public class RobotUnits { + // constants + + // angle conversions + public static double degreesToRadians(final double degrees) {return degrees * Math.PI / 180;} + + public static double radiansToDegrees(final double radians) {return radians / Math.PI * 180;} + + // falcon conversions + public static double falconTicksToRotations(final double ticks) {return ticks / 2048;} + + public static double falconRotationsToTicks(final double rotations) {return rotations * 2048;} + + // distance conversions + public static double metersToFeet(final double meters) {return meters * 3.28084;} + + public static double feetToMeters(final double feet) {return feet / 3.28084;} +} \ No newline at end of file