From 207e1f072067dd6840975220ff498c2ee9bb4821 Mon Sep 17 00:00:00 2001 From: owbanana <83752502+owbanana@users.noreply.github.com> Date: Thu, 6 May 2021 00:32:13 -0700 Subject: [PATCH] Add files via upload Added commands --- .../java/frc/robot/commands/ArmWiggle.java | 53 +++++++++++++++++++ .../java/frc/robot/commands/Autoroutine1.java | 26 +++++++++ .../java/frc/robot/commands/Autoroutine2.java | 26 +++++++++ .../frc/robot/commands/DriveBackward.java | 50 +++++++++++++++++ .../frc/robot/commands/DriveCcwCircle.java | 48 +++++++++++++++++ .../frc/robot/commands/DriveCwCircle.java | 44 +++++++++++++++ .../java/frc/robot/commands/DriveForward.java | 49 +++++++++++++++++ .../frc/robot/commands/GoBackAndForth.java | 50 +++++++++++++++++ src/main/java/frc/robot/commands/Spin.java | 48 +++++++++++++++++ .../java/frc/robot/commands/TurnAround.java | 44 +++++++++++++++ 10 files changed, 438 insertions(+) create mode 100644 src/main/java/frc/robot/commands/ArmWiggle.java create mode 100644 src/main/java/frc/robot/commands/Autoroutine1.java create mode 100644 src/main/java/frc/robot/commands/Autoroutine2.java create mode 100644 src/main/java/frc/robot/commands/DriveBackward.java create mode 100644 src/main/java/frc/robot/commands/DriveCcwCircle.java create mode 100644 src/main/java/frc/robot/commands/DriveCwCircle.java create mode 100644 src/main/java/frc/robot/commands/DriveForward.java create mode 100644 src/main/java/frc/robot/commands/GoBackAndForth.java create mode 100644 src/main/java/frc/robot/commands/Spin.java create mode 100644 src/main/java/frc/robot/commands/TurnAround.java diff --git a/src/main/java/frc/robot/commands/ArmWiggle.java b/src/main/java/frc/robot/commands/ArmWiggle.java new file mode 100644 index 0000000..d85c6c1 --- /dev/null +++ b/src/main/java/frc/robot/commands/ArmWiggle.java @@ -0,0 +1,53 @@ +// 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.DriveTrain; +import frc.robot.subsystems.Arm; +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class ArmWiggle extends CommandBase { + +//moves arm up and down twice + +private final Arm arm; +private final Timer timer; + + /** Creates a new DriveCwCircle. */ + public ArmWiggle(Arm arm) { + timer = new Timer(); + addRequirements(arm); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + for(int i = 0, i < 2; i++){ + while(!arm.getLimitSwitch() && timer.get() < 2){ + arm.moveUp(); + } + while(timer.get() >= 2 && timer.get()< 4){ + arm.moveDown(); + } + } + + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/commands/Autoroutine1.java b/src/main/java/frc/robot/commands/Autoroutine1.java new file mode 100644 index 0000000..9cdfde4 --- /dev/null +++ b/src/main/java/frc/robot/commands/Autoroutine1.java @@ -0,0 +1,26 @@ +// 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.SequentialCommandGroup; + + +public class Autoroutine1 extends SequentialCommandGroup { + //drives in circles and spins a lot + /** Creates a new Autoroutine1. */ + public Autoroutine1(DriveTrain drivetrain) { + + addCommands( + new DriveCwCircle(drivetrain), + new DriveForward(drivetrain), + new DriveCcwCircle(drivetrain), + new Spin(drivetrain), + new TurnAround(drivetrain), + new DriveForward(drivetrain), + new TurnAround(drivetrain), + new Spin(drivetrain), + ); + } +} diff --git a/src/main/java/frc/robot/commands/Autoroutine2.java b/src/main/java/frc/robot/commands/Autoroutine2.java new file mode 100644 index 0000000..97b8d3b --- /dev/null +++ b/src/main/java/frc/robot/commands/Autoroutine2.java @@ -0,0 +1,26 @@ +// 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.SequentialCommandGroup; + +public class Autoroutine2 extends SequentialCommandGroup { + //Does a lot of arm moving up and down and also moves a bit + /** Creates a new Autoroutine2. */ + public Autoroutine2(DriveTrain drivetrain, Arm arm) { + + // addCommands(new FooCommand(), new BarCommand()); + addCommands( + new ArmWiggle(arm), + new DriveForward(drivetrain), + new ArmWiggle(arm), + new TurnAround(drivetrain), + new ArmWiggle(arm), + new DriveForward(drivetrain), + new TurnAround(drivetrain), + new ArmWiggle(arm) + ); + } +} diff --git a/src/main/java/frc/robot/commands/DriveBackward.java b/src/main/java/frc/robot/commands/DriveBackward.java new file mode 100644 index 0000000..8ef4b37 --- /dev/null +++ b/src/main/java/frc/robot/commands/DriveBackward.java @@ -0,0 +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 frc.robot.subsystems.DriveTrain; +import edu.wpi.first.wpilibj2.command.CommandBase; +import edu.wpi.first.wpilibj.Timer; + +public class DriveBackwards extends CommandBase { + //drives robot backwards + + private final DriveTrain drivetrain; + private final Timer timer; + + /** Creates a new DriveCwCircle. */ + public DriveBackwards(DriveTrain drivetrain) { + this.drivetrain = drivetrain; + timer = new Timer(); + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(drivetrain); + + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + timer.reset(); + timer.start(); + while(timer.get() < 2){ + drivetrain.drive(-0.5,-0.5); + } + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} + diff --git a/src/main/java/frc/robot/commands/DriveCcwCircle.java b/src/main/java/frc/robot/commands/DriveCcwCircle.java new file mode 100644 index 0000000..0700426 --- /dev/null +++ b/src/main/java/frc/robot/commands/DriveCcwCircle.java @@ -0,0 +1,48 @@ +// 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.DriveTrain; +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class DriveCcwCircle extends CommandBase { + //makes robot drive in a circle counterclockwise + + private final DriveTrain drivetrain; + + /** Creates a new DriveCwCircle. */ + public DriveCcwCircle(DriveTrain drivetrain) { + this.drivetrain = drivetrain; + + addRequirements(drivetrain); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + @Override + public void initialize() { + double targetDegrees = 359; + while(drivetrain.getAngle() < targetDegrees){ + drivetrain.drive(0.3,0.7); + } + } + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/commands/DriveCwCircle.java b/src/main/java/frc/robot/commands/DriveCwCircle.java new file mode 100644 index 0000000..905de52 --- /dev/null +++ b/src/main/java/frc/robot/commands/DriveCwCircle.java @@ -0,0 +1,44 @@ +// 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.DriveTrain; +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class DriveCwCircle extends CommandBase { + //makes robot drive in a circle clockwise + private final DriveTrain drivetrain; + + /** Creates a new DriveCwCircle. */ + public DriveCwCircle(DriveTrain drivetrain) { + this.drivetrain = drivetrain; + + addRequirements(drivetrain); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + double targetDegrees = 359; + while(drivetrain.getAngle() < targetDegrees){ + drivetrain.drive(0.7,0.3); + } + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/commands/DriveForward.java b/src/main/java/frc/robot/commands/DriveForward.java new file mode 100644 index 0000000..0cf5b0c --- /dev/null +++ b/src/main/java/frc/robot/commands/DriveForward.java @@ -0,0 +1,49 @@ +// 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.DriveTrain; +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class DriveForward extends CommandBase { + //makes robot go forward + + private final DriveTrain drivetrain; + private final Timer timer; + + /** Creates a new DriveCwCircle. */ + public DriveForward(DriveTrain drivetrain) { + this.drivetrain = drivetrain; + timer = new Timer(); + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(drivetrain); + + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + timer.reset(); + timer.start(); + while(timer.get() < 2){ + drivetrain.drive(0.5,0.5); + } + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/commands/GoBackAndForth.java b/src/main/java/frc/robot/commands/GoBackAndForth.java new file mode 100644 index 0000000..5776522 --- /dev/null +++ b/src/main/java/frc/robot/commands/GoBackAndForth.java @@ -0,0 +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.CommandBase; + +public class GoBackAndForth extends CommandBase { + //makes robot go backwards and forwards for 3 times + private final DriveTrain drivetrain; + private final Timer timer; + + /** Creates a new GoBackAndForth. */ + public GoBackAndForth(DriveTrain drivetrain) { + // Use addRequirements() here to declare subsystem dependencies. + this.drivetrain = drivetrain; + timer = new Timer(); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + int direction = 1; + + for(int i = 0; i < 6; i++){ + timer.reset(); + timer.start(); + while(timer.get() < 2){ + drivetrain.drive(direction*0.5, direction*0.5); + direction *= -1; + } + } + + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/commands/Spin.java b/src/main/java/frc/robot/commands/Spin.java new file mode 100644 index 0000000..f92b849 --- /dev/null +++ b/src/main/java/frc/robot/commands/Spin.java @@ -0,0 +1,48 @@ +// 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.DriveTrain; +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class Spin extends CommandBase { + //spins in place 4 times + private final DriveTrain drivetrain; + private int numSpins; + + /** Creates a new DriveCwCircle. */ + public Spin(DriveTrain drivetrain) { + this.drivetrain = drivetrain; + + addRequirements(drivetrain); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + double targetDegrees = 359; + for(numSpins = 0; numSpins < 4; numSpins ++){ + while(drivetrain.getAngle() < targetDegrees){ + drivetrain.drive(0.5,-0.5); + } + targetDegrees --; + } + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return numSpins == 4; + } +} diff --git a/src/main/java/frc/robot/commands/TurnAround.java b/src/main/java/frc/robot/commands/TurnAround.java new file mode 100644 index 0000000..e0a444f --- /dev/null +++ b/src/main/java/frc/robot/commands/TurnAround.java @@ -0,0 +1,44 @@ +// 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.DriveTrain; +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class TurnAround extends CommandBase { + //makes robot do 188 degree turn + private final DriveTrain drivetrain; + + /** Creates a new DriveCwCircle. */ + public TurnAround(DriveTrain drivetrain) { + this.drivetrain = drivetrain; + + addRequirements(drivetrain); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + double initialAngle = drivetrain.getAngle(); + while(drivetrain.getAngle() < initialAngle+180){ + drivetrain.drive(0.5,-0.5); + } + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) {} + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +}