From bc328e3918bd68e746ee27c8254333f6c00cbaeb Mon Sep 17 00:00:00 2001 From: Computer 0 <48131223+TheGamer1002@users.noreply.github.com> Date: Wed, 5 Apr 2023 09:45:06 -0400 Subject: [PATCH] do stuff --- .../bearbots/BearLib/drivebase/Drivebase.java | 60 +++++++++++++++++++ .../BearLib/drivebase/MecanumDrivebase.java | 4 ++ .../BearLib/drivebase/SwerveDrivebase.java | 4 ++ .../BearLib/drivebase/TankDrivebase.java | 4 ++ src/main/java/frc/robot/RebindHat.java | 14 +---- .../frc/robot/commands/BalanceCommand.java | 14 +++-- src/main/java/frc/robot/subsystems/Arm.java | 19 ++---- .../{ => subsystems}/FieldConstants.java | 2 +- 8 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 src/main/java/edu/bearbots/BearLib/drivebase/Drivebase.java create mode 100644 src/main/java/edu/bearbots/BearLib/drivebase/MecanumDrivebase.java create mode 100644 src/main/java/edu/bearbots/BearLib/drivebase/SwerveDrivebase.java create mode 100644 src/main/java/edu/bearbots/BearLib/drivebase/TankDrivebase.java rename src/main/java/frc/robot/{ => subsystems}/FieldConstants.java (99%) diff --git a/src/main/java/edu/bearbots/BearLib/drivebase/Drivebase.java b/src/main/java/edu/bearbots/BearLib/drivebase/Drivebase.java new file mode 100644 index 0000000..39ef02a --- /dev/null +++ b/src/main/java/edu/bearbots/BearLib/drivebase/Drivebase.java @@ -0,0 +1,60 @@ +package edu.bearbots.BearLib.drivebase; + +import com.revrobotics.CANSparkMax; +import com.revrobotics.REVLibError; +import com.revrobotics.CANSparkMax.IdleMode; + +import java.util.Map; + +/** + * Abstract class to handle common drivebase motor controller functions. + */ +public abstract class Drivebase { + // for all drive bases? don't implement motors + // odometry + // driving + // move to + + /** + * Sets the current limit for Spark Max motor controllers, given a free limit + * and a stall limit (in amps) as well as any number of Spark Maxes. + * + * @param freeLimit The free limit (in amps) + * @param stallLimit The stall limit (in amps) + * @param motor The Spark Maxes + * @return An array of errors, if any + */ + public REVLibError[] setCurrentLimit(int freeLimit, int stallLimit, CANSparkMax... motor) { + REVLibError[] errors = new REVLibError[motor.length]; + int i = 0; + + for (CANSparkMax m : motor) { + errors[i] = m.setSmartCurrentLimit(freeLimit, stallLimit); + i++; + } + + return errors; + } + + + /** + * Sets the idle mode for Spark Max motor controllers, given an idle mode and + * any number of Spark Maxes. + * + * @param mode The idle mode + * @param motor The Spark Maxes + * @return An array of errors, if any + */ + public REVLibError[] setIdleMode(IdleMode mode, CANSparkMax... motor) { + REVLibError[] errors = new REVLibError[motor.length]; + int i = 0; + + for (CANSparkMax m : motor) { + errors[i] = m.setIdleMode(mode); + i++; + } + + return errors; + } +} +// inclue \ No newline at end of file diff --git a/src/main/java/edu/bearbots/BearLib/drivebase/MecanumDrivebase.java b/src/main/java/edu/bearbots/BearLib/drivebase/MecanumDrivebase.java new file mode 100644 index 0000000..3454ffc --- /dev/null +++ b/src/main/java/edu/bearbots/BearLib/drivebase/MecanumDrivebase.java @@ -0,0 +1,4 @@ +package edu.bearbots.BearLib.drivebase; + +public abstract class MecanumDrivebase extends Drivebase { +} \ No newline at end of file diff --git a/src/main/java/edu/bearbots/BearLib/drivebase/SwerveDrivebase.java b/src/main/java/edu/bearbots/BearLib/drivebase/SwerveDrivebase.java new file mode 100644 index 0000000..830a8e2 --- /dev/null +++ b/src/main/java/edu/bearbots/BearLib/drivebase/SwerveDrivebase.java @@ -0,0 +1,4 @@ +package edu.bearbots.BearLib.drivebase; + +public abstract class SwerveDrivebase extends Drivebase { +} \ No newline at end of file diff --git a/src/main/java/edu/bearbots/BearLib/drivebase/TankDrivebase.java b/src/main/java/edu/bearbots/BearLib/drivebase/TankDrivebase.java new file mode 100644 index 0000000..6a87612 --- /dev/null +++ b/src/main/java/edu/bearbots/BearLib/drivebase/TankDrivebase.java @@ -0,0 +1,4 @@ +package edu.bearbots.BearLib.drivebase; + +public abstract class TankDrivebase extends Drivebase { +} \ No newline at end of file diff --git a/src/main/java/frc/robot/RebindHat.java b/src/main/java/frc/robot/RebindHat.java index 42b88f4..c131f10 100644 --- a/src/main/java/frc/robot/RebindHat.java +++ b/src/main/java/frc/robot/RebindHat.java @@ -1,19 +1,11 @@ package frc.robot; + /** @deprecated */ +// dude come onthis is the deffinition fo unnesseary complecity @Deprecated public class RebindHat { public static double JoystickToYAxis() { - if (RobotContainer.m_armController.getPOV() == -1 - || RobotContainer.m_armController.getPOV() == 90 - || RobotContainer.m_armController.getPOV() == 270) { - return 0; - } - if (RobotContainer.m_armController.getPOV() > 270 - || RobotContainer.m_armController.getPOV() < 90) { - return 1; - } else { - return -1; - } + } public static double JoystickToXAxis() { diff --git a/src/main/java/frc/robot/commands/BalanceCommand.java b/src/main/java/frc/robot/commands/BalanceCommand.java index 3b6ccc5..7a3f962 100644 --- a/src/main/java/frc/robot/commands/BalanceCommand.java +++ b/src/main/java/frc/robot/commands/BalanceCommand.java @@ -11,7 +11,9 @@ import frc.robot.subsystems.PID; import frc.robot.subsystems.Tank; -/** This command balances the robot on the charge station. Default auto command. */ +/** + * This command balances the robot on the charge station. Default auto command. + */ public class BalanceCommand extends CommandBase { @SuppressWarnings({ "PMD.UnusedPrivateField", "PMD.SingularField" }) private final PID pidLoop; @@ -53,9 +55,11 @@ public void execute() { SmartDashboard.putNumber("max offset", maxPitch); SmartDashboard.putNumber( "motor speed", Constants.OperatorConstants.Pconstant * (pitchOffset)); - if (pitchOffset > maxPitch) { - maxPitch = pitchOffset; - } + /* + * if (pitchOffset > maxPitch) { + * maxPitch = pitchOffset; + * } + */ // set boolean to true when robot is on ramp to run p loop if (!onRamp && pitchOffset >= 16) { @@ -63,7 +67,6 @@ public void execute() { } if (onRamp) { - onRamp = true; // dead zone of tilt if (Math.abs(pitchOffset) < 2) { driveBase.setAllMotors(0); @@ -76,6 +79,7 @@ public void execute() { @Override public void end(boolean interrupted) { + // not used } @Override diff --git a/src/main/java/frc/robot/subsystems/Arm.java b/src/main/java/frc/robot/subsystems/Arm.java index a7daa40..2ed7103 100644 --- a/src/main/java/frc/robot/subsystems/Arm.java +++ b/src/main/java/frc/robot/subsystems/Arm.java @@ -50,28 +50,21 @@ public Arm() { @Override public void periodic() { - SmartDashboard.putBoolean("zeroDeg", allTheWayDownRear.get()); + // SmartDashboard.putBoolean("zeroDeg", allTheWayDownRear.get()); encoderWidget.setDouble(armMotor.getEncoder().getPosition()); } - public void moveArm(double leftStickYaxis) { + /** + * uses input double value to set the motor speed of the arm + */ + public void moveArm(double value) { double speed = 0.8; - double motorDrive = leftStickYaxis * speed; + double motorDrive = value * speed; armMotor.set(motorDrive); } public void moveArmToZeroDeg() { - double speedY = 0.2; - while (allTheWayDownRear - .get()) { // the '== true' is implied, because the if statement is looking for the - // expression to be true. If it is false, it will not run the code inside the if - // statement, so we don't need to write it. - armMotor.set(-1 * speedY); - } - armMotor.set(0); - armMotor.getEncoder().setPosition(0); - currentArmAngle = 0; } @Override diff --git a/src/main/java/frc/robot/FieldConstants.java b/src/main/java/frc/robot/subsystems/FieldConstants.java similarity index 99% rename from src/main/java/frc/robot/FieldConstants.java rename to src/main/java/frc/robot/subsystems/FieldConstants.java index b2375a4..b78eab5 100644 --- a/src/main/java/frc/robot/FieldConstants.java +++ b/src/main/java/frc/robot/subsystems/FieldConstants.java @@ -5,7 +5,7 @@ // license that can be found in the LICENSE file at // the root directory of this project. -package frc.robot; +package frc.robot.subsystems; import edu.wpi.first.apriltag.AprilTag; import edu.wpi.first.apriltag.AprilTagFieldLayout;