From bcced0d0f7def58da03f5638a8145040bc6870bc Mon Sep 17 00:00:00 2001 From: alleycat6 Date: Mon, 29 Jan 2024 20:16:19 -0800 Subject: [PATCH 1/8] add comments / organize code and fix warnings --- .vscode/launch.json | 12 +- .vscode/settings.json | 7 +- src/main/java/frc/robot/Constants.java | 130 ++++++------ src/main/java/frc/robot/Main.java | 27 ++- src/main/java/frc/robot/OI.java | 99 ++++++--- src/main/java/frc/robot/Robot.java | 189 ++++++++++-------- src/main/java/frc/robot/RobotContainer.java | 94 ++++----- .../robot/commands/ArcadeDriveCommand.java | 30 ++- src/main/java/frc/robot/commands/Autos.java | 46 +++-- .../robot/commands/DefaultIntakeCommand.java | 34 +++- .../robot/commands/DistanceDriveCommand.java | 98 +++++---- .../frc/robot/commands/ExampleCommand.java | 70 ++++--- .../robot/commands/IntakeBackwardCommand.java | 28 ++- .../robot/commands/IntakeForwardCommand.java | 27 ++- .../robot/commands/PivotBackwardCommand.java | 27 ++- .../robot/commands/PivotForwardCommand.java | 29 ++- .../java/frc/robot/subsystems/Climber.java | 56 ++++-- .../java/frc/robot/subsystems/Drivetrain.java | 92 ++++++--- .../robot/subsystems/ExampleSubsystem.java | 67 +++++-- .../java/frc/robot/subsystems/Intake.java | 74 ++++--- 20 files changed, 799 insertions(+), 437 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5b804e8..322274b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,18 +4,24 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - + { + "type": "java", + "name": "Main", + "request": "launch", + "mainClass": "frc.robot.Main", + "projectName": "Robot-Code-2024" + }, { "type": "wpilib", "name": "WPILib Desktop Debug", "request": "launch", - "desktop": true, + "desktop": true }, { "type": "wpilib", "name": "WPILib roboRIO Debug", "request": "launch", - "desktop": false, + "desktop": false } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 8be11f2..f9d11ed 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,5 +25,10 @@ } }, ], - "java.test.defaultConfig": "WPIlibUnitTests" + "java.test.defaultConfig": "WPIlibUnitTests", + "java.format.settings.url": ".vscode/eclipse-java-google-style.xml", + "[java]": { + "editor.detectIndentation": false + }, + "java.checkstyle.configuration": "${workspaceFolder}/.vscode/eclipse-java-google-style.xml" } diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 4738fb5..d0a3fa2 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -1,7 +1,3 @@ -// 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 frc.robot; /** @@ -9,59 +5,81 @@ * constants. This class should not be used for any other purpose. All constants should be declared * globally (i.e. public static). Do not put anything functional in this class. * - *

It is advised to statically import this class (or one of its inner classes) wherever the + * It is advised to statically import this class (or one of its inner classes) wherever the * constants are needed, to reduce verbosity. */ public final class Constants { - - public static class OperatorConstants { - public static final int DRIVER_XBOX_PORT = 0; - public static final int COPILOT_XBOX_PORT = 1; - - public static final double DRIVER_JOYSTICK_DEADBAND = 0.1; - public static final double DRIVE_SPEED_ADJUSTMENT = 0.8; - } - - public static class DrivetrainConstants { - public static final int LEFT_MOTOR_1_PORT = 1; // TO DO: update - public static final int LEFT_MOTOR_2_PORT = 2; // TO DO: update - public static final int RIGHT_MOTOR_1_PORT = 3; // ^^ - public static final int RIGHT_MOTOR_2_PORT = 4; // ^^ - - public static final int COUNTS_PER_REV = 42; - } - - public static class IntakeConstants { - - // CONSTANTS FROM OFFSEASON; may need changing - - public static final int INTAKE_MOTOR_PORT = 6; // TO DO: update - public static final int PIVOT_MOTOR_PORT = 8; // TO DO: update - - public static final double INTAKE_MOTOR_SPEED_FORWARD = 0.4; // default value 0.6, lower to prevent cubes from breaking - public static final double INTAKE_MOTOR_SPEED_BACKWARD = -0.6; - public static final double INTAKE_MOTOR_SPEED_DEFAULT = 0.05; - - public static final double PIVOT_MOTOR_SPEED = 0.2; - - public static final int COUNTS_PER_REV = 42; - - public static final double PIVOT_DELTA = 8; // for if we want to run a relative encoder thing - - // for if we want to fix encoder values for up and down (these are untested!) - public static final double PIVOT_DOWN_POSITION = 8.5; - public static final double PIVOT_UP_POSITION = 0.5; - - } - - public static class ClimberConstants { - public static final int CLIMBER_MOTOR_PORT = 100; // TO DO: set ID val - - public static final int COUNTS_PER_REV = 42; - } - - public static class AutoConstants { - public static final double TAXI_AUTO_TARGET_DISTANCE = 25; // (temp) distance (in rotations of encoder) to travel (can be both neg + pos) - public static final double TAXI_AUTO_SPEED = 0.25; // (temp) speed of robot during taxi auto - } + /** + * Constructs Constants object. + */ + public Constants() {} + + /** + * Class for operator constants. + */ + public static class OperatorConstants { + public static final int DRIVER_XBOX_PORT = 0; + public static final int COPILOT_XBOX_PORT = 1; + + public static final double DRIVER_JOYSTICK_DEADBAND = 0.1; + public static final double DRIVE_SPEED_ADJUSTMENT = 0.8; + } + + /** + * Class for drivetrain constants. + */ + public static class DrivetrainConstants { + // TO DO: update + public static final int LEFT_MOTOR_1_PORT = 1; + public static final int LEFT_MOTOR_2_PORT = 2; + public static final int RIGHT_MOTOR_1_PORT = 3; + public static final int RIGHT_MOTOR_2_PORT = 4; + + public static final int COUNTS_PER_REV = 42; + } + + /** + * Class for intake constants. + */ + public static class IntakeConstants { + // TO DO: update + public static final int INTAKE_MOTOR_PORT = 6; + public static final int PIVOT_MOTOR_PORT = 8; + + public static final double INTAKE_MOTOR_SPEED_FORWARD = 0.4; + public static final double INTAKE_MOTOR_SPEED_BACKWARD = -0.6; + public static final double INTAKE_MOTOR_SPEED_DEFAULT = 0.05; + + public static final double PIVOT_MOTOR_SPEED = 0.2; + + public static final int COUNTS_PER_REV = 42; + + // TO DO: delete after intake is updated + // For if we want to run a relative encoder thing + public static final double PIVOT_DELTA = 8; + + // TO DO: delete after intake is updated + // For if we want to fix encoder values for up and down (these are untested) + public static final double PIVOT_DOWN_POSITION = 8.5; + public static final double PIVOT_UP_POSITION = 0.5; + } + + /** + * Class for climber constants. + */ + public static class ClimberConstants { + // TO DO: set ID val + public static final int CLIMBER_MOTOR_PORT = 100; + + public static final int COUNTS_PER_REV = 42; + } + + /** + * Class for auto constants. + */ + public static class AutoConstants { + // TO DO: update + public static final double TAXI_AUTO_TARGET_DISTANCE = 25; + public static final double TAXI_AUTO_SPEED = 0.25; + } } diff --git a/src/main/java/frc/robot/Main.java b/src/main/java/frc/robot/Main.java index 8776e5d..4642233 100644 --- a/src/main/java/frc/robot/Main.java +++ b/src/main/java/frc/robot/Main.java @@ -1,25 +1,24 @@ -// 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 frc.robot; import edu.wpi.first.wpilibj.RobotBase; /** - * Do NOT add any static variables to this class, or any initialization at all. Unless you know what + * Do not add any static variables to this class, or any initialization at all. Unless you know what * you are doing, do not modify this file except to change the parameter class to the startRobot * call. */ public final class Main { - private Main() {} + /** + * Constructs Main object. + */ + public Main() {} - /** - * Main initialization function. Do not perform any initialization here. - * - *

If you change your main robot class, change the parameter type. - */ - public static void main(String... args) { - RobotBase.startRobot(Robot::new); - } + /** + * Main initialization function. Do not perform any initialization here. + * + * If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } } diff --git a/src/main/java/frc/robot/OI.java b/src/main/java/frc/robot/OI.java index 9559799..9c70e47 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc/robot/OI.java @@ -1,51 +1,102 @@ package frc.robot; -import frc.robot.Constants.OperatorConstants; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; +import frc.robot.Constants.OperatorConstants; + +/** + * Operator Interface class to handle communication between controllers and driver station. + */ public class OI { - - // Replace with CommandPS4Controller or CommandJoystick if needed + // Instance variables public static CommandXboxController m_driverXbox = new CommandXboxController( OperatorConstants.DRIVER_XBOX_PORT); public static CommandXboxController m_coPilotXbox = new CommandXboxController( OperatorConstants.COPILOT_XBOX_PORT); + + /** + * Constructs OI object. + */ + public OI() {} - // driver xbox inputs - - // needs to be negative to make motors run straight as of 9/26/23 - public double getDriverXBoxLeftJoyY() { - return -m_driverXbox.getLeftY(); - } + // Driver XBox joystick values + /** + * Gets XBox left joystick x-axis value. + * + * @return current left side x-axis value + */ public double getDriverXBoxLeftJoyX() { return m_driverXbox.getLeftX(); } - public double getDriverXBoxRightJoyY() { - return m_driverXbox.getRightY(); + /** + * Gets XBox left joystick y-axis value. + * + * @return current left side y-axis value + */ + public double getDriverXBoxLeftJoyY() { + // Needs to be negative to make motors run straight (as of 9/26/23) + return -m_driverXbox.getLeftY(); } - // needs to be negative to make the turning correct as of 9/26/23 + /** + * Gets XBox right joystick x-axis value. + * + * @return current right side x-axis value + */ public double getDriverXBoxRightJoyX() { + // Needs to be negative to make the turning correct (as of 9/26/23) return -m_driverXbox.getRightX(); } - // copilot xbox inputs - public double getCoXBoxLeftJoyY() { - return m_coPilotXbox.getLeftY(); + /** + * Gets XBox right joystick y-axis value. + * + * @return current right side y-axis value + */ + public double getDriverXBoxRightJoyY() { + return m_driverXbox.getRightY(); } - public double getCoXBoxLeftJoyX() { - return m_coPilotXbox.getLeftX(); - } + // Copilot XBox joystick values (not being used right now) + + // /** + // * Gets XBox left joystick x-axis value. + // * + // * @return current left side x-axis value + // */ + // public double getCoXBoxLeftJoyX() { + // return m_coPilotXbox.getLeftX(); + // } - public double getCoXBoxRightJoyY() { - return m_coPilotXbox.getRightY(); - } + // /** + // * Gets XBox left joystick y-axis value. + // * + // * @return current left side y-axis value + // */ + // public double getCoXBoxLeftJoyY() { + // // Needs to be negative to make motors run straight (as of 9/26/23) + // return -m_driverXbox.getLeftY(); + // } - public double getCoXBoxRightJoyX() { - return m_coPilotXbox.getRightX(); - } + // /** + // * Gets XBox right joystick x-axis value. + // * + // * @return current right side x-axis value + // */ + // public double getCoXBoxRightJoyX() { + // // Needs to be negative to make the turning correct (as of 9/26/23) + // return -m_driverXbox.getRightX(); + // } + + // /** + // * Gets XBox right joystick y-axis value. + // * + // * @return current right side y-axis value + // */ + // public double getCoXBoxRightJoyY() { + // return m_coPilotXbox.getRightY(); + // } } diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index ccdab80..8cdd556 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -1,14 +1,9 @@ -// 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 frc.robot; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; - /** * The VM is configured to automatically run this class, and to call the functions corresponding to * each mode, as described in the TimedRobot documentation. If you change the name of this class or @@ -16,90 +11,116 @@ * project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; - - private RobotContainer m_robotContainer; - - /** - * This function is run when the robot is first started up and should be used for any - * initialization code. - */ - @Override - public void robotInit() { - // Instantiate our RobotContainer. This will perform all our button bindings, and put our - // autonomous chooser on the dashboard. - - m_robotContainer = new RobotContainer(); - } - - /** - * This function is called every 20 ms, no matter the mode. Use this for items like diagnostics - * that you want ran during disabled, autonomous, teleoperated and test. - * - *

This runs after the mode specific periodic functions, but before LiveWindow and - * SmartDashboard integrated updating. - */ - @Override - public void robotPeriodic() { - // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled - // commands, running already-scheduled commands, removing finished or interrupted commands, - // and running subsystem periodic() methods. This must be called from the robot's periodic - // block in order for anything in the Command-based framework to work. - CommandScheduler.getInstance().run(); - } - - /** This function is called once each time the robot enters Disabled mode. */ - @Override - public void disabledInit() {} - - @Override - public void disabledPeriodic() {} - - /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ - @Override - public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); - - // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - m_autonomousCommand.schedule(); + // Instance variables + private Command m_autonomousCommand; + private RobotContainer m_robotContainer; + + /** + * Constructs Robot object. + */ + public Robot() {} + + /** + * This function is run when the robot is first started up and should be used for any robot-wide + * initialization code. + */ + @Override + public void robotInit() { + // Instantiate our RobotContainer. This will perform all our button bindings, and put our + // autonomous chooser on the dashboard. + m_robotContainer = new RobotContainer(); } - } - /** This function is called periodically during autonomous. */ - @Override - public void autonomousPeriodic() {} - - @Override - public void teleopInit() { - // This makes sure that the autonomous stops running when - // teleop starts running. If you want the autonomous to - // continue until interrupted by another command, remove - // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + /** + * This function is called every 20 ms, no matter the mode. Use this for items like diagnostics + * that you want ran during disabled, autonomous, teleoperated and test. + * + * This runs after the mode specific periodic functions, but before LiveWindow and SmartDashboard + * integrated updating. + */ + @Override + public void robotPeriodic() { + // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled + // commands, running already-scheduled commands, removing finished or interrupted commands, and + // running subsystem periodic() methods. This must be called from the robot's periodic block in + // order for anything in the Command-based framework to work. + CommandScheduler.getInstance().run(); } - } - - /** This function is called periodically during operator control. */ - @Override - public void teleopPeriodic() {} - @Override - public void testInit() { - // Cancels all running commands at the start of test mode. - CommandScheduler.getInstance().cancelAll(); - } + /** + * This function is called once each time the robot enters disabled mode. + */ + @Override + public void disabledInit() {} + + /** + * This function is called periodically while the robot is in disabled mode. + */ + @Override + public void disabledPeriodic() {} + + /** + * This function is called once each time the robot enters autonomous mode. + */ + @Override + public void autonomousInit() { + m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + + // schedule the autonomous command (example) + if (m_autonomousCommand != null) { + m_autonomousCommand.schedule(); + } + } - /** This function is called periodically during test mode. */ - @Override - public void testPeriodic() {} + /** + * This function is called periodically while the robot is in autonomous mode. + */ + @Override + public void autonomousPeriodic() {} + + /** + * This function is called once each time the robot enters teleop mode. + */ + @Override + public void teleopInit() { + // This makes sure that the autonomous stops running when teleop starts running. If you want the + // autonomous to continue until interrupted by another command, remove this line or comment it + // out. + if (m_autonomousCommand != null) { + m_autonomousCommand.cancel(); + } + } - /** This function is called once when the robot is first started up. */ - @Override - public void simulationInit() {} + /** + * This function is called periodically while the robot is in teleop mode. + */ + @Override + public void teleopPeriodic() {} + + /** + * This function is called once each time the robot enters test mode. + */ + @Override + public void testInit() { + // Cancels all running commands at the start of test mode. + CommandScheduler.getInstance().cancelAll(); + } - /** This function is called periodically whilst in simulation. */ - @Override - public void simulationPeriodic() {} + /** + * This function is called periodically while the robot is in test mode. + */ + @Override + public void testPeriodic() {} + + /** + * This function is called once when the robot is first started up. + */ + @Override + public void simulationInit() {} + + /** + * This function is called periodically while the robot is in simulation. + */ + @Override + public void simulationPeriodic() {} } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index f7a9654..48dc95f 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -1,73 +1,61 @@ -// 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 frc.robot; -// import frc.robot.Constants.OperatorConstants; +import edu.wpi.first.wpilibj2.command.Command; +// import edu.wpi.first.wpilibj2.command.button.Trigger; import frc.robot.commands.Autos; -// import frc.robot.commands.ExampleCommand; import frc.robot.commands.ArcadeDriveCommand; import frc.robot.commands.IntakeBackwardCommand; import frc.robot.commands.IntakeForwardCommand; import frc.robot.commands.PivotBackwardCommand; import frc.robot.commands.PivotForwardCommand; import frc.robot.commands.DefaultIntakeCommand; - import frc.robot.subsystems.Drivetrain; -import frc.robot.subsystems.ExampleSubsystem; import frc.robot.subsystems.Intake; -import edu.wpi.first.wpilibj2.command.Command; -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} + * "declarative" paradigm, very little robot logic should actually be handled in the Robot * periodic methods (other than the scheduler calls). Instead, the structure of the robot (including * subsystems, commands, and trigger mappings) should be declared here. */ public class RobotContainer { - // The robot's subsystems and commands are defined here... - private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem(); - private static final OI m_humanControl = new OI(); - public static final Drivetrain m_drivetrain = new Drivetrain(m_humanControl); - private static final Intake m_intake = new Intake(); - - /** The container for the robot. Contains subsystems, OI devices, and commands. */ - public RobotContainer() { - // Configure the trigger bindings - configureBindings(); - m_drivetrain.setDefaultCommand(new ArcadeDriveCommand(m_drivetrain, m_humanControl)); - m_intake.setDefaultCommand(new DefaultIntakeCommand(m_intake)); - } - - /** - * Use this method to define your trigger->command mappings. Triggers can be created via the - * {@link Trigger#Trigger(java.util.function.BooleanSupplier)} constructor with an arbitrary - * predicate, or via the named factories in {@link - * edu.wpi.first.wpilibj2.command.button.CommandGenericHID}'s subclasses for {@link - * CommandXboxController Xbox}/{@link edu.wpi.first.wpilibj2.command.button.CommandPS4Controller - * PS4} controllers or {@link edu.wpi.first.wpilibj2.command.button.CommandJoystick Flight - * joysticks}. - */ - private void configureBindings() { - - OI.m_coPilotXbox.b().whileTrue(new IntakeForwardCommand(m_intake)); - OI.m_coPilotXbox.a().whileTrue(new IntakeBackwardCommand(m_intake)); - OI.m_coPilotXbox.x().whileTrue(new PivotBackwardCommand(m_intake)); - OI.m_coPilotXbox.y().whileTrue(new PivotForwardCommand(m_intake)); - } - - /** - * Use this to pass the autonomous command to the main {@link Robot} class. - * - * @return the command to run in autonomous - */ - public Command getAutonomousCommand() { - // the taxi command that will be run in autonomous - return Autos.taxiAuto(m_drivetrain); - } + // Instance variables + // The robot's subsystems and commands are defined here + private static final OI m_humanControl = new OI(); + public static final Drivetrain m_drivetrain = new Drivetrain(m_humanControl); + private static final Intake m_intake = new Intake(); + + /** + * The container for the robot. Contains subsystems, OI devices, and commands. + */ + public RobotContainer() { + // Configure the trigger bindings + configureBindings(); + m_drivetrain.setDefaultCommand(new ArcadeDriveCommand(m_drivetrain, m_humanControl)); + m_intake.setDefaultCommand(new DefaultIntakeCommand(m_intake)); + } + + /** + * Use this method to define your trigger -> command mappings. Triggers can be created via the + * Trigger (java.util.function.BooleanSupplier) constructor with an arbitrary predicate, or via + * the named factories in CommandGenericHID's subclasses for CommandXboxController or + * CommandPS4Controller controllers or CommandJoystick Flight joysticks. + */ + private void configureBindings() { + OI.m_coPilotXbox.b().whileTrue(new IntakeForwardCommand(m_intake)); + OI.m_coPilotXbox.a().whileTrue(new IntakeBackwardCommand(m_intake)); + OI.m_coPilotXbox.x().whileTrue(new PivotBackwardCommand(m_intake)); + OI.m_coPilotXbox.y().whileTrue(new PivotForwardCommand(m_intake)); + } + + /** + * Use this to pass the autonomous command to the main Robot class. + * + * @return the command to run in autonomous + */ + public Command getAutonomousCommand() { + // Taxi command that will be run in autonomous + return Autos.taxiAuto(m_drivetrain); + } } \ No newline at end of file diff --git a/src/main/java/frc/robot/commands/ArcadeDriveCommand.java b/src/main/java/frc/robot/commands/ArcadeDriveCommand.java index 08ac909..e30f712 100644 --- a/src/main/java/frc/robot/commands/ArcadeDriveCommand.java +++ b/src/main/java/frc/robot/commands/ArcadeDriveCommand.java @@ -6,22 +6,32 @@ import frc.robot.OI; import frc.robot.Constants.OperatorConstants; -// import java.lang.Math.*; - +/** + * Command to arcade drive. Uses Drivetrain and OI subsystems. + */ public class ArcadeDriveCommand extends Command { + // Instance variables private final Drivetrain m_drivetrain; private final OI m_humanControl; + /** + * Constructs an ArcadeDriveCommand command. + */ public ArcadeDriveCommand(Drivetrain drivetrain, OI humanControl) { m_drivetrain = drivetrain; m_humanControl = humanControl; addRequirements(drivetrain); } + /** + * Method called once per time the command is scheduled. + */ @Override - public void initialize() { } + public void initialize() {} - // Called every time the scheduler runs while the command is scheduled. + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ @Override public void execute() { double xJoy = m_humanControl.getDriverXBoxLeftJoyY(); @@ -32,13 +42,21 @@ public void execute() { m_drivetrain.arcadeDrive(OperatorConstants.DRIVE_SPEED_ADJUSTMENT * x_val, OperatorConstants.DRIVE_SPEED_ADJUSTMENT * y_val); } - // Called once the command ends or is interrupted. + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ @Override public void end(boolean interrupted) {} - // Returns true when the command should end. + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ @Override public boolean isFinished() { + return false; } } diff --git a/src/main/java/frc/robot/commands/Autos.java b/src/main/java/frc/robot/commands/Autos.java index dacf47c..f471390 100644 --- a/src/main/java/frc/robot/commands/Autos.java +++ b/src/main/java/frc/robot/commands/Autos.java @@ -1,26 +1,38 @@ -// 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 frc.robot.commands; -import frc.robot.subsystems.*; -import frc.robot.Constants.AutoConstants; - import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; +import frc.robot.subsystems.ExampleSubsystem; +import frc.robot.subsystems.Drivetrain; +import frc.robot.Constants.AutoConstants; + +/** + * Class to hold all auto commands. + */ public final class Autos { - /** Example static factory for an autonomous command. */ - public static Command exampleAuto(ExampleSubsystem subsystem) { - return Commands.sequence(subsystem.exampleMethodCommand(), new ExampleCommand(subsystem)); - } + /** + * Example static factory method to create autonomous command. + * + * @return sequence of example commands to run in series, one after another + */ + public static Command exampleAuto(ExampleSubsystem subsystem) { + return Commands.sequence(subsystem.exampleMethodCommand(), new ExampleCommand(subsystem)); + } - public static Command taxiAuto(Drivetrain drivetrain) { - return new DistanceDriveCommand(drivetrain, AutoConstants.TAXI_AUTO_TARGET_DISTANCE); - } + /** + * Command to drive straight. + * + * @return DistanceDriveCommand to drive straight + */ + public static Command taxiAuto(Drivetrain drivetrain) { + return new DistanceDriveCommand(drivetrain, AutoConstants.TAXI_AUTO_TARGET_DISTANCE); + } - private Autos() { - throw new UnsupportedOperationException("This is a utility class!"); - } + /** + * Throws an error if Autos object is constructed. + */ + private Autos() { + throw new UnsupportedOperationException("This is a utility class!"); + } } diff --git a/src/main/java/frc/robot/commands/DefaultIntakeCommand.java b/src/main/java/frc/robot/commands/DefaultIntakeCommand.java index cdc64ab..c384282 100644 --- a/src/main/java/frc/robot/commands/DefaultIntakeCommand.java +++ b/src/main/java/frc/robot/commands/DefaultIntakeCommand.java @@ -1,30 +1,54 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.Command; + import frc.robot.subsystems.Intake; import frc.robot.Constants.IntakeConstants; -public class DefaultIntakeCommand extends Command{ +/** + * Command to run default intake. Uses Intake subsystem. + */ +public class DefaultIntakeCommand extends Command { + // Instance variables private Intake m_intake; - public DefaultIntakeCommand(Intake intake){ + + /** + * Constructs a DefaultIntakeCommand command. + */ + public DefaultIntakeCommand(Intake intake) { m_intake = intake; addRequirements(intake); } + /** + * Method called once per time the command is scheduled. + */ @Override - public void initialize() { - } + public void initialize() {} + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ @Override public void execute() { - m_intake.runIntakeMotor(IntakeConstants.INTAKE_MOTOR_SPEED_DEFAULT); // default value 0.6, lower to prevent cubes from breaking + // Default value 0.6, lower to prevent cubes from breaking + m_intake.runIntakeMotor(IntakeConstants.INTAKE_MOTOR_SPEED_DEFAULT); } + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ @Override public void end(boolean interrupted) { m_intake.intakeOff(); } + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ @Override public boolean isFinished() { return false; diff --git a/src/main/java/frc/robot/commands/DistanceDriveCommand.java b/src/main/java/frc/robot/commands/DistanceDriveCommand.java index f07416a..fc98e5b 100644 --- a/src/main/java/frc/robot/commands/DistanceDriveCommand.java +++ b/src/main/java/frc/robot/commands/DistanceDriveCommand.java @@ -1,51 +1,65 @@ -// 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 frc.robot.commands; + +import edu.wpi.first.wpilibj2.command.Command; + import frc.robot.subsystems.Drivetrain; import frc.robot.Constants.AutoConstants; +/** + * Command to drive a set distance. Uses Drivetrain subsystem. + */ +public class DistanceDriveCommand extends Command { + // Instance variables + private final Drivetrain m_drivetrain; + private double m_rightEncoderStart; + private double m_leftEncoderStart; + private double m_targetDistance; -//import java.lang.Math.*; + /** + * Constructs a DistanceDriveCommand command. + */ + public DistanceDriveCommand(Drivetrain drivetrain, double targetDistance) { + m_drivetrain = drivetrain; + // Supports both negative and positive targetDistance + m_targetDistance = targetDistance; + addRequirements(drivetrain); + } -import edu.wpi.first.wpilibj2.command.Command; + /** + * Method called once per time the command is scheduled. + */ + @Override + public void initialize() { + // Gets start positions of encoders + m_rightEncoderStart = m_drivetrain.getRightEncoderPosition(); + m_leftEncoderStart = m_drivetrain.getLeftEncoderPosition(); + } + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ + @Override + public void execute() { + m_drivetrain.arcadeDrive(AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance), 0); // drives in the direction of targetDistance + } -/** An taxi command that uses the drivetrain subsystem. */ -public class DistanceDriveCommand extends Command { - @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) - private final Drivetrain m_drivetrain; - private double m_rightEncoderStart; - private double m_leftEncoderStart; - private double m_targetDistance; - - - public DistanceDriveCommand(Drivetrain drivetrain, double targetDistance) { - m_drivetrain = drivetrain; - m_targetDistance = targetDistance; // supports both neg + pos targetDistance - addRequirements(drivetrain); - } - - @Override - public void initialize() { - // gets start positions of encoders - m_rightEncoderStart = m_drivetrain.getRightEncoderPosition(); - m_leftEncoderStart = m_drivetrain.getLeftEncoderPosition(); - } - - @Override - public void execute() { - m_drivetrain.arcadeDrive(AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance), 0); // drives in the direction of targetDistance - } - - @Override - public void end(boolean interrupted) {} - - @Override - public boolean isFinished() { - // calculates if either encoder has moved enough to reach the target distance - return (Math.abs(m_drivetrain.getRightEncoderPosition() - m_rightEncoderStart) > Math.abs(m_targetDistance) - || Math.abs(m_drivetrain.getLeftEncoderPosition() - m_leftEncoderStart) > Math.abs(m_targetDistance)); - } + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ + @Override + public void end(boolean interrupted) {} + + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ + @Override + public boolean isFinished() { + // Calculates if either encoder has moved enough to reach the target distance + return (Math.abs(m_drivetrain.getRightEncoderPosition() - m_rightEncoderStart) > + Math.abs(m_targetDistance) || Math.abs(m_drivetrain.getLeftEncoderPosition() - + m_leftEncoderStart) > Math.abs(m_targetDistance)); + } } diff --git a/src/main/java/frc/robot/commands/ExampleCommand.java b/src/main/java/frc/robot/commands/ExampleCommand.java index 6161529..de60a6c 100644 --- a/src/main/java/frc/robot/commands/ExampleCommand.java +++ b/src/main/java/frc/robot/commands/ExampleCommand.java @@ -1,34 +1,50 @@ -// 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 frc.robot.commands; import edu.wpi.first.wpilibj2.command.Command; + import frc.robot.subsystems.ExampleSubsystem; -/** An example command that uses an example subsystem. */ +/** + * Command example. Uses ExampleSubsystem subsystem. + */ public class ExampleCommand extends Command { - @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) - private final ExampleSubsystem m_subsystem; - - - public ExampleCommand(ExampleSubsystem subsystem) { - m_subsystem = subsystem; - addRequirements(subsystem); - } - - @Override - public void initialize() {} - - @Override - public void execute() {} - - @Override - public void end(boolean interrupted) {} - - @Override - public boolean isFinished() { - return false; - } + // Instance variables + private final ExampleSubsystem m_subsystem; + + /** + * Constructs an ExampleCommand command. + */ + public ExampleCommand(ExampleSubsystem subsystem) { + m_subsystem = subsystem; + addRequirements(subsystem); + } + + /** + * Method called once per time the command is scheduled. + */ + @Override + public void initialize() {} + + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ + @Override + public void execute() {} + + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ + @Override + public void end(boolean interrupted) {} + + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ + @Override + public boolean isFinished() { + return false; + } } diff --git a/src/main/java/frc/robot/commands/IntakeBackwardCommand.java b/src/main/java/frc/robot/commands/IntakeBackwardCommand.java index 98ceb85..eeb3763 100644 --- a/src/main/java/frc/robot/commands/IntakeBackwardCommand.java +++ b/src/main/java/frc/robot/commands/IntakeBackwardCommand.java @@ -1,33 +1,53 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.Command; + import frc.robot.subsystems.Intake; import frc.robot.Constants.IntakeConstants; - +/** + * Command to run intake backward. Uses Intake subsystem. + */ public class IntakeBackwardCommand extends Command { + // Instance variables private Intake m_intake; + /** + * Constructs an IntakeBackwardCommand command. + */ public IntakeBackwardCommand(Intake intake){ m_intake = intake; addRequirements(intake); } + /** + * Method called once per time the command is scheduled. + */ @Override - public void initialize() { - // System.out.println("INTAKE SPIT COMMAND STARTED"); - } + public void initialize() {} + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ @Override public void execute() { m_intake.runIntakeMotor(IntakeConstants.INTAKE_MOTOR_SPEED_BACKWARD); } + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ @Override public void end(boolean interrupted) { m_intake.intakeOff(); } + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ @Override public boolean isFinished() { return false; diff --git a/src/main/java/frc/robot/commands/IntakeForwardCommand.java b/src/main/java/frc/robot/commands/IntakeForwardCommand.java index 4ed88cf..62c146a 100644 --- a/src/main/java/frc/robot/commands/IntakeForwardCommand.java +++ b/src/main/java/frc/robot/commands/IntakeForwardCommand.java @@ -1,32 +1,53 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.Command; + import frc.robot.subsystems.Intake; import frc.robot.Constants.IntakeConstants; +/** + * Command to run intake forward. Uses Intake subsystem. + */ public class IntakeForwardCommand extends Command { + // Instance variables private Intake m_intake; + /** + * Constructs an IntakeForwardCommand command. + */ public IntakeForwardCommand(Intake intake){ m_intake = intake; addRequirements(intake); } + /** + * Method called once per time the command is scheduled. + */ @Override - public void initialize() { - // System.out.println("INTAKE SUCK COMMAND STARTED"); - } + public void initialize() {} + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ @Override public void execute() { m_intake.runIntakeMotor(IntakeConstants.INTAKE_MOTOR_SPEED_FORWARD); } + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ @Override public void end(boolean interrupted) { m_intake.intakeOff(); } + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ @Override public boolean isFinished() { return false; diff --git a/src/main/java/frc/robot/commands/PivotBackwardCommand.java b/src/main/java/frc/robot/commands/PivotBackwardCommand.java index 0b7f5d6..4b8af90 100644 --- a/src/main/java/frc/robot/commands/PivotBackwardCommand.java +++ b/src/main/java/frc/robot/commands/PivotBackwardCommand.java @@ -1,36 +1,57 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.Command; -import frc.robot.subsystems.Intake; +import frc.robot.subsystems.Intake; import frc.robot.Constants.IntakeConstants; +/** + * Command to run pivot backward. Uses Intake subsystem. + */ public class PivotBackwardCommand extends Command { - private double m_encoderStart; + // Instance variables private Intake m_intake; + private double m_encoderStart; + /** + * Constructs a PivotBackwardCommand command. + */ public PivotBackwardCommand(Intake intake){ m_intake = intake; } + /** + * Method called once per time the command is scheduled. + */ @Override public void initialize() { m_encoderStart = m_intake.getPivotEncoderPosition(); } + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ @Override public void execute() { m_intake.runPivotIntakeMotor(-IntakeConstants.PIVOT_MOTOR_SPEED); } + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ @Override public void end(boolean interrupted) { m_intake.pivotMotorOff(); } + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ @Override public boolean isFinished() { return m_intake.getPivotEncoderPosition() <= m_encoderStart - IntakeConstants.PIVOT_DELTA; - // return m_intake.getPivotEncoderPosition() <= IntakeConstants.PIVOT_UP_POSITION; } } diff --git a/src/main/java/frc/robot/commands/PivotForwardCommand.java b/src/main/java/frc/robot/commands/PivotForwardCommand.java index 492fa18..d73167b 100644 --- a/src/main/java/frc/robot/commands/PivotForwardCommand.java +++ b/src/main/java/frc/robot/commands/PivotForwardCommand.java @@ -1,36 +1,57 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.Command; -import frc.robot.subsystems.Intake; +import frc.robot.subsystems.Intake; import frc.robot.Constants.IntakeConstants; -public class PivotForwardCommand extends Command{ - private double m_encoderStart; +/** + * Command to run pivot forward. Uses Intake subsystem. + */ +public class PivotForwardCommand extends Command { + // Instance variables private Intake m_intake; + private double m_encoderStart; + /** + * Constructs a PivotForwardCommand command. + */ public PivotForwardCommand(Intake intake){ m_intake = intake; } + /** + * Method called once per time the command is scheduled. + */ @Override public void initialize() { m_encoderStart = m_intake.getPivotEncoderPosition(); } + /** + * Method called repeatedly while the command is scheduled (every time the scheduler runs). + */ @Override public void execute() { m_intake.runPivotIntakeMotor(IntakeConstants.PIVOT_MOTOR_SPEED); } + /** + * Method called once when the command ends (whether it finishes normally or is interrupted). + */ @Override public void end(boolean interrupted) { m_intake.pivotMotorOff(); } + /** + * Method called repeatedly while the command is scheduled (returns false while the command is + * scheduled, true when the command should end). + * + * @return whether command is finished + */ @Override public boolean isFinished() { return m_intake.getPivotEncoderPosition() >= m_encoderStart + IntakeConstants.PIVOT_DELTA; - // return m_intake.getPivotEncoderPosition() >= IntakeConstants.PIVOT_DOWN_POSITION; } } diff --git a/src/main/java/frc/robot/subsystems/Climber.java b/src/main/java/frc/robot/subsystems/Climber.java index e33fb2f..621a07d 100644 --- a/src/main/java/frc/robot/subsystems/Climber.java +++ b/src/main/java/frc/robot/subsystems/Climber.java @@ -4,42 +4,66 @@ import com.revrobotics.CANSparkMaxLowLevel.MotorType; import com.revrobotics.SparkMaxRelativeEncoder; -import edu.wpi.first.wpilibj2.command.Subsystem; -import frc.robot.Constants.ClimberConstants; +import edu.wpi.first.wpilibj2.command.SubsystemBase; -/* THIS CODE IS PLACEHOLDER CODE AND NEEDS TO BE REPLACED WHEN CLIMBER DESIGN IS FINALIZED */ +import frc.robot.Constants.ClimberConstants; -public class Climber extends Subsystem{ - private final CANSparkMax m_climberMotor = new CANSparkMax(ClimberConstants.CLIMBER_MOTOR_PORT, MotorType.kBrushless); +/** + * Subsystem to control the climber. + */ +public class Climber extends SubsystemBase { + // Instance variables + // Motor + private final CANSparkMax m_climberMotor = new CANSparkMax(ClimberConstants.CLIMBER_MOTOR_PORT, + MotorType.kBrushless); - private final SparkMaxRelativeEncoder m_climberEncoder = (SparkMaxRelativeEncoder) m_climberMotor - .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, ClimberConstants.COUNTS_PER_REV); + // Encoder + private final SparkMaxRelativeEncoder m_climberEncoder = (SparkMaxRelativeEncoder) + m_climberMotor.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, + ClimberConstants.COUNTS_PER_REV); - // Constructor for the Intake class - public Climber(){ - } + /** + * Constructs a Climber subsystem. + */ + public Climber() {} - // returns encoder position + /** + * Gets climber encoder position. + * + * @return current encoder position (in "rotations") + */ public double getclimberEncoderPosition() { return m_climberEncoder.getPosition(); } - // sets encoder to desired position + /** + * Sets climber encoder position. + * + * @param position desired encoder position (in "rotations") + */ public void setClimberEncoderPosition(double position) { m_climberEncoder.setPosition(position); } - // initializes encoder position to 0 - MAKE SURE INTAKE IS ALWAYS FULLY UP WHENEVER THIS METHOD IS CALLED + /** + * Initializes climber encoder position to 0. + */ public void initializeClimberEncoderPosition() { - setClimberEncoderPosition(0); // TO DO: WRITE THE SET FUNCTION + setClimberEncoderPosition(0); } - // Sets intake motor speed (forward if positive, backward if negative) + /** + * Sets climber motor speed (forward if positive / backward if negative). + * + * @param speed desired motor speed (between -1.0 and 1.0) + */ public void runClimberMotor(double speed){ m_climberMotor.set(speed); } - // Sets intake motor speed to zero and stops motor + /** + * Sets climber motor speed to 0 and stops motor. + */ public void climberOff() { m_climberMotor.set(0); m_climberMotor.stopMotor(); diff --git a/src/main/java/frc/robot/subsystems/Drivetrain.java b/src/main/java/frc/robot/subsystems/Drivetrain.java index eceee3d..e096f3d 100644 --- a/src/main/java/frc/robot/subsystems/Drivetrain.java +++ b/src/main/java/frc/robot/subsystems/Drivetrain.java @@ -1,28 +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 frc.robot.subsystems; -import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.Subsystem; -import frc.robot.Constants.DrivetrainConstants; - -import frc.robot.OI; import com.revrobotics.CANSparkMax; import com.revrobotics.CANSparkMaxLowLevel.MotorType; import com.revrobotics.SparkMaxRelativeEncoder; + +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -public class Drivetrain extends Subsystem { - - // instance variables +import frc.robot.Constants.DrivetrainConstants; +import frc.robot.OI; +/** + * Subsystem to control the drivetrain. + */ +public class Drivetrain extends SubsystemBase { + // Instance variables private final OI m_humanControl; + public static DifferentialDrive m_robotDrive; - // motors - // sets up a CAN-enabled SPARK MAX motor controller for each motor (left primary, left secondary, right primary, and right secondary) + // Motors + // Sets up a CAN-enabled SPARK MAX motor controller for each motor (left primary, left secondary, right primary, and right secondary) public final CANSparkMax m_leftPrimary = new CANSparkMax(DrivetrainConstants.LEFT_MOTOR_1_PORT, MotorType.kBrushless); private final CANSparkMax m_leftSecondary = new CANSparkMax(DrivetrainConstants.LEFT_MOTOR_2_PORT, @@ -32,7 +31,7 @@ public class Drivetrain extends Subsystem { private final CANSparkMax m_rightSecondary = new CANSparkMax(DrivetrainConstants.RIGHT_MOTOR_2_PORT, MotorType.kBrushless); - // encoders + // Encoders public final SparkMaxRelativeEncoder m_leftPrimaryEncoder = (SparkMaxRelativeEncoder) m_leftPrimary .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, DrivetrainConstants.COUNTS_PER_REV); public final SparkMaxRelativeEncoder m_leftSecondaryEncoder = (SparkMaxRelativeEncoder) m_leftSecondary @@ -42,12 +41,14 @@ public class Drivetrain extends Subsystem { public final SparkMaxRelativeEncoder m_rightSecondaryEncoder = (SparkMaxRelativeEncoder) m_rightSecondary .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, DrivetrainConstants.COUNTS_PER_REV); - // groups - to control multiple motors at once (for multiple motors per side of the drivetrain) + // Groups + // Controls multiple motors at once (for multiple motors per side of the drivetrain) private final MotorControllerGroup m_leftGroup = new MotorControllerGroup(m_leftPrimary, m_leftSecondary); private final MotorControllerGroup m_rightGroup = new MotorControllerGroup(m_rightPrimary, m_rightSecondary); - - public static DifferentialDrive m_robotDrive; + /** + * Constructs a Drivetrain subsystem. + */ public Drivetrain(OI humanControl) { m_robotDrive = new DifferentialDrive(m_leftGroup, m_rightGroup); m_humanControl = humanControl; @@ -55,44 +56,73 @@ public Drivetrain(OI humanControl) { configDrivetrainMotors(); } + /** + * Method called once every scheduler run (not being used right now). + */ @Override - public void periodic() {} + public void periodic() { + // Typically used for telemetry and other periodic actions that do not interfere with commands + } - public void configDrivetrainMotors() { + /** + * Method called once every scheduler run during simulation (not being used right now). + */ + @Override + public void simulationPeriodic() { + // Can be used to update state of robot + } - // makes the secondary motors follow the primary ones + /** + * Sets up motors during construction. + */ + // + public void configDrivetrainMotors() { + // Makes the secondary motors follow the primary ones m_leftSecondary.follow(m_leftPrimary); m_rightSecondary.follow(m_rightPrimary); - // inverts the right side to account for the fact that that side initially moves backwards for positive velocity and forwards for negative + // Inverts the right side to account for the fact that that side initially moves backwards for positive velocity and forwards for negative m_leftGroup.setInverted(false); m_rightGroup.setInverted(true); } - // returns position in "rotations" + /** + * Gets left primary encoder position. + * + * @return current encoder position (in "rotations") + */ public double getLeftEncoderPosition() { return m_leftPrimaryEncoder.getPosition(); } - // returns position in "rotations" + /** + * Gets right primary encoder position. + * + * @return current encoder position (in "rotations") + */ public double getRightEncoderPosition() { return m_rightPrimaryEncoder.getPosition(); } - // returns velocity in RPM + /** + * Gets left primary encoder velocity. + * + * @return current encoder velocity (in RPM) + */ public double getLeftEncoderVelocity() { return m_leftPrimaryEncoder.getVelocity(); } - // returns velocity in RPM + /** + * Gets right primary encoder velocity. + * + * @return current encoder velocity (in RPM) + */ public double getRightEncoderVelocity() { return m_rightPrimaryEncoder.getVelocity(); } - @Override - public void simulationPeriodic() {} - - // ensures given value is within a specified range + // Ensures given value is within a specified range public double clamp(double val, double min, double max) { if (val > max) { System.out.println("out of range"); @@ -104,7 +134,7 @@ public double clamp(double val, double min, double max) { return val; } - // arcade drive + // Arcade drive public void arcadeDrive(double forwardSpeed, double rotationSpeed) { m_robotDrive.arcadeDrive(forwardSpeed, rotationSpeed); } diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem.java index 7126eef..425da36 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem.java @@ -1,30 +1,55 @@ -// 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 frc.robot.subsystems; +import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.Subsystem; -public class ExampleSubsystem extends Subsystem { - /** Creates a new ExampleSubsystem. */ - public ExampleSubsystem() {} +/** + * Subsystem example. + */ +public class ExampleSubsystem extends SubsystemBase { + /** + * Constructs an ExampleSubsystem subsystem. + */ + public ExampleSubsystem() {} - public Command exampleMethodCommand() { - // Inline construction of command goes here. - // Subsystem::RunOnce implicitly requires `this` subsystem. - return runOnce(() - -> { - /* one-time action goes here */ - }); - } + /** + * Factory method to create command (not being used right now). + * + * @return a command + */ + public Command exampleMethodCommand() { + // Inline construction of command + // Subsystem::RunOnce implicitly requires `this` subsystem + return runOnce( + () -> { + // One-time action + } + ); + } - public boolean exampleCondition() { return false; } + /** + * Method to query a boolean state of the subsystem (not being used right now). + * + * @return value of some boolean subsystem state + */ + public boolean exampleCondition() { + // Query some boolean state, such as a digital sensor + return false; + } - @Override - public void periodic() {} + /** + * Method to be called once every scheduler run (not being used right now). + */ + @Override + public void periodic() { + // Typically used for telemetry and other periodic actions that do not interfere with commands + } - @Override - public void simulationPeriodic() {} + /** + * Method to be called once every scheduler run during simulation (not being used right now). + */ + @Override + public void simulationPeriodic() { + // Can be used to update state of robot + } } diff --git a/src/main/java/frc/robot/subsystems/Intake.java b/src/main/java/frc/robot/subsystems/Intake.java index 3e0f1fc..e281c93 100644 --- a/src/main/java/frc/robot/subsystems/Intake.java +++ b/src/main/java/frc/robot/subsystems/Intake.java @@ -4,55 +4,83 @@ import com.revrobotics.CANSparkMaxLowLevel.MotorType; import com.revrobotics.SparkMaxRelativeEncoder; -import edu.wpi.first.wpilibj2.command.Subsystem; -import frc.robot.Constants.IntakeConstants; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import edu.wpi.first.wpilibj2.command.Command; -/* THIS CODE IS FOR THE OFFSEASON INTAKE; MUST BE UPDATED WHEN INTAKE DEISGN IS FINALIZED */ +import frc.robot.Constants.IntakeConstants; -public class Intake extends Subsystem{ +/** + * Subsystem to control the intake. + */ +public class Intake extends SubsystemBase { + // Motors private final CANSparkMax m_intakeMotor = new CANSparkMax(IntakeConstants.INTAKE_MOTOR_PORT, MotorType.kBrushless); // pivot motor represents the stuff that will control the four bar linkage in the 2024 bot private final CANSparkMax m_pivotIntakeMotor = new CANSparkMax(IntakeConstants.PIVOT_MOTOR_PORT, MotorType.kBrushless); + // Encoder private final SparkMaxRelativeEncoder m_pivotEncoder = (SparkMaxRelativeEncoder) m_pivotIntakeMotor .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, IntakeConstants.COUNTS_PER_REV); - // Constructor for the Intake class - public Intake(){ + /** + * Constructs an Intake subsystem. + */ + public Intake() {} + + /** + * Sets intake motor speed (forward if positive / backward if negative). + * + * @param speed desired motor speed (between -1.0 and 1.0) + */ + public void runIntakeMotor(double speed){ + m_intakeMotor.set(speed); + } + + /** + * Sets intake motor speed to 0 and stops motor. + */ + public void intakeOff() { + m_intakeMotor.set(0); + m_intakeMotor.stopMotor(); } - // returns encoder position + /** + * Gets pivot intake encoder position. + * + * @return current encoder position (in "rotations") + */ public double getPivotEncoderPosition() { return m_pivotEncoder.getPosition(); } - // sets encoder to desired position + /** + * Sets pivot intake encoder position. + * + * @param position desired encoder position (in "rotations") + */ public void setPivotEncoderPosition(double position) { m_pivotEncoder.setPosition(position); } - // initializes encoder position to 0 - MAKE SURE INTAKE IS ALWAYS FULLY UP WHENEVER THIS METHOD IS CALLED + /** + * Initializes pivot intake encoder position to 0. MAKE SURE INTAKE IS ALWAYS FULLY UP WHENEVER THIS METHOD IS CALLED. + */ public void initializePivotEncoderPosition() { - setPivotEncoderPosition(0); // TO DO: WRITE THE SET FUNCTION - } - - // Sets intake motor speed (forward if positive, backward if negative) - public void runIntakeMotor(double speed){ - m_intakeMotor.set(speed); - } - - // Sets intake motor speed to zero and stops motor - public void intakeOff() { - m_intakeMotor.set(0); - m_intakeMotor.stopMotor(); + setPivotEncoderPosition(0); } - // Sets pivot intake motor speed (forward if positive, backward if negative) + /** + * Sets pivot intake motor speed (forward if positive / backward if negative). + * + * @param speed desired motor speed (between -1.0 and 1.0) + */ public void runPivotIntakeMotor(double speed){ m_pivotIntakeMotor.set(speed); } - // Sets pivot intake motor speed to zero and stops motor + /** + * Sets pivot intake motor speed to 0 and stops motor. + */ public void pivotMotorOff() { m_pivotIntakeMotor.set(0); m_pivotIntakeMotor.stopMotor(); From 93b717f261ed811d5f429172849af04b55be26eb Mon Sep 17 00:00:00 2001 From: alleycat6 Date: Mon, 29 Jan 2024 20:36:18 -0800 Subject: [PATCH 2/8] fix more syntax --- src/main/java/frc/robot/Constants.java | 6 +- src/main/java/frc/robot/Main.java | 6 +- src/main/java/frc/robot/Robot.java | 20 ++--- src/main/java/frc/robot/RobotContainer.java | 4 +- .../robot/commands/ArcadeDriveCommand.java | 4 +- .../robot/commands/DistanceDriveCommand.java | 7 +- .../java/frc/robot/subsystems/Climber.java | 4 +- .../java/frc/robot/subsystems/Drivetrain.java | 85 ++++++++++--------- .../robot/subsystems/ExampleSubsystem.java | 3 +- .../java/frc/robot/subsystems/Intake.java | 20 +++-- 10 files changed, 87 insertions(+), 72 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index d0a3fa2..c4b2e2b 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -1,9 +1,9 @@ package frc.robot; /** - * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean - * constants. This class should not be used for any other purpose. All constants should be declared - * globally (i.e. public static). Do not put anything functional in this class. + * The Constants class provides a convenient place for teams to hold robot-wide numerical or + * boolean constants. This class should not be used for any other purpose. All constants should be + * declared globally (i.e. public static). Do not put anything functional in this class. * * It is advised to statically import this class (or one of its inner classes) wherever the * constants are needed, to reduce verbosity. diff --git a/src/main/java/frc/robot/Main.java b/src/main/java/frc/robot/Main.java index 4642233..028613e 100644 --- a/src/main/java/frc/robot/Main.java +++ b/src/main/java/frc/robot/Main.java @@ -3,9 +3,9 @@ import edu.wpi.first.wpilibj.RobotBase; /** - * Do not add any static variables to this class, or any initialization at all. Unless you know what - * you are doing, do not modify this file except to change the parameter class to the startRobot - * call. + * Do not add any static variables to this class, or any initialization at all. Unless you know + * what you are doing, do not modify this file except to change the parameter class to the + * startRobot call. */ public final class Main { /** diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 8cdd556..e1383af 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -21,8 +21,8 @@ public class Robot extends TimedRobot { public Robot() {} /** - * This function is run when the robot is first started up and should be used for any robot-wide - * initialization code. + * This function is run when the robot is first started up and should be used for any + * robot-wide initialization code. */ @Override public void robotInit() { @@ -35,15 +35,15 @@ public void robotInit() { * This function is called every 20 ms, no matter the mode. Use this for items like diagnostics * that you want ran during disabled, autonomous, teleoperated and test. * - * This runs after the mode specific periodic functions, but before LiveWindow and SmartDashboard - * integrated updating. + * This runs after the mode specific periodic functions, but before LiveWindow and + * SmartDashboard integrated updating. */ @Override public void robotPeriodic() { // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled - // commands, running already-scheduled commands, removing finished or interrupted commands, and - // running subsystem periodic() methods. This must be called from the robot's periodic block in - // order for anything in the Command-based framework to work. + // commands, running already-scheduled commands, removing finished or interrupted commands, + // and running subsystem periodic() methods. This must be called from the robot's periodic + // block in order for anything in the Command-based framework to work. CommandScheduler.getInstance().run(); } @@ -83,9 +83,9 @@ public void autonomousPeriodic() {} */ @Override public void teleopInit() { - // This makes sure that the autonomous stops running when teleop starts running. If you want the - // autonomous to continue until interrupted by another command, remove this line or comment it - // out. + // This makes sure that the autonomous stops running when teleop starts running. If you + // want the autonomous to continue until interrupted by another command, remove this line + // or comment it out. if (m_autonomousCommand != null) { m_autonomousCommand.cancel(); } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 48dc95f..e171d98 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -15,8 +15,8 @@ /** * 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 Robot - * periodic methods (other than the scheduler calls). Instead, the structure of the robot (including + * "declarative" paradigm, very little robot logic should actually be handled in the Robot periodic + * methods (other than the scheduler calls). Instead, the structure of the robot (including * subsystems, commands, and trigger mappings) should be declared here. */ public class RobotContainer { diff --git a/src/main/java/frc/robot/commands/ArcadeDriveCommand.java b/src/main/java/frc/robot/commands/ArcadeDriveCommand.java index e30f712..4502c90 100644 --- a/src/main/java/frc/robot/commands/ArcadeDriveCommand.java +++ b/src/main/java/frc/robot/commands/ArcadeDriveCommand.java @@ -39,7 +39,8 @@ public void execute() { double x_val = Math.abs(xJoy) > OperatorConstants.DRIVER_JOYSTICK_DEADBAND ? xJoy : 0.0; double y_val = Math.abs(yJoy) > OperatorConstants.DRIVER_JOYSTICK_DEADBAND ? yJoy : 0.0; - m_drivetrain.arcadeDrive(OperatorConstants.DRIVE_SPEED_ADJUSTMENT * x_val, OperatorConstants.DRIVE_SPEED_ADJUSTMENT * y_val); + m_drivetrain.arcadeDrive(OperatorConstants.DRIVE_SPEED_ADJUSTMENT * x_val, + OperatorConstants.DRIVE_SPEED_ADJUSTMENT * y_val); } /** @@ -56,7 +57,6 @@ public void end(boolean interrupted) {} */ @Override public boolean isFinished() { - return false; } } diff --git a/src/main/java/frc/robot/commands/DistanceDriveCommand.java b/src/main/java/frc/robot/commands/DistanceDriveCommand.java index fc98e5b..f5f60dd 100644 --- a/src/main/java/frc/robot/commands/DistanceDriveCommand.java +++ b/src/main/java/frc/robot/commands/DistanceDriveCommand.java @@ -40,7 +40,8 @@ public void initialize() { */ @Override public void execute() { - m_drivetrain.arcadeDrive(AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance), 0); // drives in the direction of targetDistance + // Drives in the direction of targetDistance + m_drivetrain.arcadeDrive(AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance), 0); } /** @@ -59,7 +60,7 @@ public void end(boolean interrupted) {} public boolean isFinished() { // Calculates if either encoder has moved enough to reach the target distance return (Math.abs(m_drivetrain.getRightEncoderPosition() - m_rightEncoderStart) > - Math.abs(m_targetDistance) || Math.abs(m_drivetrain.getLeftEncoderPosition() - - m_leftEncoderStart) > Math.abs(m_targetDistance)); + Math.abs(m_targetDistance) || Math.abs(m_drivetrain.getLeftEncoderPosition() - + m_leftEncoderStart) > Math.abs(m_targetDistance)); } } diff --git a/src/main/java/frc/robot/subsystems/Climber.java b/src/main/java/frc/robot/subsystems/Climber.java index 621a07d..c386954 100644 --- a/src/main/java/frc/robot/subsystems/Climber.java +++ b/src/main/java/frc/robot/subsystems/Climber.java @@ -65,8 +65,8 @@ public void runClimberMotor(double speed){ * Sets climber motor speed to 0 and stops motor. */ public void climberOff() { - m_climberMotor.set(0); - m_climberMotor.stopMotor(); + m_climberMotor.set(0); + m_climberMotor.stopMotor(); } } diff --git a/src/main/java/frc/robot/subsystems/Drivetrain.java b/src/main/java/frc/robot/subsystems/Drivetrain.java index e096f3d..e9c5a06 100644 --- a/src/main/java/frc/robot/subsystems/Drivetrain.java +++ b/src/main/java/frc/robot/subsystems/Drivetrain.java @@ -21,39 +21,46 @@ public class Drivetrain extends SubsystemBase { public static DifferentialDrive m_robotDrive; // Motors - // Sets up a CAN-enabled SPARK MAX motor controller for each motor (left primary, left secondary, right primary, and right secondary) - public final CANSparkMax m_leftPrimary = new CANSparkMax(DrivetrainConstants.LEFT_MOTOR_1_PORT, - MotorType.kBrushless); - private final CANSparkMax m_leftSecondary = new CANSparkMax(DrivetrainConstants.LEFT_MOTOR_2_PORT, - MotorType.kBrushless); - private final CANSparkMax m_rightPrimary = new CANSparkMax(DrivetrainConstants.RIGHT_MOTOR_1_PORT, - MotorType.kBrushless); - private final CANSparkMax m_rightSecondary = new CANSparkMax(DrivetrainConstants.RIGHT_MOTOR_2_PORT, - MotorType.kBrushless); + // Sets up a CAN-enabled SPARK MAX motor controller for each motor (left primary, left + // secondary, right primary, and right secondary) + public final CANSparkMax m_leftPrimary = new CANSparkMax( + DrivetrainConstants.LEFT_MOTOR_1_PORT, MotorType.kBrushless); + private final CANSparkMax m_leftSecondary = new CANSparkMax( + DrivetrainConstants.LEFT_MOTOR_2_PORT, MotorType.kBrushless); + private final CANSparkMax m_rightPrimary = new CANSparkMax( + DrivetrainConstants.RIGHT_MOTOR_1_PORT, MotorType.kBrushless); + private final CANSparkMax m_rightSecondary = new CANSparkMax( + DrivetrainConstants.RIGHT_MOTOR_2_PORT, MotorType.kBrushless); // Encoders - public final SparkMaxRelativeEncoder m_leftPrimaryEncoder = (SparkMaxRelativeEncoder) m_leftPrimary - .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, DrivetrainConstants.COUNTS_PER_REV); - public final SparkMaxRelativeEncoder m_leftSecondaryEncoder = (SparkMaxRelativeEncoder) m_leftSecondary - .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, DrivetrainConstants.COUNTS_PER_REV); - public final SparkMaxRelativeEncoder m_rightPrimaryEncoder = (SparkMaxRelativeEncoder) m_rightPrimary - .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, DrivetrainConstants.COUNTS_PER_REV); - public final SparkMaxRelativeEncoder m_rightSecondaryEncoder = (SparkMaxRelativeEncoder) m_rightSecondary - .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, DrivetrainConstants.COUNTS_PER_REV); + public final SparkMaxRelativeEncoder m_leftPrimaryEncoder = (SparkMaxRelativeEncoder) + m_leftPrimary.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, + DrivetrainConstants.COUNTS_PER_REV); + public final SparkMaxRelativeEncoder m_leftSecondaryEncoder = (SparkMaxRelativeEncoder) + m_leftSecondary.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, + DrivetrainConstants.COUNTS_PER_REV); + public final SparkMaxRelativeEncoder m_rightPrimaryEncoder = (SparkMaxRelativeEncoder) + m_rightPrimary.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, + DrivetrainConstants.COUNTS_PER_REV); + public final SparkMaxRelativeEncoder m_rightSecondaryEncoder = (SparkMaxRelativeEncoder) + m_rightSecondary.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, + DrivetrainConstants.COUNTS_PER_REV); // Groups // Controls multiple motors at once (for multiple motors per side of the drivetrain) - private final MotorControllerGroup m_leftGroup = new MotorControllerGroup(m_leftPrimary, m_leftSecondary); - private final MotorControllerGroup m_rightGroup = new MotorControllerGroup(m_rightPrimary, m_rightSecondary); + private final MotorControllerGroup m_leftGroup = new MotorControllerGroup(m_leftPrimary, + m_leftSecondary); + private final MotorControllerGroup m_rightGroup = new MotorControllerGroup(m_rightPrimary, + m_rightSecondary); /** * Constructs a Drivetrain subsystem. */ public Drivetrain(OI humanControl) { - m_robotDrive = new DifferentialDrive(m_leftGroup, m_rightGroup); - m_humanControl = humanControl; + m_robotDrive = new DifferentialDrive(m_leftGroup, m_rightGroup); + m_humanControl = humanControl; - configDrivetrainMotors(); + configDrivetrainMotors(); } /** @@ -61,7 +68,8 @@ public Drivetrain(OI humanControl) { */ @Override public void periodic() { - // Typically used for telemetry and other periodic actions that do not interfere with commands + // Typically used for telemetry and other periodic actions that do not interfere with + // commands } /** @@ -77,13 +85,14 @@ public void simulationPeriodic() { */ // public void configDrivetrainMotors() { - // Makes the secondary motors follow the primary ones - m_leftSecondary.follow(m_leftPrimary); - m_rightSecondary.follow(m_rightPrimary); - - // Inverts the right side to account for the fact that that side initially moves backwards for positive velocity and forwards for negative - m_leftGroup.setInverted(false); - m_rightGroup.setInverted(true); + // Makes the secondary motors follow the primary ones + m_leftSecondary.follow(m_leftPrimary); + m_rightSecondary.follow(m_rightPrimary); + + // Inverts the right side to account for the fact that that side initially moves backwards + // for positive velocity and forwards for negative + m_leftGroup.setInverted(false); + m_rightGroup.setInverted(true); } /** @@ -124,14 +133,14 @@ public double getRightEncoderVelocity() { // Ensures given value is within a specified range public double clamp(double val, double min, double max) { - if (val > max) { - System.out.println("out of range"); - return max; - } else if (val < min) { - System.out.println("out of range"); - return min; - } - return val; + if (val > max) { + System.out.println("out of range"); + return max; + } else if (val < min) { + System.out.println("out of range"); + return min; + } + return val; } // Arcade drive diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem.java index 425da36..16925d5 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem.java @@ -42,7 +42,8 @@ public boolean exampleCondition() { */ @Override public void periodic() { - // Typically used for telemetry and other periodic actions that do not interfere with commands + // Typically used for telemetry and other periodic actions that do not interfere with + // commands } /** diff --git a/src/main/java/frc/robot/subsystems/Intake.java b/src/main/java/frc/robot/subsystems/Intake.java index e281c93..cb44600 100644 --- a/src/main/java/frc/robot/subsystems/Intake.java +++ b/src/main/java/frc/robot/subsystems/Intake.java @@ -14,13 +14,16 @@ */ public class Intake extends SubsystemBase { // Motors - private final CANSparkMax m_intakeMotor = new CANSparkMax(IntakeConstants.INTAKE_MOTOR_PORT, MotorType.kBrushless); - // pivot motor represents the stuff that will control the four bar linkage in the 2024 bot - private final CANSparkMax m_pivotIntakeMotor = new CANSparkMax(IntakeConstants.PIVOT_MOTOR_PORT, MotorType.kBrushless); + private final CANSparkMax m_intakeMotor = new CANSparkMax(IntakeConstants.INTAKE_MOTOR_PORT, + MotorType.kBrushless); + // Pivot motor represents the stuff that will control the four bar linkage in the 2024 bot + private final CANSparkMax m_pivotIntakeMotor = new CANSparkMax( + IntakeConstants.PIVOT_MOTOR_PORT, MotorType.kBrushless); // Encoder - private final SparkMaxRelativeEncoder m_pivotEncoder = (SparkMaxRelativeEncoder) m_pivotIntakeMotor - .getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, IntakeConstants.COUNTS_PER_REV); + private final SparkMaxRelativeEncoder m_pivotEncoder = (SparkMaxRelativeEncoder) + m_pivotIntakeMotor.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, + IntakeConstants.COUNTS_PER_REV); /** * Constructs an Intake subsystem. @@ -63,9 +66,10 @@ public void setPivotEncoderPosition(double position) { } /** - * Initializes pivot intake encoder position to 0. MAKE SURE INTAKE IS ALWAYS FULLY UP WHENEVER THIS METHOD IS CALLED. + * Initializes pivot intake encoder position to 0. */ public void initializePivotEncoderPosition() { + // MAKE SURE INTAKE IS ALWAYS FULLY UP WHENEVER THIS METHOD IS CALLED. setPivotEncoderPosition(0); } @@ -82,7 +86,7 @@ public void runPivotIntakeMotor(double speed){ * Sets pivot intake motor speed to 0 and stops motor. */ public void pivotMotorOff() { - m_pivotIntakeMotor.set(0); - m_pivotIntakeMotor.stopMotor(); + m_pivotIntakeMotor.set(0); + m_pivotIntakeMotor.stopMotor(); } } From 9a65616d2ba5d67e1ab483090aaec9c7a9cec85e Mon Sep 17 00:00:00 2001 From: alleycat6 Date: Mon, 29 Jan 2024 20:37:12 -0800 Subject: [PATCH 3/8] fix more syntax again sorry!!! --- src/main/java/frc/robot/subsystems/Climber.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/Climber.java b/src/main/java/frc/robot/subsystems/Climber.java index c386954..8aad0c9 100644 --- a/src/main/java/frc/robot/subsystems/Climber.java +++ b/src/main/java/frc/robot/subsystems/Climber.java @@ -15,12 +15,12 @@ public class Climber extends SubsystemBase { // Instance variables // Motor private final CANSparkMax m_climberMotor = new CANSparkMax(ClimberConstants.CLIMBER_MOTOR_PORT, - MotorType.kBrushless); + MotorType.kBrushless); // Encoder private final SparkMaxRelativeEncoder m_climberEncoder = (SparkMaxRelativeEncoder) - m_climberMotor.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, - ClimberConstants.COUNTS_PER_REV); + m_climberMotor.getEncoder(SparkMaxRelativeEncoder.Type.kHallSensor, + ClimberConstants.COUNTS_PER_REV); /** * Constructs a Climber subsystem. From 66b48a792d3c8fde0bb64bb22891a1c4254064c5 Mon Sep 17 00:00:00 2001 From: amelia-chen Date: Mon, 26 Feb 2024 20:44:25 -0800 Subject: [PATCH 4/8] get rid of old command --- src/main/java/frc/robot/Constants.java | 4 +- .../robot/commands/PivotBackwardCommand.java | 58 ------------------- 2 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 src/main/java/frc/robot/commands/PivotBackwardCommand.java diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index f07613a..489c4e3 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -45,8 +45,8 @@ public static class IntakeConstants { public static class IndexerConstants { public static final int INDEXER_MOTOR_PORT = 6; - public static final double INDEXER_MOTOR_SPEED_DOWN = 0.4; // TODO: replace with values from beam break branch - public static final double INDEXER_MOTOR_SPEED_UP = -0.4; // TODO: replace with values from beam break branch + public static final double INDEXER_MOTOR_SPEED_DOWN = 0.4; // TO DO: replace with values from beam break branch + public static final double INDEXER_MOTOR_SPEED_UP = -0.4; // TO DO: replace with values from beam break branch public static final double INDEXER_MOTOR_SPEED_DOWN_BACKUP = 0.2; // for testing/backup, finalized 02/23/2024 public static final double INDEXER_MOTOR_SPEED_UP_BACKUP = -0.2; // for testing/backup, finalized 02/23/2024 diff --git a/src/main/java/frc/robot/commands/PivotBackwardCommand.java b/src/main/java/frc/robot/commands/PivotBackwardCommand.java deleted file mode 100644 index 86c21e0..0000000 --- a/src/main/java/frc/robot/commands/PivotBackwardCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -package frc.robot.commands; - -import edu.wpi.first.wpilibj2.command.Command; - -import frc.robot.subsystems.Intake; -import frc.robot.Constants.IntakeConstants; - -/** - * Command to run pivot backward. Uses Intake subsystem. - */ -public class PivotBackwardCommand extends Command { - // Instance variables - private Intake m_intake; - private double m_encoderStart; - - /** - * Constructs a PivotBackwardCommand command. - */ - public PivotBackwardCommand(Intake intake){ - m_intake = intake; - } - - /** - * Method called once per time the command is scheduled. - */ - @Override - public void initialize() { - m_encoderStart = m_intake.getPivotEncoderPosition(); - } - - /** - * Method called repeatedly while the command is scheduled (every time the scheduler runs). - */ - @Override - public void execute() { - m_intake.runPivotIntakeMotor(-IntakeConstants.PIVOT_MOTOR_SPEED); - } - - /** - * Method called once when the command ends (whether it finishes normally or is interrupted). - */ - @Override - public void end(boolean interrupted) { - m_intake.pivotMotorOff(); - } - - /** - * Method called repeatedly while the command is scheduled (returns false while the command is - * scheduled, true when the command should end). - * - * @return whether command is finished - */ - @Override - public boolean isFinished() { - return m_intake.getPivotEncoderPosition() <= m_encoderStart - IntakeConstants.PIVOT_DELTA; - } -} - From 87166b2be86016b29849d30fa0558796e2dae809 Mon Sep 17 00:00:00 2001 From: amelia-chen Date: Mon, 26 Feb 2024 20:50:50 -0800 Subject: [PATCH 5/8] fix indentations --- .../robot/commands/DistanceDriveCommand.java | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/main/java/frc/robot/commands/DistanceDriveCommand.java b/src/main/java/frc/robot/commands/DistanceDriveCommand.java index cfb25ac..90ceb56 100644 --- a/src/main/java/frc/robot/commands/DistanceDriveCommand.java +++ b/src/main/java/frc/robot/commands/DistanceDriveCommand.java @@ -14,47 +14,47 @@ * Command to drive a set distance. Uses Drivetrain subsystem. */ public class DistanceDriveCommand extends Command { - @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) - private final Drivetrain m_drivetrain; - private double m_targetDistance; - - /** - * A dead reckoning drive command. - * Takes in target distance in meters and drives straight that amount. - */ - public DistanceDriveCommand(Drivetrain drivetrain, double targetDistance) { - m_drivetrain = drivetrain; - m_targetDistance = targetDistance * DrivetrainConstants.METERS_TO_ROTATIONS; // convert meters to motor rotations - // System.out.println("Target meters: " + targetDistance + ", target rotations: " + m_targetDistance); - - addRequirements(drivetrain); - } - - @Override - public void initialize() { - // resets positions of encoders - m_drivetrain.setRightEncoder(0); - m_drivetrain.setleftEncoder(0); - } - - @Override - public void execute() { - double thrust = AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance); // drives in the direction of targetDistance - m_drivetrain.tankDrive(-thrust, -thrust); - // System.out.println("Left encoder position: " + m_drivetrain.getLeftEncoderPosition() + ", Right encoder position: " + m_drivetrain.getRightEncoderPosition()); - } - - @Override - public void end(boolean interrupted) { - m_drivetrain.stopMotors(); - m_drivetrain.setRightEncoder(0); - m_drivetrain.setleftEncoder(0); - } - - @Override - public boolean isFinished() { - // calculates if either encoder has moved enough to reach the target distance - return (Math.abs(m_drivetrain.getRightEncoderPosition()) > Math.abs(m_targetDistance) - || Math.abs(m_drivetrain.getLeftEncoderPosition()) > Math.abs(m_targetDistance)); - } + @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) + private final Drivetrain m_drivetrain; + private double m_targetDistance; + + /** + * A dead reckoning drive command. + * Takes in target distance in meters and drives straight that amount. + */ + public DistanceDriveCommand(Drivetrain drivetrain, double targetDistance) { + m_drivetrain = drivetrain; + m_targetDistance = targetDistance * DrivetrainConstants.METERS_TO_ROTATIONS; // convert meters to motor rotations + // System.out.println("Target meters: " + targetDistance + ", target rotations: " + m_targetDistance); + + addRequirements(drivetrain); + } + + @Override + public void initialize() { + // resets positions of encoders + m_drivetrain.setRightEncoder(0); + m_drivetrain.setleftEncoder(0); + } + + @Override + public void execute() { + double thrust = AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance); // drives in the direction of targetDistance + m_drivetrain.tankDrive(-thrust, -thrust); + // System.out.println("Left encoder position: " + m_drivetrain.getLeftEncoderPosition() + ", Right encoder position: " + m_drivetrain.getRightEncoderPosition()); + } + + @Override + public void end(boolean interrupted) { + m_drivetrain.stopMotors(); + m_drivetrain.setRightEncoder(0); + m_drivetrain.setleftEncoder(0); + } + + @Override + public boolean isFinished() { + // calculates if either encoder has moved enough to reach the target distance + return (Math.abs(m_drivetrain.getRightEncoderPosition()) > Math.abs(m_targetDistance) + || Math.abs(m_drivetrain.getLeftEncoderPosition()) > Math.abs(m_targetDistance)); + } } From b9dc62022f77db73a9a6f879c21958492e4f4dee Mon Sep 17 00:00:00 2001 From: alleycat6 Date: Mon, 26 Feb 2024 20:51:10 -0800 Subject: [PATCH 6/8] fix indenting --- .../robot/commands/DistanceDriveCommand.java | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/main/java/frc/robot/commands/DistanceDriveCommand.java b/src/main/java/frc/robot/commands/DistanceDriveCommand.java index cfb25ac..90ceb56 100644 --- a/src/main/java/frc/robot/commands/DistanceDriveCommand.java +++ b/src/main/java/frc/robot/commands/DistanceDriveCommand.java @@ -14,47 +14,47 @@ * Command to drive a set distance. Uses Drivetrain subsystem. */ public class DistanceDriveCommand extends Command { - @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) - private final Drivetrain m_drivetrain; - private double m_targetDistance; - - /** - * A dead reckoning drive command. - * Takes in target distance in meters and drives straight that amount. - */ - public DistanceDriveCommand(Drivetrain drivetrain, double targetDistance) { - m_drivetrain = drivetrain; - m_targetDistance = targetDistance * DrivetrainConstants.METERS_TO_ROTATIONS; // convert meters to motor rotations - // System.out.println("Target meters: " + targetDistance + ", target rotations: " + m_targetDistance); - - addRequirements(drivetrain); - } - - @Override - public void initialize() { - // resets positions of encoders - m_drivetrain.setRightEncoder(0); - m_drivetrain.setleftEncoder(0); - } - - @Override - public void execute() { - double thrust = AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance); // drives in the direction of targetDistance - m_drivetrain.tankDrive(-thrust, -thrust); - // System.out.println("Left encoder position: " + m_drivetrain.getLeftEncoderPosition() + ", Right encoder position: " + m_drivetrain.getRightEncoderPosition()); - } - - @Override - public void end(boolean interrupted) { - m_drivetrain.stopMotors(); - m_drivetrain.setRightEncoder(0); - m_drivetrain.setleftEncoder(0); - } - - @Override - public boolean isFinished() { - // calculates if either encoder has moved enough to reach the target distance - return (Math.abs(m_drivetrain.getRightEncoderPosition()) > Math.abs(m_targetDistance) - || Math.abs(m_drivetrain.getLeftEncoderPosition()) > Math.abs(m_targetDistance)); - } + @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) + private final Drivetrain m_drivetrain; + private double m_targetDistance; + + /** + * A dead reckoning drive command. + * Takes in target distance in meters and drives straight that amount. + */ + public DistanceDriveCommand(Drivetrain drivetrain, double targetDistance) { + m_drivetrain = drivetrain; + m_targetDistance = targetDistance * DrivetrainConstants.METERS_TO_ROTATIONS; // convert meters to motor rotations + // System.out.println("Target meters: " + targetDistance + ", target rotations: " + m_targetDistance); + + addRequirements(drivetrain); + } + + @Override + public void initialize() { + // resets positions of encoders + m_drivetrain.setRightEncoder(0); + m_drivetrain.setleftEncoder(0); + } + + @Override + public void execute() { + double thrust = AutoConstants.TAXI_AUTO_SPEED*Math.signum(m_targetDistance); // drives in the direction of targetDistance + m_drivetrain.tankDrive(-thrust, -thrust); + // System.out.println("Left encoder position: " + m_drivetrain.getLeftEncoderPosition() + ", Right encoder position: " + m_drivetrain.getRightEncoderPosition()); + } + + @Override + public void end(boolean interrupted) { + m_drivetrain.stopMotors(); + m_drivetrain.setRightEncoder(0); + m_drivetrain.setleftEncoder(0); + } + + @Override + public boolean isFinished() { + // calculates if either encoder has moved enough to reach the target distance + return (Math.abs(m_drivetrain.getRightEncoderPosition()) > Math.abs(m_targetDistance) + || Math.abs(m_drivetrain.getLeftEncoderPosition()) > Math.abs(m_targetDistance)); + } } From 60124c0856d6f9fa93f716b297f243ac9a038f87 Mon Sep 17 00:00:00 2001 From: alleycat6 Date: Mon, 26 Feb 2024 21:02:33 -0800 Subject: [PATCH 7/8] fix indenting again --- src/main/java/frc/robot/Constants.java | 112 +++++++------- src/main/java/frc/robot/RobotContainer.java | 141 ++++++++---------- .../commands/HoodPivotForwardCommand.java | 4 +- .../robot/commands/IntakeIndexCommand.java | 2 - .../commands/IntakeIndexCommandBackup.java | 2 - .../robot/commands/OuttakeIndexCommand.java | 2 - .../frc/robot/commands/PrintHoodEncoder.java | 2 +- .../java/frc/robot/subsystems/Intake.java | 67 +++++---- .../java/frc/robot/subsystems/Shooter.java | 63 ++++---- 9 files changed, 191 insertions(+), 204 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 489c4e3..bab4dd6 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -12,83 +12,83 @@ */ public final class Constants { - public static class OperatorConstants { - public static final int DRIVER_XBOX_PORT = 0; - public static final int COPILOT_XBOX_PORT = 1; + public static class OperatorConstants { + public static final int DRIVER_XBOX_PORT = 0; + public static final int COPILOT_XBOX_PORT = 1; - public static final double DRIVER_JOYSTICK_DEADBAND = 0.1; - public static final double DRIVE_SPEED_ADJUSTMENT = 0.8; - } + public static final double DRIVER_JOYSTICK_DEADBAND = 0.1; + public static final double DRIVE_SPEED_ADJUSTMENT = 0.8; + } - public static class DrivetrainConstants { - public static final int LEFT_MOTOR_1_PORT = 1; - public static final int LEFT_MOTOR_2_PORT = 2; - public static final int RIGHT_MOTOR_1_PORT = 3; - public static final int RIGHT_MOTOR_2_PORT = 4; + public static class DrivetrainConstants { + public static final int LEFT_MOTOR_1_PORT = 1; + public static final int LEFT_MOTOR_2_PORT = 2; + public static final int RIGHT_MOTOR_1_PORT = 3; + public static final int RIGHT_MOTOR_2_PORT = 4; - public static final int COUNTS_PER_REV = 42; + public static final int COUNTS_PER_REV = 42; - // 1 meter = 39.37 inches = 2.088 wheel rotations = 17.664 motor rotations (assuming gear ratio = 8.46) - public static final double METERS_TO_ROTATIONS = 17.664; - public static final double DEGREES_TO_ROTATIONS = 0.1; // value accurate as of 2/13/24 - } + // 1 meter = 39.37 inches = 2.088 wheel rotations = 17.664 motor rotations (assuming gear ratio = 8.46) + public static final double METERS_TO_ROTATIONS = 17.664; + public static final double DEGREES_TO_ROTATIONS = 0.1; // value accurate as of 2/13/24 + } - public static class IntakeConstants { - public static final int INTAKE_MOTOR_PORT = 5; + public static class IntakeConstants { + public static final int INTAKE_MOTOR_PORT = 5; - public static final double INTAKE_MOTOR_SPEED_IN = 0.4; - public static final double INTAKE_MOTOR_SPEED_OUT = -0.4; + public static final double INTAKE_MOTOR_SPEED_IN = 0.4; + public static final double INTAKE_MOTOR_SPEED_OUT = -0.4; - public static final int COUNTS_PER_REV = 42; - } + public static final int COUNTS_PER_REV = 42; + } - public static class IndexerConstants { - public static final int INDEXER_MOTOR_PORT = 6; + public static class IndexerConstants { + public static final int INDEXER_MOTOR_PORT = 6; - public static final double INDEXER_MOTOR_SPEED_DOWN = 0.4; // TO DO: replace with values from beam break branch - public static final double INDEXER_MOTOR_SPEED_UP = -0.4; // TO DO: replace with values from beam break branch + public static final double INDEXER_MOTOR_SPEED_DOWN = 0.4; // TO DO: replace with values from beam break branch + public static final double INDEXER_MOTOR_SPEED_UP = -0.4; // TO DO: replace with values from beam break branch - public static final double INDEXER_MOTOR_SPEED_DOWN_BACKUP = 0.2; // for testing/backup, finalized 02/23/2024 - public static final double INDEXER_MOTOR_SPEED_UP_BACKUP = -0.2; // for testing/backup, finalized 02/23/2024 + public static final double INDEXER_MOTOR_SPEED_DOWN_BACKUP = 0.2; // for testing/backup, finalized 02/23/2024 + public static final double INDEXER_MOTOR_SPEED_UP_BACKUP = -0.2; // for testing/backup, finalized 02/23/2024 - public static final int COUNTS_PER_REV = 42; - } + public static final int COUNTS_PER_REV = 42; + } - public static class ShooterConstants { - public static final int SHOOTER_MOTOR_PORT = 7; + public static class ShooterConstants { + public static final int SHOOTER_MOTOR_PORT = 7; - public static final double SHOOTER_MOTOR_SPEED_AMP = HoodConstants.HOOD_MOTOR_SPEED / -2.0; // should be half of HOOD_MOTOR_SPEED, finalized 02/23/2024 - public static final double SHOOTER_MOTOR_SPEED_SPEAKER = -0.5; // correct as of 2/25/24 - public static final double SHOOTER_MOTOR_SPEED_OUT = -0.5; // constant for testing + public static final double SHOOTER_MOTOR_SPEED_AMP = HoodConstants.HOOD_MOTOR_SPEED / -2.0; // should be half of HOOD_MOTOR_SPEED, finalized 02/23/2024 + public static final double SHOOTER_MOTOR_SPEED_SPEAKER = -0.5; // correct as of 2/25/24 + public static final double SHOOTER_MOTOR_SPEED_OUT = -0.5; // constant for testing - public static final int COUNTS_PER_REV = 42; - } + public static final int COUNTS_PER_REV = 42; + } - public static class HoodConstants { - public static final int HOOD_MOTOR_PORT = 9; // correct as of 2/20/24 - public static final int PIVOT_MOTOR_PORT = 8; // correct as of 2/20/24 + public static class HoodConstants { + public static final int HOOD_MOTOR_PORT = 9; // correct as of 2/20/24 + public static final int PIVOT_MOTOR_PORT = 8; // correct as of 2/20/24 - public static final double HOOD_MOTOR_SPEED = 0.4; // should be double of SHOOTER_MOTOR_SPEED_AMP, finalized 02/23/2024 + public static final double HOOD_MOTOR_SPEED = 0.4; // should be double of SHOOTER_MOTOR_SPEED_AMP, finalized 02/23/2024 - public static final double PIVOT_MOTOR_SPEED = 0.5; // finalized 02/23/2024 - public static final double SLOW_PIVOT_MOTOR_SPEED = 0.2; // finalized 02/23/2024 + public static final double PIVOT_MOTOR_SPEED = 0.5; // finalized 02/23/2024 + public static final double SLOW_PIVOT_MOTOR_SPEED = 0.2; // finalized 02/23/2024 - // assuming hood back is at encoder position 0, PIVOT_DISTANCE is the required encoder position for the hood to be forward - public static final double PIVOT_DISTANCE = -48.20; // correct as of 2/20/24 + // assuming hood back is at encoder position 0, PIVOT_DISTANCE is the required encoder position for the hood to be forward + public static final double PIVOT_DISTANCE = -48.20; // correct as of 2/20/24 - public static final int COUNTS_PER_REV = 42; - } + public static final int COUNTS_PER_REV = 42; + } - public static class ClimberConstants { - public static final int CLIMBER_MOTOR_PORT = 100; // TO DO: set ID val + public static class ClimberConstants { + public static final int CLIMBER_MOTOR_PORT = 100; // TO DO: set ID val - public static final int COUNTS_PER_REV = 42; - } + public static final int COUNTS_PER_REV = 42; + } - public static class AutoConstants { - public static final double TAXI_AUTO_TARGET_DISTANCE = 25; // distance in meters to taxi (unset for 2024) - public static final double TAXI_AUTO_SPEED = 0.4; // (temp) speed of robot during taxi auto - public static final double ROTATION_SPEED = 0.5; - } + public static class AutoConstants { + public static final double TAXI_AUTO_TARGET_DISTANCE = 25; // distance in meters to taxi (unset for 2024) + public static final double TAXI_AUTO_SPEED = 0.4; // (temp) speed of robot during taxi auto + public static final double ROTATION_SPEED = 0.5; + } } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 2d8fe37..dc765f5 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -59,80 +59,71 @@ * subsystems, commands, and trigger mappings) should be declared here. */ public class RobotContainer { - // The robot's subsystems and commands are defined here... - private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem(); - private static final OI m_humanControl = new OI(); - public static final Drivetrain m_drivetrain = new Drivetrain(m_humanControl); - private static final Indexer m_indexer = new Indexer(); - private static final Intake m_intake = new Intake(); - private static final Shooter m_shooter = new Shooter(); - private static final Hood m_hood = new Hood(); - - public SendableChooser m_chooser = new SendableChooser<>(); - // public static SequentialCommandGroup m_driveTwice = new SequentialCommandGroup( - // // new SuctionOnCommand(m_gripper), - // // new ArmPlaceHighCommand(m_arm), - // // new SuctionOffCommand(m_gripper), - // new DistanceDriveCommand(m_drivetrain, 1), - // new DistanceDriveCommand(m_drivetrain, 2) - // ); - - /** The container for the robot. Contains subsystems, OI devices, and commands. */ - public RobotContainer() { - // Configure the trigger bindings - configureBindings(); - - // set default commands - m_drivetrain.setDefaultCommand(new ArcadeDriveCommand(m_drivetrain, m_humanControl)); - // m_hood.setDefaultCommand(new PrintHoodEncoder(m_hood)); - - // auto routines - m_chooser.addOption("Drive 2 meters", new DistanceDriveCommand(m_drivetrain, 2)); - m_chooser.addOption("Rotate 90 degrees", new RotationCommand(m_drivetrain, 90)); - // m_chooser.addOption("Double drive", m_driveTwice); - - ShuffleboardTab compTab = Shuffleboard.getTab("Comp HUD"); - compTab.add("Auto Chooser", m_chooser).withSize(3, 2); - } - - /** - * Use this method to define your trigger->command mappings. Triggers can be created via the - * {@link Trigger#Trigger(java.util.function.BooleanSupplier)} constructor with an arbitrary - * predicate, or via the named factories in {@link - * edu.wpi.first.wpilibj2.command.button.CommandGenericHID}'s subclasses for {@link - * CommandXboxController Xbox}/{@link edu.wpi.first.wpilibj2.command.button.CommandPS4Controller - * PS4} controllers or {@link edu.wpi.first.wpilibj2.command.button.CommandJoystick Flight - * joysticks}. - */ - private void configureBindings() { // temp for testing - - OI.m_coPilotXbox.a().whileTrue(new ShooterHoodBackward(m_shooter, m_hood)); // emergency use button that should not be pressed in normal circumstances - OI.m_coPilotXbox.b().whileTrue(new OuttakeIndexCommand(m_indexer, m_intake)); // outtaking should not normally be necessary - OI.m_coPilotXbox.x().whileTrue(new IntakeIndexCommand(m_indexer, m_intake)); - OI.m_coPilotXbox.y().whileTrue(new IndexerUpCommand(m_indexer)); - - OI.m_coPilotXbox.leftTrigger().whileTrue(new ShooterSpeakerCommand(m_shooter)); - OI.m_coPilotXbox.rightTrigger().whileTrue(new ShooterAmpCommand(m_shooter, m_hood)); - - OI.m_coPilotXbox.leftBumper().whileTrue(new HoodPivotForwardCommand(m_hood)); - OI.m_coPilotXbox.rightBumper().whileTrue(new HoodPivotBackwardCommand(m_hood)); - - // back and start buttons are backup commands for if the hood encoders mess up - OI.m_coPilotXbox.back().whileTrue(new HoodPivotForwardBackup(m_hood)); - OI.m_coPilotXbox.start().whileTrue(new HoodPivotBackwardBackup(m_hood)); - - OI.m_coPilotXbox.leftStick().whileTrue(new IntakeIndexCommandBackup(m_indexer, m_intake)); // backup intakeindex command in case beam break has issues - // OI.m_coPilotXbox.leftStick().whileTrue(new HoodRollerCommand(m_hood)); // for testing only! + // The robot's subsystems and commands are defined here... + private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem(); + private static final OI m_humanControl = new OI(); + public static final Drivetrain m_drivetrain = new Drivetrain(m_humanControl); + private static final Indexer m_indexer = new Indexer(); + private static final Intake m_intake = new Intake(); + private static final Shooter m_shooter = new Shooter(); + private static final Hood m_hood = new Hood(); + + public SendableChooser m_chooser = new SendableChooser<>(); + + /** The container for the robot. Contains subsystems, OI devices, and commands. */ + public RobotContainer() { + // Configure the trigger bindings + configureBindings(); + + // set default commands + m_drivetrain.setDefaultCommand(new ArcadeDriveCommand(m_drivetrain, m_humanControl)); + // m_hood.setDefaultCommand(new PrintHoodEncoder(m_hood)); + + // auto routines + m_chooser.addOption("Drive 2 meters", new DistanceDriveCommand(m_drivetrain, 2)); + m_chooser.addOption("Rotate 90 degrees", new RotationCommand(m_drivetrain, 90)); + // m_chooser.addOption("Double drive", m_driveTwice); + + ShuffleboardTab compTab = Shuffleboard.getTab("Comp HUD"); + compTab.add("Auto Chooser", m_chooser).withSize(3, 2); + } + + /** + * Use this method to define your trigger->command mappings. Triggers can be created via the + * {@link Trigger#Trigger(java.util.function.BooleanSupplier)} constructor with an arbitrary + * predicate, or via the named factories in {@link + * edu.wpi.first.wpilibj2.command.button.CommandGenericHID}'s subclasses for {@link + * CommandXboxController Xbox}/{@link edu.wpi.first.wpilibj2.command.button.CommandPS4Controller + * PS4} controllers or {@link edu.wpi.first.wpilibj2.command.button.CommandJoystick Flight + * joysticks}. + */ + private void configureBindings() { // temp for testing + OI.m_coPilotXbox.a().whileTrue(new ShooterHoodBackward(m_shooter, m_hood)); // emergency use button that should not be pressed in normal circumstances + OI.m_coPilotXbox.b().whileTrue(new OuttakeIndexCommand(m_indexer, m_intake)); // outtaking should not normally be necessary + OI.m_coPilotXbox.x().whileTrue(new IntakeIndexCommand(m_indexer, m_intake)); + OI.m_coPilotXbox.y().whileTrue(new IndexerUpCommand(m_indexer)); + + OI.m_coPilotXbox.leftTrigger().whileTrue(new ShooterSpeakerCommand(m_shooter)); + OI.m_coPilotXbox.rightTrigger().whileTrue(new ShooterAmpCommand(m_shooter, m_hood)); + + OI.m_coPilotXbox.leftBumper().whileTrue(new HoodPivotForwardCommand(m_hood)); + OI.m_coPilotXbox.rightBumper().whileTrue(new HoodPivotBackwardCommand(m_hood)); + + // back and start buttons are backup commands for if the hood encoders mess up + OI.m_coPilotXbox.back().whileTrue(new HoodPivotForwardBackup(m_hood)); + OI.m_coPilotXbox.start().whileTrue(new HoodPivotBackwardBackup(m_hood)); - } - - /** - * Use this to pass the autonomous command to the main {@link Robot} class. - * - * @return the command to run in autonomous - */ - public Command getAutonomousCommand() { - // the selected command from shuffleboard that will be run in autonomous - return m_chooser.getSelected(); - } + OI.m_coPilotXbox.leftStick().whileTrue(new IntakeIndexCommandBackup(m_indexer, m_intake)); // backup intakeindex command in case beam break has issues + // OI.m_coPilotXbox.leftStick().whileTrue(new HoodRollerCommand(m_hood)); // for testing only! + } + + /** + * Use this to pass the autonomous command to the main {@link Robot} class. + * + * @return the command to run in autonomous + */ + public Command getAutonomousCommand() { + // the selected command from shuffleboard that will be run in autonomous + return m_chooser.getSelected(); + } } \ No newline at end of file diff --git a/src/main/java/frc/robot/commands/HoodPivotForwardCommand.java b/src/main/java/frc/robot/commands/HoodPivotForwardCommand.java index 6d5049f..acfc45e 100644 --- a/src/main/java/frc/robot/commands/HoodPivotForwardCommand.java +++ b/src/main/java/frc/robot/commands/HoodPivotForwardCommand.java @@ -26,9 +26,9 @@ public void initialize() { @Override public void execute() { // If hood pass 80% of pivot distance, it slows - if(Math.abs(m_hood.getPivotEncoderPosition()) > 0.8*Math.abs(HoodConstants.PIVOT_DISTANCE)){ + if (Math.abs(m_hood.getPivotEncoderPosition()) > (0.8 * Math.abs(HoodConstants.PIVOT_DISTANCE))) { m_hood.runPivotHoodMotor(-HoodConstants.SLOW_PIVOT_MOTOR_SPEED); - }else{ + } else { m_hood.runPivotHoodMotor(-HoodConstants.PIVOT_MOTOR_SPEED); } System.out.println(m_hood.getPivotEncoderPosition()); diff --git a/src/main/java/frc/robot/commands/IntakeIndexCommand.java b/src/main/java/frc/robot/commands/IntakeIndexCommand.java index 7e04b2e..42337a3 100644 --- a/src/main/java/frc/robot/commands/IntakeIndexCommand.java +++ b/src/main/java/frc/robot/commands/IntakeIndexCommand.java @@ -31,14 +31,12 @@ public void initialize() { public void execute() { m_indexer.runIndexerMotor(IndexerConstants.INDEXER_MOTOR_SPEED_UP); m_intake.runIntakeMotor(IntakeConstants.INTAKE_MOTOR_SPEED_IN); - } @Override public void end(boolean interrupted) { m_indexer.indexerOff(); m_intake.intakeOff(); - } @Override diff --git a/src/main/java/frc/robot/commands/IntakeIndexCommandBackup.java b/src/main/java/frc/robot/commands/IntakeIndexCommandBackup.java index deb54db..ce47c7e 100644 --- a/src/main/java/frc/robot/commands/IntakeIndexCommandBackup.java +++ b/src/main/java/frc/robot/commands/IntakeIndexCommandBackup.java @@ -29,14 +29,12 @@ public void initialize() { public void execute() { m_indexer.runIndexerMotor(IndexerConstants.INDEXER_MOTOR_SPEED_UP_BACKUP); m_intake.runIntakeMotor(IntakeConstants.INTAKE_MOTOR_SPEED_IN); - } @Override public void end(boolean interrupted) { m_indexer.indexerOff(); m_intake.intakeOff(); - } @Override diff --git a/src/main/java/frc/robot/commands/OuttakeIndexCommand.java b/src/main/java/frc/robot/commands/OuttakeIndexCommand.java index 589cfa1..69c8922 100644 --- a/src/main/java/frc/robot/commands/OuttakeIndexCommand.java +++ b/src/main/java/frc/robot/commands/OuttakeIndexCommand.java @@ -29,14 +29,12 @@ public void initialize() { public void execute() { m_indexer.runIndexerMotor(IndexerConstants.INDEXER_MOTOR_SPEED_DOWN); m_intake.runIntakeMotor(IntakeConstants.INTAKE_MOTOR_SPEED_OUT); - } @Override public void end(boolean interrupted) { m_indexer.indexerOff(); m_intake.intakeOff(); - } @Override diff --git a/src/main/java/frc/robot/commands/PrintHoodEncoder.java b/src/main/java/frc/robot/commands/PrintHoodEncoder.java index 3a96875..dfab3f0 100644 --- a/src/main/java/frc/robot/commands/PrintHoodEncoder.java +++ b/src/main/java/frc/robot/commands/PrintHoodEncoder.java @@ -20,7 +20,7 @@ public void initialize() { @Override public void execute() { - System.out.println(m_hood.getPivotEncoderPosition()); + System.out.println(m_hood.getPivotEncoderPosition()); } @Override diff --git a/src/main/java/frc/robot/subsystems/Intake.java b/src/main/java/frc/robot/subsystems/Intake.java index 6fa0be0..2614ab8 100644 --- a/src/main/java/frc/robot/subsystems/Intake.java +++ b/src/main/java/frc/robot/subsystems/Intake.java @@ -15,37 +15,38 @@ public class Intake extends SubsystemBase { - // instance variables - private final CANSparkMax m_intakeMotor = new CANSparkMax(IntakeConstants.INTAKE_MOTOR_PORT, MotorType.kBrushless); - private final SparkRelativeEncoder m_intakeEncoder = (SparkRelativeEncoder) m_intakeMotor - .getEncoder(SparkRelativeEncoder.Type.kHallSensor, IntakeConstants.COUNTS_PER_REV); - - // constructor - public Intake() {} - - // Sets intake motor speed (forward if positive, backward if negative) - public void runIntakeMotor(double speed) { - m_intakeMotor.set(speed); - } - - // Sets intake motor speed to zero and stops motor - public void intakeOff() { - m_intakeMotor.set(0); - m_intakeMotor.stopMotor(); - } - - // returns encoder position - public double getEncoderPosition() { - return m_intakeEncoder.getPosition(); - } - - // sets encoder to desired position - public void setEncoderPosition(double position) { - m_intakeEncoder.setPosition(position); - } - - // returns encoder velocity - public double getEncoderVelocity() { - return m_intakeEncoder.getVelocity(); - } + // instance variables + private final CANSparkMax m_intakeMotor = new CANSparkMax(IntakeConstants.INTAKE_MOTOR_PORT, + MotorType.kBrushless); + private final SparkRelativeEncoder m_intakeEncoder = (SparkRelativeEncoder) + m_intakeMotor.getEncoder(SparkRelativeEncoder.Type.kHallSensor, IntakeConstants.COUNTS_PER_REV); + + // constructor + public Intake() {} + + // Sets intake motor speed (forward if positive, backward if negative) + public void runIntakeMotor(double speed) { + m_intakeMotor.set(speed); + } + + // Sets intake motor speed to zero and stops motor + public void intakeOff() { + m_intakeMotor.set(0); + m_intakeMotor.stopMotor(); + } + + // returns encoder position + public double getEncoderPosition() { + return m_intakeEncoder.getPosition(); + } + + // sets encoder to desired position + public void setEncoderPosition(double position) { + m_intakeEncoder.setPosition(position); + } + + // returns encoder velocity + public double getEncoderVelocity() { + return m_intakeEncoder.getVelocity(); + } } \ No newline at end of file diff --git a/src/main/java/frc/robot/subsystems/Shooter.java b/src/main/java/frc/robot/subsystems/Shooter.java index ac5fbdb..3bdc599 100644 --- a/src/main/java/frc/robot/subsystems/Shooter.java +++ b/src/main/java/frc/robot/subsystems/Shooter.java @@ -14,35 +14,36 @@ // ***NEED TO BE UPDATED FOR 2024 SEASON*** public class Shooter extends SubsystemBase { - private final CANSparkMax m_shooterMotor = new CANSparkMax(ShooterConstants.SHOOTER_MOTOR_PORT, MotorType.kBrushless); - private final SparkRelativeEncoder m_shooterEncoder = (SparkRelativeEncoder) m_shooterMotor - .getEncoder(SparkRelativeEncoder.Type.kHallSensor, ShooterConstants.COUNTS_PER_REV); - - public Shooter() {} - - // Sets intake motor speed (forward if positive, backward if negative) - public void runShooterMotor(double speed) { - m_shooterMotor.set(speed); - } - - // Sets intake motor speed to zero and stops motor - public void shooterOff() { - m_shooterMotor.set(0); - m_shooterMotor.stopMotor(); - } - - // returns encoder position - public double getEncoderPosition() { - return m_shooterEncoder.getPosition(); - } - - // sets encoder to desired position - public void setEncoderPosition(double position) { - m_shooterEncoder.setPosition(position); - } - - // returns encoder velocity - public double getEncoderVelocity() { - return m_shooterEncoder.getVelocity(); - } + private final CANSparkMax m_shooterMotor = new CANSparkMax(ShooterConstants.SHOOTER_MOTOR_PORT, + MotorType.kBrushless); + private final SparkRelativeEncoder m_shooterEncoder = (SparkRelativeEncoder) + m_shooterMotor.getEncoder(SparkRelativeEncoder.Type.kHallSensor, ShooterConstants.COUNTS_PER_REV); + + public Shooter() {} + + // Sets intake motor speed (forward if positive, backward if negative) + public void runShooterMotor(double speed) { + m_shooterMotor.set(speed); + } + + // Sets intake motor speed to zero and stops motor + public void shooterOff() { + m_shooterMotor.set(0); + m_shooterMotor.stopMotor(); + } + + // returns encoder position + public double getEncoderPosition() { + return m_shooterEncoder.getPosition(); + } + + // sets encoder to desired position + public void setEncoderPosition(double position) { + m_shooterEncoder.setPosition(position); + } + + // returns encoder velocity + public double getEncoderVelocity() { + return m_shooterEncoder.getVelocity(); + } } \ No newline at end of file From 5a060819598d7354cfc63b710ead8b771653ba2e Mon Sep 17 00:00:00 2001 From: alleycat6 Date: Tue, 5 Mar 2024 17:35:39 -0800 Subject: [PATCH 8/8] fix indents --- .../java/frc/robot/subsystems/Indexer.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/Indexer.java b/src/main/java/frc/robot/subsystems/Indexer.java index 9cc57ca..3b0122c 100644 --- a/src/main/java/frc/robot/subsystems/Indexer.java +++ b/src/main/java/frc/robot/subsystems/Indexer.java @@ -15,37 +15,37 @@ public class Indexer extends SubsystemBase { - // instance variables - private final CANSparkMax m_indexerMotor = new CANSparkMax(IndexerConstants.INDEXER_MOTOR_PORT, MotorType.kBrushless); - private final SparkRelativeEncoder m_indexerEncoder = (SparkRelativeEncoder) m_indexerMotor - .getEncoder(SparkRelativeEncoder.Type.kHallSensor, IndexerConstants.COUNTS_PER_REV); - - // constructor - public Indexer() {} - - // Sets Indexer motor speed (forward if positive, backward if negative) - public void runIndexerMotor(double speed) { - m_indexerMotor.set(speed); - } - - // Sets Indexer motor speed to zero and stops motor - public void indexerOff() { - m_indexerMotor.set(0); - m_indexerMotor.stopMotor(); - } - - // returns encoder position - public double getEncoderPosition() { - return m_indexerEncoder.getPosition(); - } - - // sets encoder to desired position - public void setEncoderPosition(double position) { - m_indexerEncoder.setPosition(position); - } - - // returns encoder velocity - public double getEncoderVelocity() { - return m_indexerEncoder.getVelocity(); - } + // instance variables + private final CANSparkMax m_indexerMotor = new CANSparkMax(IndexerConstants.INDEXER_MOTOR_PORT, MotorType.kBrushless); + private final SparkRelativeEncoder m_indexerEncoder = (SparkRelativeEncoder) m_indexerMotor + .getEncoder(SparkRelativeEncoder.Type.kHallSensor, IndexerConstants.COUNTS_PER_REV); + + // constructor + public Indexer() {} + + // Sets Indexer motor speed (forward if positive, backward if negative) + public void runIndexerMotor(double speed) { + m_indexerMotor.set(speed); + } + + // Sets Indexer motor speed to zero and stops motor + public void indexerOff() { + m_indexerMotor.set(0); + m_indexerMotor.stopMotor(); + } + + // returns encoder position + public double getEncoderPosition() { + return m_indexerEncoder.getPosition(); + } + + // sets encoder to desired position + public void setEncoderPosition(double position) { + m_indexerEncoder.setPosition(position); + } + + // returns encoder velocity + public double getEncoderVelocity() { + return m_indexerEncoder.getVelocity(); + } }