From 2a54b3ff40109a07e04110117d34f898fe31a362 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:12:07 +0300 Subject: [PATCH 01/23] remove gripper --- .../frc/robot/subsystems/gripper/Gripper.java | 54 ------------------- .../subsystems/gripper/commands/Intake.java | 36 ------------- .../subsystems/gripper/commands/Outtake.java | 36 ------------- 3 files changed, 126 deletions(-) delete mode 100644 src/main/java/frc/robot/subsystems/gripper/Gripper.java delete mode 100644 src/main/java/frc/robot/subsystems/gripper/commands/Intake.java delete mode 100644 src/main/java/frc/robot/subsystems/gripper/commands/Outtake.java diff --git a/src/main/java/frc/robot/subsystems/gripper/Gripper.java b/src/main/java/frc/robot/subsystems/gripper/Gripper.java deleted file mode 100644 index 9b257dc..0000000 --- a/src/main/java/frc/robot/subsystems/gripper/Gripper.java +++ /dev/null @@ -1,54 +0,0 @@ -package frc.robot.subsystems.gripper; - -import com.ctre.phoenix.motorcontrol.ControlMode; -import com.ctre.phoenix.motorcontrol.can.VictorSPX; -import edu.wpi.first.wpilibj.Solenoid; -import edu.wpi.first.wpilibj2.command.SubsystemBase; -import frc.robot.Ports; - -import static frc.robot.Ports.Gripper.*; - -public class Gripper extends SubsystemBase { - private final VictorSPX motorRight = new VictorSPX(RIGHTMOTOR); - private final VictorSPX motorLeft = new VictorSPX(LEFTMOTOR); - private final Solenoid solenoid = new Solenoid(SOLENOID); - - private final static Gripper INSTANCE = new Gripper(); - - public static Gripper getInstance() { - return INSTANCE; - } - - /** - * Check if motor inverted - */ - private Gripper() { - motorRight.setInverted(RIGHT_MOTOR_INVERTED); - motorLeft.setInverted(LEFT_MOTOR_INVERTED); - motorRight.follow(motorLeft); - } - - /** - * Set power - * - * @param power power to give to the motor - */ - public void setPower(double power) { - motorRight.set(ControlMode.PercentOutput, power); - } - - - /** - * Close solenoid - */ - public void close() { - solenoid.set(false); - } - - /** - * Open solenoid - */ - public void open() { - solenoid.set(true); - } -} diff --git a/src/main/java/frc/robot/subsystems/gripper/commands/Intake.java b/src/main/java/frc/robot/subsystems/gripper/commands/Intake.java deleted file mode 100644 index cd6bed5..0000000 --- a/src/main/java/frc/robot/subsystems/gripper/commands/Intake.java +++ /dev/null @@ -1,36 +0,0 @@ -package frc.robot.subsystems.gripper.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; -import frc.robot.subsystems.gripper.Gripper; - -public class Intake extends CommandBase { - private final Gripper gripper; - private final double intakePower; - - public Intake(Gripper gripper, double intakePower) { - this.gripper = gripper; - this.intakePower = intakePower; - addRequirements(gripper); - } - - @Override - public void initialize() { - - } - - @Override - public void execute() { - gripper.close(); - gripper.setPower(intakePower); - } - - @Override - public void end(boolean interrupted) { - gripper.setPower(0); - } - - @Override - public boolean isFinished() { - return false; - } -} diff --git a/src/main/java/frc/robot/subsystems/gripper/commands/Outtake.java b/src/main/java/frc/robot/subsystems/gripper/commands/Outtake.java deleted file mode 100644 index afb8eb0..0000000 --- a/src/main/java/frc/robot/subsystems/gripper/commands/Outtake.java +++ /dev/null @@ -1,36 +0,0 @@ -package frc.robot.subsystems.gripper.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; -import frc.robot.subsystems.gripper.Gripper; - -public class Outtake extends CommandBase { - private final Gripper gripper; - private final double outtakePower; - - public Outtake(Gripper gripper, double outtakePower) { - this.gripper = gripper; - this.outtakePower = outtakePower; - addRequirements(gripper); - } - - @Override - public void initialize() { - - } - - @Override - public void execute() { - gripper.open(); - gripper.setPower(outtakePower); - - } - @Override - public void end(boolean interrupted) { - gripper.setPower(0); - } - - @Override - public boolean isFinished() { - return false; - } -} From bea42af3f40f4dbe1e7ce30b6435940ec522d716 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:12:39 +0300 Subject: [PATCH 02/23] add elevator subsystem --- .../subsystems/ExampleSubsystem/Elevator.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java new file mode 100644 index 0000000..f486bfa --- /dev/null +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -0,0 +1,21 @@ +package frc.robot.subsystems.ExampleSubsystem; + +import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.Constants; +import frc.robot.Ports; +import frc.robot.subsystems.UnitModel; + +public class Elevator extends SubsystemBase { + private final WPI_TalonFX motor=new WPI_TalonFX(Ports.MOTOR); + private static final Elevator INSTANCE=null; + public static final UnitModel unitModel = new UnitModel(Constants.TICKS_PER_METER); + + public Elevator(){ + motor.enableVoltageCompensation(Constants.ENABLE_VOLT_COMP); + motor.configVoltageCompSaturation(Constants.CONFIG_VOLT); + motor.configMotionAcceleration(Constants.MOTION_ACCELERATION); + motor.configMotionCruiseVelocity(Constants.CRUISE_VELOCITY); + + } +} From 7b3df500f87161c9cf974e003426bdd034169624 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:14:40 +0300 Subject: [PATCH 03/23] add constants --- .idea/misc.xml | 8 -------- src/main/java/frc/robot/Constants.java | 8 ++++++-- 2 files changed, 6 insertions(+), 10 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 6b60455..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 2aa942f..5290aa2 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -16,7 +16,11 @@ * constants are needed, to reduce verbosity. */ public final class Constants { - public static final class Gripper { - } + public static final double DRUM_RADIUS= 0.03;//[meter] + public static final double TICKS_PER_METER= 2 * Math.PI * DRUM_RADIUS / 4096;//[ticks\second] + public static final int CONFIG_VOLT= 12; + public static final boolean ENABLE_VOLT_COMP= true; + public static final int MOTION_ACCELERATION=0; + public static final int CRUISE_VELOCITY=0; } From 4da0654c68d8782e0e7facd786c93b38d21e4b06 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:14:58 +0300 Subject: [PATCH 04/23] add motor port --- src/main/java/frc/robot/Ports.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/main/java/frc/robot/Ports.java b/src/main/java/frc/robot/Ports.java index b74187a..07f0112 100644 --- a/src/main/java/frc/robot/Ports.java +++ b/src/main/java/frc/robot/Ports.java @@ -1,15 +1,5 @@ package frc.robot; public class Ports { - public static class Gripper { - public static final int LEFTMOTOR = 0; - public static final int RIGHTMOTOR = 0; - public static final int SOLENOID = 0; - - public static final boolean RIGHT_MOTOR_INVERTED = false; - public static final boolean LEFT_MOTOR_INVERTED = false; - } - public static class Controller { - public static final int XBOX_CONTROLLER = 0; - } + public static final int MOTOR=0; } From c3f890722f77c8a01e703c283f0db57f16c8d3d5 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:20:35 +0300 Subject: [PATCH 05/23] add invert type port --- src/main/java/frc/robot/Ports.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/frc/robot/Ports.java b/src/main/java/frc/robot/Ports.java index 07f0112..d94a8be 100644 --- a/src/main/java/frc/robot/Ports.java +++ b/src/main/java/frc/robot/Ports.java @@ -1,5 +1,10 @@ package frc.robot; +import com.ctre.phoenix.motorcontrol.InvertType; +import com.ctre.phoenix.motorcontrol.TalonFXInvertType; + public class Ports { public static final int MOTOR=0; + public static final TalonFXInvertType INVERTED = TalonFXInvertType.Clockwise; + } From 4ad5252372d3b12863dd54988eaf2adc6183210f Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:21:18 +0300 Subject: [PATCH 06/23] define motor invert type and neutral mode --- .../frc/robot/subsystems/ExampleSubsystem/Elevator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index f486bfa..02b755c 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -1,5 +1,6 @@ package frc.robot.subsystems.ExampleSubsystem; +import com.ctre.phoenix.motorcontrol.NeutralMode; import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.Constants; @@ -16,6 +17,11 @@ public Elevator(){ motor.configVoltageCompSaturation(Constants.CONFIG_VOLT); motor.configMotionAcceleration(Constants.MOTION_ACCELERATION); motor.configMotionCruiseVelocity(Constants.CRUISE_VELOCITY); + motor.setInverted(Ports.INVERTED); + motor.setNeutralMode(NeutralMode.Brake); + } + + public static void } From 0d607b4faac1f71812ecf3acb25b0052ba3687a3 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:39:21 +0300 Subject: [PATCH 07/23] remove gripper --- src/main/java/frc/robot/RobotContainer.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 1facbc9..3147b9e 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -20,12 +20,6 @@ import static frc.robot.Ports.Controller.*; public class RobotContainer { - private final XboxController Xbox = new XboxController(XBOX_CONTROLLER); - private final Trigger lt = new Trigger(() -> Xbox.getTriggerAxis(GenericHID.Hand.kLeft) > 0.3); - private final Trigger rt = new Trigger(() -> Xbox.getTriggerAxis(GenericHID.Hand.kRight) > 0.3); - private final JoystickButton lb = new JoystickButton(Xbox, XboxController.Button.kBumperLeft.value); - private final JoystickButton rb = new JoystickButton(Xbox, XboxController.Button.kBumperRight.value); - private final Gripper gripper = Gripper.getInstance(); public RobotContainer() { @@ -33,8 +27,7 @@ public RobotContainer() { } //robot will intake when left trigger is held and outtake while right trigger is held private void configureButtonBindings() { - lt.whileActiveContinuous(new Intake(gripper, 1)); - rt.whileActiveContinuous(new Outtake(gripper, -1)); + } From 87e5bc9a53c94604dadbd3fbb4401c5ee309b5bc Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:39:41 +0300 Subject: [PATCH 08/23] add functions --- .../subsystems/ExampleSubsystem/Elevator.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index 02b755c..1a280fb 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -1,5 +1,6 @@ package frc.robot.subsystems.ExampleSubsystem; +import com.ctre.phoenix.motorcontrol.ControlMode; import com.ctre.phoenix.motorcontrol.NeutralMode; import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; import edu.wpi.first.wpilibj2.command.SubsystemBase; @@ -9,7 +10,7 @@ public class Elevator extends SubsystemBase { private final WPI_TalonFX motor=new WPI_TalonFX(Ports.MOTOR); - private static final Elevator INSTANCE=null; + private static Elevator INSTANCE=null; public static final UnitModel unitModel = new UnitModel(Constants.TICKS_PER_METER); public Elevator(){ @@ -23,5 +24,26 @@ public Elevator(){ } - public static void + public Elevator getInstance(){ + if(INSTANCE==null){ + INSTANCE = new Elevator(); + } + return INSTANCE; + } + + public double getPower(){ + return motor.get(); + } + + public void setPower(double Power){ + motor.set(Power); + } + + public void setVelocity(double velocity){ + motor.set(ControlMode.Velocity, unitModel.toTicks100ms(velocity)); + } + + public double getVelocity(){ + return unitModel.toVelocity(motor.getSelectedSensorVelocity()); + } } From b1d8c77252f729fc06b058a87a7e9f514dbee1cc Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:49:12 +0300 Subject: [PATCH 09/23] add commad --- src/main/java/frc/robot/commands/MoveElevator.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/frc/robot/commands/MoveElevator.java diff --git a/src/main/java/frc/robot/commands/MoveElevator.java b/src/main/java/frc/robot/commands/MoveElevator.java new file mode 100644 index 0000000..711456d --- /dev/null +++ b/src/main/java/frc/robot/commands/MoveElevator.java @@ -0,0 +1,2 @@ +package frc.robot.commands;public class MoveElevator { +} From 7251e87673f7bd4030dd2c51f6e773a13aa37c8f Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:50:02 +0300 Subject: [PATCH 10/23] add constructor and override methods to command --- .../java/frc/robot/commands/MoveElevator.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/commands/MoveElevator.java b/src/main/java/frc/robot/commands/MoveElevator.java index 711456d..5c156a8 100644 --- a/src/main/java/frc/robot/commands/MoveElevator.java +++ b/src/main/java/frc/robot/commands/MoveElevator.java @@ -1,2 +1,32 @@ -package frc.robot.commands;public class MoveElevator { +package frc.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.ExampleSubsystem.Elevator; + +import java.util.function.DoubleSupplier; + +public class MoveElevator extends CommandBase { + private final Elevator elevator; + private final DoubleSupplier doubleSupplier; + + public MoveElevator(Elevator elevator, DoubleSupplier doubleSupplier){ + this.elevator=elevator; + this.doubleSupplier=doubleSupplier; + addRequirements(elevator); + } + + @Override + public void execute() { + elevator.setPower(); + } + + @Override + public void end(boolean interrupted) { + + } + + @Override + public boolean isFinished() { + return false; + } } From 703e089bb2d4c1e05f99c8bb7e2fd3df4b17ef95 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:50:13 +0300 Subject: [PATCH 11/23] add constant --- src/main/java/frc/robot/Constants.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 5290aa2..66b85e5 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -22,5 +22,6 @@ public final class Constants { public static final boolean ENABLE_VOLT_COMP= true; public static final int MOTION_ACCELERATION=0; public static final int CRUISE_VELOCITY=0; + public static final double DEAD_BEND=0.05; } From 11e230b46b136b9b8a4290cde944af12ca768330 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:50:55 +0300 Subject: [PATCH 12/23] add lines --- .../java/frc/robot/subsystems/ExampleSubsystem/Elevator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index 1a280fb..fbf2611 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -46,4 +46,6 @@ public void setVelocity(double velocity){ public double getVelocity(){ return unitModel.toVelocity(motor.getSelectedSensorVelocity()); } + + } From f3046c01793c9379cfee85e29a0933063b5d4913 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 11:59:34 +0300 Subject: [PATCH 13/23] add override methods --- .../java/frc/robot/commands/MoveElevator.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/frc/robot/commands/MoveElevator.java b/src/main/java/frc/robot/commands/MoveElevator.java index 5c156a8..4f5facf 100644 --- a/src/main/java/frc/robot/commands/MoveElevator.java +++ b/src/main/java/frc/robot/commands/MoveElevator.java @@ -7,26 +7,21 @@ public class MoveElevator extends CommandBase { private final Elevator elevator; - private final DoubleSupplier doubleSupplier; + private final DoubleSupplier joystickValue; - public MoveElevator(Elevator elevator, DoubleSupplier doubleSupplier){ + public MoveElevator(Elevator elevator, DoubleSupplier joystickValue){ this.elevator=elevator; - this.doubleSupplier=doubleSupplier; + this.joystickValue=joystickValue; addRequirements(elevator); } @Override public void execute() { - elevator.setPower(); + elevator.setPower(elevator.DeadZone(joystickValue.getAsDouble())); } @Override public void end(boolean interrupted) { - - } - - @Override - public boolean isFinished() { - return false; + elevator.setPower(0); } } From 8cbca37b73e5edd57e2183b38061447d452e8c3f Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:00:04 +0300 Subject: [PATCH 14/23] add function --- .../frc/robot/subsystems/ExampleSubsystem/Elevator.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index fbf2611..51e7619 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -47,5 +47,12 @@ public double getVelocity(){ return unitModel.toVelocity(motor.getSelectedSensorVelocity()); } - + public double DeadZone(double value){ + if(value>=Constants.DEAD_BEND||value<=Constants.DEAD_BEND){ + return 0; + } + else{ + return value; + } + } } From aa549a5ad1b5686742cb57183bc4f2b27f8a8bbf Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:05:30 +0300 Subject: [PATCH 15/23] add comments --- .../java/frc/robot/commands/MoveElevator.java | 7 ++++++ .../subsystems/ExampleSubsystem/Elevator.java | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/main/java/frc/robot/commands/MoveElevator.java b/src/main/java/frc/robot/commands/MoveElevator.java index 4f5facf..e56bf41 100644 --- a/src/main/java/frc/robot/commands/MoveElevator.java +++ b/src/main/java/frc/robot/commands/MoveElevator.java @@ -15,11 +15,18 @@ public MoveElevator(Elevator elevator, DoubleSupplier joystickValue){ addRequirements(elevator); } + /** + * sets the power of the elevator to the desired value with a joystick + */ @Override public void execute() { elevator.setPower(elevator.DeadZone(joystickValue.getAsDouble())); } + /** + * stops the elevator + * @param interrupted + */ @Override public void end(boolean interrupted) { elevator.setPower(0); diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index 51e7619..abc4018 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -24,6 +24,10 @@ public Elevator(){ } + /** + * creates an instance if there isn't one + * @return + */ public Elevator getInstance(){ if(INSTANCE==null){ INSTANCE = new Elevator(); @@ -31,22 +35,43 @@ public Elevator getInstance(){ return INSTANCE; } + /** + * gets the power of the elevator + * @return + */ public double getPower(){ return motor.get(); } + /** + * sets the power of the elevator + * @param Power + */ public void setPower(double Power){ motor.set(Power); } + /** + * sets the velocity of the elevator + * @param velocity + */ public void setVelocity(double velocity){ motor.set(ControlMode.Velocity, unitModel.toTicks100ms(velocity)); } + /** + * gets the velocity of the elevator + * @return + */ public double getVelocity(){ return unitModel.toVelocity(motor.getSelectedSensorVelocity()); } + /** + * checks if the joystick is in the defined dead zone and stops the elevator from moving if it's in the dead zone + * @param value + * @return + */ public double DeadZone(double value){ if(value>=Constants.DEAD_BEND||value<=Constants.DEAD_BEND){ return 0; From 6fbc593d3d0b66b0f5905c4d2b2ead9c6b29f550 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:14:31 +0300 Subject: [PATCH 16/23] add command --- src/main/java/frc/robot/commands/PositionControl.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/frc/robot/commands/PositionControl.java diff --git a/src/main/java/frc/robot/commands/PositionControl.java b/src/main/java/frc/robot/commands/PositionControl.java new file mode 100644 index 0000000..8045f5b --- /dev/null +++ b/src/main/java/frc/robot/commands/PositionControl.java @@ -0,0 +1,6 @@ +package frc.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class PositionControl extends CommandBase { +} From 280e201e99febadf4d264ed0799c5d2d675568a7 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:14:43 +0300 Subject: [PATCH 17/23] add functions --- .../frc/robot/subsystems/ExampleSubsystem/Elevator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index abc4018..8e281c4 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -80,4 +80,12 @@ public double DeadZone(double value){ return value; } } + + public void setPosition(double height){ + motor.set(ControlMode.Position, unitModel.toTicks(height)); + } + + public double getPosition(){ + return unitModel.toUnits(motor.getSelectedSensorPosition()); + } } From a56af4260e3df12902b6538ddc34a1633cf7372f Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:47:05 +0300 Subject: [PATCH 18/23] add constructor and override methods --- .../frc/robot/commands/PositionControl.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/frc/robot/commands/PositionControl.java b/src/main/java/frc/robot/commands/PositionControl.java index 8045f5b..40a77bb 100644 --- a/src/main/java/frc/robot/commands/PositionControl.java +++ b/src/main/java/frc/robot/commands/PositionControl.java @@ -1,6 +1,35 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.CommandBase; +import frc.robot.subsystems.ExampleSubsystem.Elevator; public class PositionControl extends CommandBase { + private final Elevator elevator; + private final double height; + + public PositionControl(Elevator elevator, double height) { + this.elevator = elevator; + this.height=height; + addRequirements(elevator); + } + + @Override + public void execute() { + elevator.setPosition(height); + } + + @Override + public void end(boolean interrupted) { + elevator.setPower(0); + } + + @Override + public boolean isFinished() { + if(elevator.heightCheck(elevator.getPosition(), height)){ + return true; + } + else{ + return false; + } + } } From 9335784de08e17d099779fa86499f018e7e3adfe Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:48:14 +0300 Subject: [PATCH 19/23] add constant --- src/main/java/frc/robot/Constants.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 66b85e5..45f9877 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -23,5 +23,6 @@ public final class Constants { public static final int MOTION_ACCELERATION=0; public static final int CRUISE_VELOCITY=0; public static final double DEAD_BEND=0.05; + public static final double ELEVATOR_THRESHOLD=0.3; } From d1310b2def18e60e9a3ce59a32dff1f1c9ec9e77 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:48:31 +0300 Subject: [PATCH 20/23] add function --- .../frc/robot/subsystems/ExampleSubsystem/Elevator.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index 8e281c4..8603b29 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -88,4 +88,13 @@ public void setPosition(double height){ public double getPosition(){ return unitModel.toUnits(motor.getSelectedSensorPosition()); } + + public boolean heightCheck(double currentHeight, double desiredHeight){ + if (currentHeight>=desiredHeight-3&¤tHeight<=desiredHeight+3){ + return true; + } + else{ + return false; + } + } } From ce7867bf6025b7220fa3d30950a34589bdc2a018 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 12:53:01 +0300 Subject: [PATCH 21/23] add comments --- .../java/frc/robot/commands/PositionControl.java | 11 +++++++++++ .../subsystems/ExampleSubsystem/Elevator.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/frc/robot/commands/PositionControl.java b/src/main/java/frc/robot/commands/PositionControl.java index 40a77bb..f688ddb 100644 --- a/src/main/java/frc/robot/commands/PositionControl.java +++ b/src/main/java/frc/robot/commands/PositionControl.java @@ -13,16 +13,27 @@ public PositionControl(Elevator elevator, double height) { addRequirements(elevator); } + /** + * sets the position of the elevator + */ @Override public void execute() { elevator.setPosition(height); } + /** + * stops the elevator + * @param interrupted + */ @Override public void end(boolean interrupted) { elevator.setPower(0); } + /** + * checks if the elevator reached the desired height + * @return + */ @Override public boolean isFinished() { if(elevator.heightCheck(elevator.getPosition(), height)){ diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index 8603b29..6a40c62 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -81,14 +81,28 @@ public double DeadZone(double value){ } } + /** + * sets the position of the elevator + * @param height + */ public void setPosition(double height){ motor.set(ControlMode.Position, unitModel.toTicks(height)); } + /** + * ges the position of the elevator + * @return + */ public double getPosition(){ return unitModel.toUnits(motor.getSelectedSensorPosition()); } + /** + * checks if the elevator reached the desired position + * @param currentHeight + * @param desiredHeight + * @return + */ public boolean heightCheck(double currentHeight, double desiredHeight){ if (currentHeight>=desiredHeight-3&¤tHeight<=desiredHeight+3){ return true; From cb50a730e660e9708e042a1131de4803268ae3e1 Mon Sep 17 00:00:00 2001 From: Emma03 Date: Fri, 26 Aug 2022 13:29:18 +0300 Subject: [PATCH 22/23] changes after pull request --- src/main/java/frc/robot/Constants.java | 4 +- .../java/frc/robot/commands/MoveElevator.java | 15 ++--- .../subsystems/ExampleSubsystem/Elevator.java | 57 ++++++++----------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 45f9877..b1d7853 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -22,7 +22,7 @@ public final class Constants { public static final boolean ENABLE_VOLT_COMP= true; public static final int MOTION_ACCELERATION=0; public static final int CRUISE_VELOCITY=0; - public static final double DEAD_BEND=0.05; - public static final double ELEVATOR_THRESHOLD=0.3; + public static final double DEAD_BEND=0.05;//[%] + public static final double ELEVATOR_THRESHOLD=0.3;//[meters] } diff --git a/src/main/java/frc/robot/commands/MoveElevator.java b/src/main/java/frc/robot/commands/MoveElevator.java index e56bf41..b1d2b75 100644 --- a/src/main/java/frc/robot/commands/MoveElevator.java +++ b/src/main/java/frc/robot/commands/MoveElevator.java @@ -6,14 +6,14 @@ import java.util.function.DoubleSupplier; public class MoveElevator extends CommandBase { - private final Elevator elevator; - private final DoubleSupplier joystickValue; + private final Elevator elevator; + private final DoubleSupplier joystickValue; - public MoveElevator(Elevator elevator, DoubleSupplier joystickValue){ - this.elevator=elevator; - this.joystickValue=joystickValue; - addRequirements(elevator); - } + public MoveElevator(Elevator elevator, DoubleSupplier joystickValue) { + this.elevator = elevator; + this.joystickValue = joystickValue; + addRequirements(elevator); + } /** * sets the power of the elevator to the desired value with a joystick @@ -25,6 +25,7 @@ public void execute() { /** * stops the elevator + * * @param interrupted */ @Override diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java index 6a40c62..ef81165 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java +++ b/src/main/java/frc/robot/subsystems/ExampleSubsystem/Elevator.java @@ -9,11 +9,11 @@ import frc.robot.subsystems.UnitModel; public class Elevator extends SubsystemBase { - private final WPI_TalonFX motor=new WPI_TalonFX(Ports.MOTOR); - private static Elevator INSTANCE=null; - public static final UnitModel unitModel = new UnitModel(Constants.TICKS_PER_METER); + private final WPI_TalonFX motor = new WPI_TalonFX(Ports.MOTOR); + private static Elevator INSTANCE = null; + public static final UnitModel unitModel = new UnitModel(Constants.TICKS_PER_METER); - public Elevator(){ + public Elevator() { motor.enableVoltageCompensation(Constants.ENABLE_VOLT_COMP); motor.configVoltageCompSaturation(Constants.CONFIG_VOLT); motor.configMotionAcceleration(Constants.MOTION_ACCELERATION); @@ -26,10 +26,11 @@ public Elevator(){ /** * creates an instance if there isn't one + * * @return */ - public Elevator getInstance(){ - if(INSTANCE==null){ + public Elevator getInstance() { + if (INSTANCE == null) { INSTANCE = new Elevator(); } return INSTANCE; @@ -37,77 +38,65 @@ public Elevator getInstance(){ /** * gets the power of the elevator + * * @return */ - public double getPower(){ + public double getPower() { return motor.get(); } /** * sets the power of the elevator + * * @param Power */ - public void setPower(double Power){ + public void setPower(double Power) { motor.set(Power); } - /** - * sets the velocity of the elevator - * @param velocity - */ - public void setVelocity(double velocity){ - motor.set(ControlMode.Velocity, unitModel.toTicks100ms(velocity)); - } - - /** - * gets the velocity of the elevator - * @return - */ - public double getVelocity(){ - return unitModel.toVelocity(motor.getSelectedSensorVelocity()); - } - /** * checks if the joystick is in the defined dead zone and stops the elevator from moving if it's in the dead zone + * * @param value * @return */ - public double DeadZone(double value){ - if(value>=Constants.DEAD_BEND||value<=Constants.DEAD_BEND){ + public double DeadZone(double value) { + if (value >= Constants.DEAD_BEND || value <= Constants.DEAD_BEND) { return 0; - } - else{ + } else { return value; } } /** * sets the position of the elevator + * * @param height */ - public void setPosition(double height){ + public void setPosition(double height) { motor.set(ControlMode.Position, unitModel.toTicks(height)); } /** * ges the position of the elevator + * * @return */ - public double getPosition(){ + public double getPosition() { return unitModel.toUnits(motor.getSelectedSensorPosition()); } /** * checks if the elevator reached the desired position + * * @param currentHeight * @param desiredHeight * @return */ - public boolean heightCheck(double currentHeight, double desiredHeight){ - if (currentHeight>=desiredHeight-3&¤tHeight<=desiredHeight+3){ + public boolean heightCheck(double currentHeight, double desiredHeight) { + if (currentHeight >= desiredHeight - 3 && currentHeight <= desiredHeight + 3) { return true; - } - else{ + } else { return false; } } From 24be0ac9a424f170fbec80c54ac96fc898d0efee Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 8 Sep 2022 15:51:46 +0300 Subject: [PATCH 23/23] Load system --- .../buildOutputCleanup/buildOutputCleanup.lock | Bin 17 -> 17 bytes .../java/frc/robot/commands/PositionControl.java | 9 +++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 13cc93d69d24ad266d68f52d904da5845b006bc7..2e487310ee18a4d7a530e776cb61303adb9cd9de 100644 GIT binary patch literal 17 UcmZR6wPBy2WV-wZ1_&?*05j_ZGXMYp literal 17 UcmZR6wPBy2WV-wZ1_&?%05j?YG5`Po diff --git a/src/main/java/frc/robot/commands/PositionControl.java b/src/main/java/frc/robot/commands/PositionControl.java index f688ddb..7fcac3a 100644 --- a/src/main/java/frc/robot/commands/PositionControl.java +++ b/src/main/java/frc/robot/commands/PositionControl.java @@ -9,7 +9,7 @@ public class PositionControl extends CommandBase { public PositionControl(Elevator elevator, double height) { this.elevator = elevator; - this.height=height; + this.height = height; addRequirements(elevator); } @@ -23,6 +23,7 @@ public void execute() { /** * stops the elevator + * * @param interrupted */ @Override @@ -32,14 +33,14 @@ public void end(boolean interrupted) { /** * checks if the elevator reached the desired height + * * @return */ @Override public boolean isFinished() { - if(elevator.heightCheck(elevator.getPosition(), height)){ + if (elevator.heightCheck(elevator.getPosition(), height)) { return true; - } - else{ + } else { return false; } }