From aa18b17d297c37087a07cb3c6f3902ba09924ad8 Mon Sep 17 00:00:00 2001 From: missing <4a656666official@gmail.com> Date: Thu, 27 Jan 2022 16:51:03 -0600 Subject: [PATCH] make stuff not be static --- .gitignore | 2 + .../org/firstinspires/ftc/teamcode/API.java | 81 ++++++++----------- .../firstinspires/ftc/teamcode/AutonFive.java | 24 ------ .../ftc/teamcode/AutonFourB.java | 46 +++++------ .../ftc/teamcode/AutonFourR.java | 46 +++++------ .../firstinspires/ftc/teamcode/AutonOne.java | 24 ------ .../ftc/teamcode/AutonThree.java | 24 ------ .../firstinspires/ftc/teamcode/AutonTwo.java | 33 -------- .../ftc/teamcode/BaseLinearOpMode.java | 17 ++++ .../ftc/teamcode/BaseOpMode.java | 17 ++++ .../ftc/teamcode/BasicOpMode.java | 21 ----- .../firstinspires/ftc/teamcode/GameMotor.java | 20 +++-- .../ftc/teamcode/GameMotors.java | 20 +++++ .../firstinspires/ftc/teamcode/Gamepad.java | 29 ++++--- .../ftc/teamcode/GamepadRecord.java | 22 +++-- .../ftc/teamcode/MovementAPI.java | 14 ++-- .../firstinspires/ftc/teamcode/Replayer.java | 26 +++--- 17 files changed, 205 insertions(+), 261 deletions(-) delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFive.java delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonOne.java delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonThree.java delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonTwo.java create mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseLinearOpMode.java create mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseOpMode.java delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BasicOpMode.java create mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotors.java diff --git a/.gitignore b/.gitignore index 43a8acc..f2d72c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +deploymentTargetDropDown.xml + # fork ds store .DS_Store diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/API.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/API.java index f12860e..35477b1 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/API.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/API.java @@ -13,41 +13,38 @@ import java.io.File; import java.util.UUID; public class API { - private static OpMode opMode; - public static HubIMU imu; - public static boolean useLogFile = false; - public static File logFile = null; + private OpMode opMode; + public HubIMU imu; + public boolean useLogFile = false; + public File logFile = null; + public Gamepad gamepad1; + public Gamepad gamepad2; /** - * Initializes the API - * * @param mode the opmode to initialize with * @param useLogFile whether or not to log to a log file */ - public static void init(final OpMode mode, boolean useLogFile) { + public API(final OpMode mode, boolean useLogFile) { opMode = mode; print("Initializing API for class " + opMode.getClass().getName() + "..."); - HardwareMap map = mode.hardwareMap; - imu = new HubIMU("imu", map); +// for (Motor m : Motor.values()) m.init(mode.hardwareMap); +// for (Servo s : Servo.values()) s.init(mode.hardwareMap); + imu = new HubIMU("imu"); + gamepad1 = new Gamepad(GamepadIndex.GAMEPAD1); + gamepad2 = new Gamepad(GamepadIndex.GAMEPAD2); - for (Motor m : Motor.values()) m.init(map); - for (Servo s : Servo.values()) s.init(map); - imu = new HubIMU("imu", map); - - API.useLogFile = useLogFile; + this.useLogFile = useLogFile; if (useLogFile) logFile = AppUtil.getInstance().getSettingsFile("log-" + UUID.randomUUID().toString() + ".log"); } /** - * Initializes the API - * * @param mode the opmode to initialize with */ - public static void init(final OpMode mode) { - API.init(mode, true); + public API(final OpMode mode) { + this(mode, true); } /** @@ -55,7 +52,7 @@ public class API { * * @param seconds the amount of seconds to pause for */ - public static void pause(double seconds) { + public void pause(double seconds) { double time = opMode.getRuntime() + seconds; while (opMode.getRuntime() < time) ; /* no empty while loop here! */ } @@ -66,7 +63,7 @@ public class API { * @param s the text to print * @see API#print(String, String) */ - public static void print(String s) { + public void print(String s) { opMode.telemetry.addLine(s); opMode.telemetry.update(); @@ -81,7 +78,7 @@ public class API { * @param value the value to print * @see API#print(String) */ - public static void print(String caption, String value) { + public void print(String caption, String value) { opMode.telemetry.addData(caption, value); opMode.telemetry.update(); @@ -92,12 +89,12 @@ public class API { /** * Clears the telemetry */ - public static void clear() { + public void clear() { opMode.telemetry.clear(); } - public enum Motor { - M0("m0"), M1("m1"), M2("m2"), M3("m3"), M4("m4"), M5("m5"), M6("m6"), M7("m7"); + public class Motor { +// M0("m0"), M1("m1"), M2("m2"), M3("m3"), M4("m4"), M5("m5"), M6("m6"), M7("m7"); private final String name; private DcMotor rawMotor; @@ -106,10 +103,7 @@ public class API { Motor(String name) { this.name = name; - } - - private void init(HardwareMap map) { - rawMotor = map.get(DcMotor.class, name); + rawMotor = opMode.hardwareMap.get(DcMotor.class, name); rawMotor.setPower(0); } @@ -261,8 +255,8 @@ public class API { } } - public enum Servo { - S0("s0"), S1("s1"), S2("s2"), S3("s3"), S4("s4"), S5("s5"), S6("s6"), S7("s7"), S8("s8"), S9("s9"), S10("s10"), S11("s11"); + public class Servo { +// S0("s0"), S1("s1"), S2("s2"), S3("s3"), S4("s4"), S5("s5"), S6("s6"), S7("s7"), S8("s8"), S9("s9"), S10("s10"), S11("s11"); private final String name; private com.qualcomm.robotcore.hardware.Servo servo; private Direction direction = Direction.FORWARD; @@ -270,10 +264,7 @@ public class API { Servo(String name) { this.name = name; - } - - void init(HardwareMap map) { - servo = map.get(com.qualcomm.robotcore.hardware.Servo.class, name); + servo = opMode.hardwareMap.get(com.qualcomm.robotcore.hardware.Servo.class, name); } /** @@ -327,12 +318,12 @@ public class API { } } - public static class HubIMU { + public class HubIMU { private final BNO055IMU imu; private double zeroPos; - public HubIMU(String name, HardwareMap hardwareMap) { - imu = hardwareMap.get(BNO055IMU.class, name); + public HubIMU(String name) { + imu = opMode.hardwareMap.get(BNO055IMU.class, name); setParameters(); } @@ -414,17 +405,15 @@ public class API { } } - public enum Gamepad { - G1(1), G2(2); - private final int number; + public enum GamepadIndex { + GAMEPAD1, GAMEPAD2 + } + + public class Gamepad { private com.qualcomm.robotcore.hardware.Gamepad gamepad; - Gamepad(int number) { - this.number = number; - } - - void init(OpMode opMode) { - this.gamepad = this.number == 1 ? opMode.gamepad1 : opMode.gamepad2; + Gamepad(GamepadIndex index) { + this.gamepad = index == GamepadIndex.GAMEPAD1 ? opMode.gamepad1 : opMode.gamepad2; } // Sticks diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFive.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFive.java deleted file mode 100644 index 1dcda24..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFive.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -import com.qualcomm.robotcore.eventloop.opmode.Autonomous; -import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; - -@Autonomous(name="Auton 5.0", preselectTeleOp = "AAAAAAAAA") -public class AutonFive extends LinearOpMode { - @Override - public void runOpMode() { - API.init(this); - API.print("Status", "Initializing, please wait"); - MovementAPI.init(); - GameMotor.LIFT.m.setDirection(API.Direction.REVERSE, false); - - API.clear(); - API.print("Press play to start"); - - waitForStart(); - - MovementAPI.move(0, 0.35, true); - API.pause(4); - MovementAPI.stop(); - } -} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourB.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourB.java index 68a9302..45ec9df 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourB.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourB.java @@ -4,44 +4,44 @@ import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; @Autonomous(name="Auton 4.2 Blue", preselectTeleOp = "AAAAAAAAA") -public class AutonFourB extends LinearOpMode { +public class AutonFourB extends BaseLinearOpMode { @Override public void runOpMode() { - API.init(this); - API.print("Status", "Initializing, please wait"); - MovementAPI.init(); - GameMotor.LIFT.m.setDirection(API.Direction.REVERSE, false); + this.construct(); + api.print("Status", "Initializing, please wait"); + MovementAPI.init(api, motors); + motors.lift.setDirection(API.Direction.REVERSE, false); - API.clear(); - API.print("Press play to start"); + api.clear(); + api.print("Press play to start"); waitForStart(); MovementAPI.move(-180, 0.4, true); - API.pause(0.8); + api.pause(0.8); MovementAPI.stop(); - GameMotor.LIFT.m.start(0.25); - API.pause(3); - GameMotor.LIFT.m.stop(); - GameMotor.LIFT.m.start(-0.25); - API.pause(2.5); - GameMotor.LIFT.m.stop(); + motors.lift.start(0.25); + api.pause(3); + motors.lift.stop(); + motors.lift.start(-0.25); + api.pause(2.5); + motors.lift.stop(); MovementAPI.move(0, 0.4, true); - API.pause(1); + api.pause(1); MovementAPI.move(90, 0.4, true); - API.pause(3); + api.pause(3); MovementAPI.move(-180, 0.4, true); - API.pause(1); + api.pause(1); MovementAPI.move(90, 0.4, true); - API.pause(1); + api.pause(1); MovementAPI.move(0, 0.2, true); - API.pause(1.6); + api.pause(1.6); MovementAPI.move(0, 0.1, true); - GameMotor.CAROUSEL.m.start(0.75); - API.pause(5); - GameMotor.CAROUSEL.m.stop(); + motors.carousel.start(0.75); + api.pause(5); + motors.carousel.stop(); MovementAPI.move(180, 0.4, true); - API.pause(0.47); + api.pause(0.47); MovementAPI.stop(); } } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourR.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourR.java index 451dae0..adc886e 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourR.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonFourR.java @@ -4,44 +4,44 @@ import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; @Autonomous(name="Auton 4.2 Red", preselectTeleOp = "AAAAAAAAA") -public class AutonFourR extends LinearOpMode { +public class AutonFourR extends BaseLinearOpMode { @Override public void runOpMode() { - API.init(this); - API.print("Status", "Initializing, please wait"); - MovementAPI.init(); - GameMotor.LIFT.m.setDirection(API.Direction.REVERSE, false); + this.construct(); + api.print("Status", "Initializing, please wait"); + MovementAPI.init(api, motors); + motors.lift.setDirection(API.Direction.REVERSE, false); - API.clear(); - API.print("Press play to start"); + api.clear(); + api.print("Press play to start"); waitForStart(); MovementAPI.move(-180, 0.4, true); - API.pause(0.8); + api.pause(0.8); MovementAPI.stop(); - GameMotor.LIFT.m.start(0.25); - API.pause(3); - GameMotor.LIFT.m.stop(); - GameMotor.LIFT.m.start(-0.25); - API.pause(2.5); - GameMotor.LIFT.m.stop(); + motors.lift.start(0.25); + api.pause(3); + motors.lift.stop(); + motors.lift.start(-0.25); + api.pause(2.5); + motors.lift.stop(); MovementAPI.move(0, 0.4, true); - API.pause(1); + api.pause(1); MovementAPI.move(-90, 0.4, true); - API.pause(3); + api.pause(3); MovementAPI.move(-180, 0.4, true); - API.pause(1); + api.pause(1); MovementAPI.move(-90, 0.4, true); - API.pause(1); + api.pause(1); MovementAPI.move(0, 0.2, true); - API.pause(1.6); + api.pause(1.6); MovementAPI.move(0, 0.1, true); - GameMotor.CAROUSEL.m.start(-0.75); - API.pause(5); - GameMotor.CAROUSEL.m.stop(); + motors.carousel.start(-0.75); + api.pause(5); + motors.carousel.stop(); MovementAPI.move(180, 0.4, true); - API.pause(0.6); + api.pause(0.6); MovementAPI.stop(); } } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonOne.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonOne.java deleted file mode 100644 index 2161ac6..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonOne.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -import com.qualcomm.robotcore.eventloop.opmode.Autonomous; -import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; -import com.qualcomm.robotcore.eventloop.opmode.OpMode; - -@Autonomous(name="Autonomous 0.00000000000000000000000002 WORKING????", preselectTeleOp="AAAAAAAAA") -public class AutonOne extends LinearOpMode { - @Override - public void runOpMode() { - API.init(this); - API.print("Status", "Initializing, please wait"); - MovementAPI.init(); - - API.clear(); - API.print("Press play to start"); - - waitForStart(); - - MovementAPI.move(0, 1, true); - API.pause(1); - MovementAPI.stop(); - } -} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonThree.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonThree.java deleted file mode 100644 index ef4bbb6..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonThree.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -import com.qualcomm.robotcore.eventloop.opmode.Autonomous; -import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; - -@Autonomous(name="Autonomous 0.00000000000000000000000003 WORKING????", preselectTeleOp="AAAAAAAAA") -public class AutonThree extends LinearOpMode { - @Override - public void runOpMode() { - API.init(this); - API.print("Status", "Initializing, please wait"); - MovementAPI.init(); - - API.clear(); - API.print("Press play to start"); - - waitForStart(); - - MovementAPI.move(0, 1, true); - API.pause(1); - MovementAPI.stop(); - GameMotor.CAROUSEL.m.start(0.6); - } -} \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonTwo.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonTwo.java deleted file mode 100644 index 8076beb..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/AutonTwo.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -import com.qualcomm.robotcore.eventloop.opmode.Autonomous; -import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; - -@Autonomous(name="Auton 2.0 maybe working?????", preselectTeleOp = "AAAAAAAAA") -public class AutonTwo extends LinearOpMode { - @Override - public void runOpMode() { - API.init(this); - API.print("Status", "Initializing, please wait"); - MovementAPI.init(); - GameMotor.LIFT.m.setDirection(API.Direction.REVERSE, false); - - API.clear(); - API.print("Press play to start"); - - waitForStart(); - - MovementAPI.move(-180, 0.4, true); - API.pause(0.8); - MovementAPI.stop(); - GameMotor.LIFT.m.start(0.25); - API.pause(5); - GameMotor.LIFT.m.stop(); - GameMotor.LIFT.m.start(-0.25); - API.pause(2.5); - GameMotor.LIFT.m.stop(); - MovementAPI.move(-180, -0.4, true); - API.pause(0.8); - MovementAPI.stop(); - } -} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseLinearOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseLinearOpMode.java new file mode 100644 index 0000000..db12a90 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseLinearOpMode.java @@ -0,0 +1,17 @@ +package org.firstinspires.ftc.teamcode; + +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; + +public abstract class BaseLinearOpMode extends LinearOpMode { + protected API api; + protected GameMotors motors; + + public void construct() { + api = new API(this, true); + motors = new GameMotors(api); + } + public void construct(boolean useLogFile) { + api = new API(this, useLogFile); + motors = new GameMotors(api); + } +} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseOpMode.java new file mode 100644 index 0000000..a280110 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BaseOpMode.java @@ -0,0 +1,17 @@ +package org.firstinspires.ftc.teamcode; + +import com.qualcomm.robotcore.eventloop.opmode.OpMode; + +public abstract class BaseOpMode extends OpMode { + protected API api; + protected GameMotors motors; + + public void construct() { + api = new API(this); + motors = new GameMotors(api); + } + public void construct(boolean useLogFile) { + api = new API(this, useLogFile); + motors = new GameMotors(api); + } +} \ No newline at end of file diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BasicOpMode.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BasicOpMode.java deleted file mode 100644 index fc6eafb..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/BasicOpMode.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; -import com.qualcomm.robotcore.eventloop.opmode.TeleOp; - - -@TeleOp -public class BasicOpMode extends LinearOpMode { - @Override - public void runOpMode() { - API.init(this); - API.Motor motor = API.Motor.M0; - motor.setDirection(API.Direction.REVERSE); - - waitForStart(); - - while(opModeIsActive()) { - motor.start(1); - } - } -} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotor.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotor.java index 130bca4..cebbc0e 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotor.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotor.java @@ -1,11 +1,21 @@ package org.firstinspires.ftc.teamcode; +//public enum GameMotor { +// FL(API.Motor.M0), FR(API.Motor.M1), BL(API.Motor.M2), BR(API.Motor.M3), INTAKE(API.Motor.M4), LIFT(API.Motor.M5), CAROUSEL(API.Motor.M6); +// +// public final API.Motor m; +// +// GameMotor(API.Motor _m) { +// m = _m; +// } +//} + public enum GameMotor { - FL(API.Motor.M0), FR(API.Motor.M1), BL(API.Motor.M2), BR(API.Motor.M3), INTAKE(API.Motor.M4), LIFT(API.Motor.M5), CAROUSEL(API.Motor.M6); + FL("m0"), FR("m1"), BL("m2"), BR("m3"), + INTAKE("m4"), LIFT("m5"), CAROUSEL("m6"); - public final API.Motor m; + public final String name; - GameMotor(API.Motor _m) { - m = _m; - } + GameMotor(String name) { this.name = name; } } + diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotors.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotors.java new file mode 100644 index 0000000..8a683a1 --- /dev/null +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GameMotors.java @@ -0,0 +1,20 @@ +package org.firstinspires.ftc.teamcode; + +public class GameMotors { + private API api; + + public API.Motor fl, fr, bl, br, intake, lift, carousel; + + public GameMotors(API api) { + this.api = api; + + fl = api.new Motor(GameMotor.FL.name); + fr = api.new Motor(GameMotor.FR.name); + bl = api.new Motor(GameMotor.BL.name); + br = api.new Motor(GameMotor.BR.name); + + intake = api.new Motor(GameMotor.INTAKE.name); + lift = api.new Motor(GameMotor.LIFT.name); + carousel = api.new Motor(GameMotor.CAROUSEL.name); + } +} diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Gamepad.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Gamepad.java index 8f7290d..da0d253 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Gamepad.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Gamepad.java @@ -1,39 +1,38 @@ package org.firstinspires.ftc.teamcode; -import com.qualcomm.robotcore.eventloop.opmode.OpMode; - -public class Gamepad extends OpMode { +public abstract class Gamepad extends BaseOpMode { protected double speed = 1; @Override public void init() { - API.init(this); - API.print("Status", "Initializing, please wait"); - API.pause(1); + this.construct(); - GameMotor.LIFT.m.setDirection(API.Direction.REVERSE); - MovementAPI.init(); + api.print("Status", "Initializing, please wait"); + api.pause(1); - API.clear(); - API.print("Press play to start"); + motors.lift.setDirection(API.Direction.REVERSE); + MovementAPI.init(api, motors); + + api.clear(); + api.print("Press play to start"); } @Override public void start() { - API.clear(); + api.clear(); } @Override public void loop() { MovementAPI.move(-gamepad1.left_stick_y, gamepad1.left_stick_x, gamepad1.right_stick_x, speed, true); - API.print("Speed", speed + ""); // i dont know how to do this better + api.print("Speed", speed + ""); // i dont know how to do this better if (gamepad1.right_bumper) speed = Math.min(speed + 0.01, 1); else if (gamepad1.left_bumper) speed = Math.max(speed - 0.01, 0.2); - GameMotor.INTAKE.m.controlWithTwoButtons(gamepad2.a, gamepad2.b); - GameMotor.LIFT.m.controlWithTwoButtons(gamepad2.dpad_up, gamepad2.dpad_down, 0.25); - GameMotor.CAROUSEL.m.controlWithTwoButtons(gamepad2.x, gamepad2.y); + motors.intake.controlWithTwoButtons(gamepad2.a, gamepad2.b); + motors.lift.controlWithTwoButtons(gamepad2.dpad_up, gamepad2.dpad_down, 0.25); + motors.carousel.controlWithTwoButtons(gamepad2.x, gamepad2.y); } } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadRecord.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadRecord.java index 19527ba..2c36649 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadRecord.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/GamepadRecord.java @@ -9,6 +9,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; +import java.util.HashMap; @TeleOp(name="Gamepad Recorder v1.0.1") public class GamepadRecord extends Gamepad { @@ -17,6 +18,7 @@ public class GamepadRecord extends Gamepad { private JSONObject outputJSON; private boolean prevGuide = false; private int currentIndex = 0; + private HashMap motors = new HashMap(); @Override public void init() { @@ -27,11 +29,15 @@ public class GamepadRecord extends Gamepad { outputJSON = new JSONObject(); outputJSON.put("recordedData", new JSONArray()); } catch (JSONException e) { - API.print("Why are we here? Just to suffer?"); + api.print("Why are we here? Just to suffer?"); } - API.clear(); - API.print("Press play to start"); + for (GameMotor m : GameMotor.values()) { + motors.put(m, api.new Motor(m.name)); + } + + api.clear(); + api.print("Press play to start"); } @Override @@ -40,13 +46,13 @@ public class GamepadRecord extends Gamepad { super.loop(); - API.print("Time", this.time + ""); + api.print("Time", this.time + ""); try { JSONObject motorData = new JSONObject(); for (GameMotor m : GameMotor.values()) { - motorData.put(m.name().toLowerCase(), m.m.getRawPower()); + motorData.put(m.name().toLowerCase(), motors.get(m).getRawPower()); } JSONObject currentData = new JSONObject() @@ -61,19 +67,19 @@ public class GamepadRecord extends Gamepad { ) outputJSON.getJSONArray("recordedData").put(currentIndex++, currentData); } catch (JSONException e) { - API.print("Why are we here? Just to suffer?" + System.lineSeparator() + e.getMessage()); + api.print("Why are we here? Just to suffer?" + System.lineSeparator() + e.getMessage()); } ms -= System.currentTimeMillis(); if (ms > 5) try { Thread.sleep(ms); } catch (InterruptedException ie) { - API.print("Why are we here? Just to suffer? (Thread.sleep error)"); + api.print("Why are we here? Just to suffer? (Thread.sleep error)"); } if (gamepad1.guide && !prevGuide) { ReadWriteFile.writeFile(outputFile, outputJSON.toString()); - API.print("Wrote file to '" + outputFile.getName() + "'!"); + api.print("Wrote file to '" + outputFile.getName() + "'!"); } prevGuide = gamepad1.guide; diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MovementAPI.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MovementAPI.java index c5ab828..557042a 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MovementAPI.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MovementAPI.java @@ -1,6 +1,8 @@ package org.firstinspires.ftc.teamcode; public class MovementAPI { + private static API api; + private static API.Motor fl; private static API.Motor fr; private static API.Motor bl; @@ -19,8 +21,10 @@ public class MovementAPI { * @param _bl the back-left wheel * @param _br the back-right wheel */ - public static void init(API.Motor _fl, API.Motor _fr, API.Motor _bl, API.Motor _br) { - API.print("Initializing MovementAPI..."); + public static void init(API api, API.Motor _fl, API.Motor _fr, API.Motor _bl, API.Motor _br) { + MovementAPI.api = api; + + api.print("Initializing Movementapi..."); fl = _fl; fr = _fr; @@ -36,8 +40,8 @@ public class MovementAPI { /** * Initializes the API with the motors in the GameMotor enum */ - public static void init() { - init(GameMotor.FL.m, GameMotor.FR.m, GameMotor.BL.m, GameMotor.BR.m); + public static void init(API api, GameMotors motors) { + init(api, motors.fl, motors.fr, motors.bl, motors.br); } /** @@ -66,7 +70,7 @@ public class MovementAPI { bl.start(blPower); br.start(brPower); - if (verbose) API.print( + if (verbose) api.print( "Front Left: " + flPower + System.lineSeparator() + "Back Left: " + blPower + System.lineSeparator() + "Front Right: " + frPower + System.lineSeparator() + diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Replayer.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Replayer.java index fcf566b..b0e0c7f 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Replayer.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Replayer.java @@ -1,6 +1,5 @@ package org.firstinspires.ftc.teamcode; -import com.qualcomm.robotcore.eventloop.opmode.OpMode; import com.qualcomm.robotcore.util.ReadWriteFile; import org.firstinspires.ftc.robotcore.internal.system.AppUtil; @@ -8,12 +7,14 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; +import java.util.HashMap; -public class Replayer extends OpMode { +public class Replayer extends BaseOpMode { private final String recordingFileName; private File recordingFile; private JSONObject recordingJSON; private int nextIndex = 0; + private HashMap motors = new HashMap(); public Replayer(String fileName) { this.recordingFileName = fileName; @@ -21,9 +22,10 @@ public class Replayer extends OpMode { @Override public void init() { - API.init(this); - API.print("Status", "Initializing, please wait"); - API.pause(1); + this.construct(); + + api.print("Status", "Initializing, please wait"); + api.pause(1); recordingFile = AppUtil.getInstance().getSettingsFile(recordingFileName); try { @@ -32,13 +34,17 @@ public class Replayer extends OpMode { somethingWentWrong(e); } - API.clear(); - API.print("Press play to start"); + for (GameMotor m : GameMotor.values()) { + motors.put(m, api.new Motor(m.name)); + } + + api.clear(); + api.print("Press play to start"); } @Override public void start() { - API.clear(); + api.clear(); this.resetStartTime(); } @@ -53,7 +59,7 @@ public class Replayer extends OpMode { if (this.getRuntime() * 1000 < currentListElement.getDouble("time")) return; for (GameMotor m : GameMotor.values()) { - m.m.start(currentData.has(m.name().toLowerCase()) ? currentData.getDouble(m.name().toLowerCase()) : 0); + motors.get(m).start(currentData.has(m.name().toLowerCase()) ? currentData.getDouble(m.name().toLowerCase()) : 0); } nextIndex++; @@ -68,7 +74,7 @@ public class Replayer extends OpMode { } public void somethingWentWrong(Exception e) { - API.print( + api.print( "Why are we here? Just to suffer?" + System.lineSeparator() + e.getMessage() ); this.requestOpModeStop();