diff --git a/Project 1 Basic Romi Drive/.Glass/glass-window.json b/Project 1 Basic Romi Drive/.Glass/glass-window.json new file mode 100644 index 0000000..37ff8ca --- /dev/null +++ b/Project 1 Basic Romi Drive/.Glass/glass-window.json @@ -0,0 +1,30 @@ +{ + "MainWindow": { + "GLOBAL": { + "height": "960", + "maximized": "0", + "style": "0", + "userScale": "2", + "width": "1280", + "xpos": "-1", + "ypos": "-1" + } + }, + "Window": { + "###NetworkTables": { + "Collapsed": "0", + "Pos": "312,346", + "Size": "937,231" + }, + "###NetworkTables Settings": { + "Collapsed": "0", + "Pos": "37,37", + "Size": "307,86" + }, + "Debug##Default": { + "Collapsed": "0", + "Pos": "60,60", + "Size": "400,400" + } + } +} diff --git a/Project 1 Basic Romi Drive/.Glass/glass.json b/Project 1 Basic Romi Drive/.Glass/glass.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/Project 1 Basic Romi Drive/.Glass/glass.json @@ -0,0 +1 @@ +{} diff --git a/Project 1 Basic Romi Drive/.vscode/launch.json b/Project 1 Basic Romi Drive/.vscode/launch.json index c9c9713..bf699a9 100644 --- a/Project 1 Basic Romi Drive/.vscode/launch.json +++ b/Project 1 Basic Romi Drive/.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": "Launch Main", + "request": "launch", + "mainClass": "frc.robot.Main", + "projectName": "Project 1 Basic Romi Drive" + }, { "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/Project 1 Basic Romi Drive/.vscode/tasks.json b/Project 1 Basic Romi Drive/.vscode/tasks.json new file mode 100644 index 0000000..eb7fd53 --- /dev/null +++ b/Project 1 Basic Romi Drive/.vscode/tasks.json @@ -0,0 +1,4 @@ +{ + "version": "2.0.0", + "tasks": [] +} \ No newline at end of file diff --git a/Project 1 Basic Romi Drive/src/main/java/frc/robot/Robot.java b/Project 1 Basic Romi Drive/src/main/java/frc/robot/Robot.java index a28c928..59398a9 100644 --- a/Project 1 Basic Romi Drive/src/main/java/frc/robot/Robot.java +++ b/Project 1 Basic Romi Drive/src/main/java/frc/robot/Robot.java @@ -19,7 +19,8 @@ public class Robot extends TimedRobot { private final RomiDrivetrain mDrivetrain = new RomiDrivetrain(); - + private int controllerPort = 0; + private final XboxController controller = new XboxController(controllerPort); /** * This function is run when the robot is first started up and should be used for any * initialization code. @@ -52,7 +53,9 @@ public void teleopInit() {} /** This function is called periodically during operator control. HINT you code will be in this function*/ @Override - public void teleopPeriodic() {} + public void teleopPeriodic(){ + mDrivetrain.arcadeDrive(controller.getY(Hand.kLeft), -1 * controller.getX(Hand.kRight)); + } /** This function is called once when the robot is disabled. */ @Override @@ -87,4 +90,4 @@ public void robotPeriodic() { public void simulationPeriodic() { mDrivetrain.simulationPeriodic(); } -} +} \ No newline at end of file diff --git a/Project 1 Basic Romi Drive/src/main/java/frc/robot/RomiDrivetrain.java b/Project 1 Basic Romi Drive/src/main/java/frc/robot/RomiDrivetrain.java index 6d258a5..772cfc8 100644 --- a/Project 1 Basic Romi Drive/src/main/java/frc/robot/RomiDrivetrain.java +++ b/Project 1 Basic Romi Drive/src/main/java/frc/robot/RomiDrivetrain.java @@ -24,6 +24,9 @@ import edu.wpi.first.wpiutil.math.VecBuilder; import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.GenericHID.Hand; + public class RomiDrivetrain extends SubsystemBase { // Romi Encoder Constants @@ -43,6 +46,10 @@ public class RomiDrivetrain extends SubsystemBase { // Set up the differential drive controller private final DifferentialDrive mDiffDrive = new DifferentialDrive(mLeftMotor, mRightMotor); + // Set up Xbox Controller + final int controllerPort = 0; + XboxController controller = new XboxController(controllerPort); + // SIMULATION STUFF @@ -70,7 +77,7 @@ public RomiDrivetrain() { /** * Commands the drivetrain through an arcade drive style. HINT: this is useful for your purposes. - * @param xaxisSpeed The speed at which the robot goes forward and backward. Should be a number between -1 and 1. + * @param xaxisSpeed The speed at which the robot goes forward and backward. Should be a number between -1 and 1. * @param zaxisRotate The speed at which the spins clockwise and counterclockwise. Should be a number between -1 and 1. */ public void arcadeDrive(double xaxisSpeed, double zaxisRotate) { diff --git a/Project 2 Basic State Machine/.vscode/launch.json b/Project 2 Basic State Machine/.vscode/launch.json index c9c9713..8ae9ccd 100644 --- a/Project 2 Basic State Machine/.vscode/launch.json +++ b/Project 2 Basic State Machine/.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": "Launch Main", + "request": "launch", + "mainClass": "frc.robot.Main", + "projectName": "Project 2 Basic State Machine" + }, { "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/Project 2 Basic State Machine/src/main/java/frc/robot/Robot.java b/Project 2 Basic State Machine/src/main/java/frc/robot/Robot.java index a28c928..1aaed7a 100644 --- a/Project 2 Basic State Machine/src/main/java/frc/robot/Robot.java +++ b/Project 2 Basic State Machine/src/main/java/frc/robot/Robot.java @@ -7,6 +7,7 @@ import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import frc.robot.RomiDrivetrain.RomiState; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.GenericHID.Hand; @@ -19,6 +20,8 @@ public class Robot extends TimedRobot { private final RomiDrivetrain mDrivetrain = new RomiDrivetrain(); + private int controllerPort = 0; + private final XboxController controller = new XboxController(controllerPort); /** * This function is run when the robot is first started up and should be used for any @@ -52,7 +55,22 @@ public void teleopInit() {} /** This function is called periodically during operator control. HINT you code will be in this function*/ @Override - public void teleopPeriodic() {} + public void teleopPeriodic() { + mDrivetrain.arcadeDrive(controller.getX(Hand.kLeft), controller.getY(Hand.kRight)); + + if (controller.getXButtonPressed()) { + mDrivetrain.setState(RomiState.SLOW); + } + + if (controller.getYButtonPressed()) { + mDrivetrain.setState(RomiState.NORMAL); + } + + if (controller.getBButtonPressed()) { + mDrivetrain.setState(RomiState.FAST); + } + + } /** This function is called once when the robot is disabled. */ @Override diff --git a/Project 2 Basic State Machine/src/main/java/frc/robot/RomiDrivetrain.java b/Project 2 Basic State Machine/src/main/java/frc/robot/RomiDrivetrain.java index 6d258a5..a9a004a 100644 --- a/Project 2 Basic State Machine/src/main/java/frc/robot/RomiDrivetrain.java +++ b/Project 2 Basic State Machine/src/main/java/frc/robot/RomiDrivetrain.java @@ -57,7 +57,7 @@ public class RomiDrivetrain extends SubsystemBase { private final DifferentialDriveOdometry mOdometry = new DifferentialDriveOdometry(Rotation2d.fromDegrees(0)); - + /** Creates a new RomiDrivetrain. */ public RomiDrivetrain() { @@ -68,13 +68,40 @@ public RomiDrivetrain() { resetEncoders(); } + //Normal Speed of Romi + private RomiState state = RomiState.NORMAL; + /** * Commands the drivetrain through an arcade drive style. HINT: this is useful for your purposes. * @param xaxisSpeed The speed at which the robot goes forward and backward. Should be a number between -1 and 1. * @param zaxisRotate The speed at which the spins clockwise and counterclockwise. Should be a number between -1 and 1. */ + + public enum RomiState { + SLOW, NORMAL, FAST + } + + public void setState(RomiState state){ + this.state = state; + } + public void arcadeDrive(double xaxisSpeed, double zaxisRotate) { - mDiffDrive.arcadeDrive(xaxisSpeed, zaxisRotate); + switch (state) { + case SLOW: + System.out.println("The Romi is in Slow Mode"); + mDiffDrive.arcadeDrive(xaxisSpeed * 0.5, zaxisRotate * 0.5); + break; + + case NORMAL: + System.out.println("The Romi is in Normal Mode"); + mDiffDrive.arcadeDrive(xaxisSpeed * 0.75, zaxisRotate * 0.75); + break; + + case FAST: + System.out.println("The Romi is in Fast Mode"); + mDiffDrive.arcadeDrive(xaxisSpeed, zaxisRotate); + break; + } } public void resetEncoders() { diff --git a/Project 3 Command Based/src/main/java/frc/robot/RobotContainer.java b/Project 3 Command Based/src/main/java/frc/robot/RobotContainer.java index 24e0011..98bd6c1 100644 --- a/Project 3 Command Based/src/main/java/frc/robot/RobotContainer.java +++ b/Project 3 Command Based/src/main/java/frc/robot/RobotContainer.java @@ -6,9 +6,14 @@ import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.GenericHID.Hand; +import edu.wpi.first.wpilibj.XboxController.Button; import frc.robot.commands.ExampleCommand; import frc.robot.subsystems.RomiDrivetrain; +import frc.robot.subsystems.RomiDrivetrain.RomiState; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.RunCommand; +import edu.wpi.first.wpilibj2.command.button.JoystickButton; /** * This class is where the bulk of the robot should be declared. Since Command-based is a @@ -19,6 +24,8 @@ public class RobotContainer { // The robot's subsystems and commands are defined here... private final RomiDrivetrain m_romiDrivetrain = new RomiDrivetrain(); + private int controllerPort = 0; + private final XboxController controller = new XboxController(controllerPort); private final ExampleCommand m_autoCommand = new ExampleCommand(m_romiDrivetrain); @@ -26,6 +33,17 @@ public class RobotContainer { public RobotContainer() { // Configure the button bindings configureButtonBindings(); + + // Configure default commands + // Set the default drive command to split-stick arcade drive + m_romiDrivetrain.setDefaultCommand( + // A split-stick arcade command, with forward/backward controlled by the left + // hand, and turning controlled by the right. + new RunCommand( + () -> + m_romiDrivetrain.arcadeDrive( + -controller.getX(Hand.kLeft), -1 * controller.getY(Hand.kRight)), + m_romiDrivetrain)); } /** @@ -34,7 +52,27 @@ public RobotContainer() { * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link * edu.wpi.first.wpilibj2.command.button.JoystickButton}. */ - private void configureButtonBindings() {} + private void configureButtonBindings() { + + new JoystickButton(controller, Button.kX.value) + .whenPressed( + () -> { + m_romiDrivetrain.setState(RomiState.SLOW); + }, m_romiDrivetrain); + + new JoystickButton(controller, Button.kY.value) + .whenPressed( + () -> { + m_romiDrivetrain.setState(RomiState.NORMAL); + }, m_romiDrivetrain); + + new JoystickButton(controller, Button.kB.value) + .whenPressed( + () -> { + m_romiDrivetrain.setState(RomiState.FAST); + }, m_romiDrivetrain); + + } /** * Use this to pass the autonomous command to the main {@link Robot} class. diff --git a/Project 3 Command Based/src/main/java/frc/robot/subsystems/RomiDrivetrain.java b/Project 3 Command Based/src/main/java/frc/robot/subsystems/RomiDrivetrain.java index f78405e..6c9d4e7 100644 --- a/Project 3 Command Based/src/main/java/frc/robot/subsystems/RomiDrivetrain.java +++ b/Project 3 Command Based/src/main/java/frc/robot/subsystems/RomiDrivetrain.java @@ -25,6 +25,7 @@ public class RomiDrivetrain extends SubsystemBase { // Set up the differential drive controller private final DifferentialDrive m_diffDrive = new DifferentialDrive(m_leftMotor, m_rightMotor); + /** Creates a new RomiDrivetrain. */ public RomiDrivetrain() { @@ -34,8 +35,33 @@ public RomiDrivetrain() { resetEncoders(); } + private RomiState state = RomiState.NORMAL; + + public enum RomiState { + SLOW, NORMAL, FAST + } + + public void setState(RomiState state) { + this.state = state; + } + public void arcadeDrive(double xaxisSpeed, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisSpeed, zaxisRotate); + switch (state) { + case SLOW: + System.out.println("The Romi is in" + state + " mode"); + m_diffDrive.arcadeDrive(xaxisSpeed * 0.5, zaxisRotate * 0.5); + break; + + case NORMAL: + System.out.println("The Romi is in" + state + " mode"); + m_diffDrive.arcadeDrive(xaxisSpeed * 0.75, zaxisRotate * 0.75); + break; + + case FAST: + System.out.println("The Romi is in" + state + " mode"); + m_diffDrive.arcadeDrive(xaxisSpeed, zaxisRotate); + break; + } } public void resetEncoders() { diff --git a/Project 4/Project 4.2 Basic Autonomous/src/main/java/frc/robot/RobotContainer.java b/Project 4/Project 4.2 Basic Autonomous/src/main/java/frc/robot/RobotContainer.java index 811aa55..f68fc76 100644 --- a/Project 4/Project 4.2 Basic Autonomous/src/main/java/frc/robot/RobotContainer.java +++ b/Project 4/Project 4.2 Basic Autonomous/src/main/java/frc/robot/RobotContainer.java @@ -25,12 +25,22 @@ public class RobotContainer { private final RomiDrivetrain m_romiDrivetrain = new RomiDrivetrain(); // You will need to set this up. - private final SequentialCommandGroup mCommand = new SequentialCommandGroup(); + private final SequentialCommandGroup mCommand = new SequentialCommandGroup( + new InstantCommand( + () -> + m_romiDrivetrain.setForwardSpeed(0.5), m_romiDrivetrain), + new WaitCommand(5), + + new InstantCommand( + () -> + m_romiDrivetrain.setForwardSpeed(0), m_romiDrivetrain)); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { // Configure the button bindings configureButtonBindings(); + + } /** diff --git a/Project 5 Closed Loop Control/.vscode/launch.json b/Project 5 Closed Loop Control/.vscode/launch.json index c9c9713..c965272 100644 --- a/Project 5 Closed Loop Control/.vscode/launch.json +++ b/Project 5 Closed Loop Control/.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": "Launch Main", + "request": "launch", + "mainClass": "frc.robot.Main", + "projectName": "Project 5 Closed Loop Control" + }, { "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/Project 5 Closed Loop Control/src/main/java/frc/robot/Constants.java b/Project 5 Closed Loop Control/src/main/java/frc/robot/Constants.java index 033c72d..e30670a 100644 --- a/Project 5 Closed Loop Control/src/main/java/frc/robot/Constants.java +++ b/Project 5 Closed Loop Control/src/main/java/frc/robot/Constants.java @@ -12,4 +12,8 @@ *
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 final class Constants { + public static double kP = 10; + public static double kI = 0; + public static double kD = 10; +} diff --git a/Project 5 Closed Loop Control/src/main/java/frc/robot/RobotContainer.java b/Project 5 Closed Loop Control/src/main/java/frc/robot/RobotContainer.java index 12363b3..f0eb50a 100644 --- a/Project 5 Closed Loop Control/src/main/java/frc/robot/RobotContainer.java +++ b/Project 5 Closed Loop Control/src/main/java/frc/robot/RobotContainer.java @@ -7,12 +7,9 @@ import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.XboxController; -import frc.robot.commands.ExampleCommand; import frc.robot.subsystems.RomiDrivetrain; import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.PIDCommand; -import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; /** * This class is where the bulk of the robot should be declared. Since Command-based is a @@ -30,6 +27,14 @@ public class RobotContainer { /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { + m_autoCommand = new PIDCommand( + new PIDController(Constants.kP, Constants.kI, Constants.kD), + m_romiDrivetrain::getDistanceInch, + 10.0, + useOutput -> m_romiDrivetrain.setForwardSpeed(useOutput), + m_romiDrivetrain + ); + // Configure the button bindings configureButtonBindings(); } diff --git a/Project 5 Closed Loop Control/src/main/java/frc/robot/commands/ExampleCommand.java b/Project 5 Closed Loop Control/src/main/java/frc/robot/commands/ExampleCommand.java index d0b185c..d4fe533 100644 --- a/Project 5 Closed Loop Control/src/main/java/frc/robot/commands/ExampleCommand.java +++ b/Project 5 Closed Loop Control/src/main/java/frc/robot/commands/ExampleCommand.java @@ -9,16 +9,12 @@ /** An example command that uses an example subsystem. */ public class ExampleCommand extends CommandBase { - @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"}) - private final RomiDrivetrain m_subsystem; - /** * Creates a new ExampleCommand. * * @param subsystem The subsystem used by this command. */ public ExampleCommand(RomiDrivetrain subsystem) { - m_subsystem = subsystem; // Use addRequirements() here to declare subsystem dependencies. addRequirements(subsystem); } diff --git a/introduction.txt b/introduction.txt index 482e223..9e7390a 100644 --- a/introduction.txt +++ b/introduction.txt @@ -1,2 +1,3 @@ -Name: -Fact: +Name: Kumar Samyak +Fact: rfr +y