From 8b4c091da90231d27398adaaa7270dabb1536fd5 Mon Sep 17 00:00:00 2001 From: FTC16750 Date: Sat, 2 Nov 2024 10:06:07 -0700 Subject: [PATCH 1/2] LearnBot servoTestingOpmode - Maggie --- .../firstinspires/ftc/learnbot/Hardware.java | 6 ++-- .../org/firstinspires/ftc/learnbot/Robot.java | 1 + .../org/firstinspires/ftc/learnbot/Setup.java | 4 +-- .../ftc/learnbot/commands/Test.java | 17 ++++++++++ .../learnbot/controllers/TestController.java | 31 ++++++++++++++----- .../tele/{Test.java => TestOpmode.java} | 14 ++++----- .../learnbot/subsystems/TestSubsystem.java | 20 ++++++++++++ 7 files changed, 72 insertions(+), 21 deletions(-) rename LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/tele/{Test.java => TestOpmode.java} (72%) diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Hardware.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Hardware.java index fcacf772..3725ad4a 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Hardware.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Hardware.java @@ -61,9 +61,9 @@ public Hardware(HardwareMap hwmap) { if (Setup.Connected.SERVO) { this.servo = new Servo(Setup.HardwareNames.SERVO); } - if (Setup.Connected.COLOR_SENSOR) { - this.colorSensor = new ColorDistanceSensor(Setup.HardwareNames.COLOR); - } + // if (Setup.Connected.COLOR_SENSOR) { + // this.colorSensor = new ColorDistanceSensor(Setup.HardwareNames.COLOR); + // } } this.imu = new IMU( Setup.HardwareNames.IMU, diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java index 08343ad9..6a087edb 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java @@ -16,6 +16,7 @@ public class Robot implements Loggable { public DrivebaseSubsystem drivebaseSubsystem; public PlacementSubsystem placementSubsystem; + public TestSubsystem testsubsystem; public Robot(Hardware hw) { this.initialVoltage = hw.voltage(); diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java index 2ae16bde..bc2ee1d0 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java @@ -8,9 +8,9 @@ public class Setup { public static class Connected { public static boolean DRIVEBASE = true; - public static boolean TESTSUBSYSTEM = false; + public static boolean TESTSUBSYSTEM = true; public static boolean MOTOR = false; - public static boolean SERVO = false; + public static boolean SERVO = true; public static boolean DISTANCE_SENSOR = false; public static boolean COLOR_SENSOR = false; public static boolean FLYWHEEL = false; diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java index a000aed8..d8ae7b39 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java @@ -2,10 +2,27 @@ import com.technototes.library.command.Command; import com.technototes.library.command.MethodCommand; +import org.firstinspires.ftc.learnbot.Robot; import org.firstinspires.ftc.learnbot.subsystems.TestSubsystem; public class Test { + public static Command ServoMax(Robot r) { + return Command.create(r.testsubsystem::servoMaxPos, r.testsubsystem); + } + + public static Command ServoMin(Robot r) { + return Command.create(r.testsubsystem::servoMinPos, r.testsubsystem); + } + + public static Command ServoInc(Robot r) { + return Command.create(r.testsubsystem::servoIncrement, r.testsubsystem); + } + + public static Command ServoDec(Robot r) { + return Command.create(r.testsubsystem::servoDecrement, r.testsubsystem); + } + public static Command ServoLeft(TestSubsystem ts) { return new MethodCommand(TestSubsystem::servoLeft, ts); } diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java index 3564adae..62263ee6 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java @@ -7,6 +7,8 @@ import org.firstinspires.ftc.learnbot.Robot; import org.firstinspires.ftc.learnbot.commands.AnalogMotorControlCmd; import org.firstinspires.ftc.learnbot.commands.EZCmd; +import org.firstinspires.ftc.learnbot.commands.Test; +import org.firstinspires.ftc.learnbot.subsystems.TestSubsystem; public class TestController implements Loggable { @@ -17,6 +19,10 @@ public class TestController implements Loggable { public CommandButton servoright; public CommandAxis motorAxis; public CommandButton modeToggle; + public CommandButton servoMax; + public CommandButton servoMin; + public CommandButton servoInc; + public CommandButton servoDec; public CommandButton liftLow, liftMid, liftHigh; @@ -28,23 +34,32 @@ public class TestController implements Loggable { public TestController(CommandGamepad g, Robot r) { this.gamepad = g; this.robot = r; - this.liftLow = gamepad.ps_triangle; - this.liftMid = gamepad.ps_cross; - this.liftHigh = gamepad.ps_circle; + // this.liftLow = gamepad.ps_triangle; + // this.liftMid = gamepad.ps_cross; + // this.liftHigh = gamepad.ps_circle; + this.servoMax = gamepad.ps_triangle; + this.servoMin = gamepad.ps_cross; + this.servoInc = gamepad.dpadUp; + this.servoDec = gamepad.dpadDown; // this.servoleft.whenPressed(new ServoLeft(r.test)); // this.servoright.whenPressed((new ServoRight(r.test))); - this.motorAxis = gamepad.rightStickY; + //this.motorAxis = gamepad.rightStickY; this.modeToggle = gamepad.rightStickButton; // this.motorMovement = new MotorMovementCommand(r.test, this.motorAxis); // this.modeToggle.whenPressed(new ToggleMotorStopModeCommand(r.test)); // CommandScheduler.scheduleJoystick(motorMovement); - this.trigger = gamepad.leftTrigger; + //this.trigger = gamepad.leftTrigger; this.threshold = gamepad.rightTrigger.getAsButton(0.5); + bindControls(); } public void bindControls() { - liftLow.whenPressed(EZCmd.Placement.LiftLow(robot.placementSubsystem)); - liftMid.whenPressed(EZCmd.Placement.LiftMedium(robot.placementSubsystem)); - liftHigh.whenPressed(EZCmd.Placement.LiftHigh(robot.placementSubsystem)); + // liftLow.whenPressed(EZCmd.Placement.LiftLow(robot.placementSubsystem)); + // liftMid.whenPressed(EZCmd.Placement.LiftMedium(robot.placementSubsystem)); + // liftHigh.whenPressed(EZCmd.Placement.LiftHigh(robot.placementSubsystem)); + servoMax.whenPressed(Test.ServoMax(robot)); + servoMin.whenPressed(Test.ServoMin(robot)); + servoInc.whenPressed(Test.ServoInc(robot)); + servoDec.whenPressed(Test.ServoDec(robot)); } } diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/tele/Test.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/tele/TestOpmode.java similarity index 72% rename from LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/tele/Test.java rename to LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/tele/TestOpmode.java index c2d756a9..f08b97bb 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/tele/Test.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/opmodes/tele/TestOpmode.java @@ -4,17 +4,15 @@ import com.acmerobotics.dashboard.telemetry.MultipleTelemetry; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; import com.technototes.library.command.Command; -import com.technototes.library.command.CommandScheduler; import com.technototes.library.logger.Loggable; import com.technototes.library.structure.CommandOpMode; import org.firstinspires.ftc.learnbot.Hardware; import org.firstinspires.ftc.learnbot.Robot; -import org.firstinspires.ftc.learnbot.commands.TriggerTestCommand; import org.firstinspires.ftc.learnbot.controllers.TestController; @TeleOp(name = "Test") @SuppressWarnings("unused") -public class Test extends CommandOpMode implements Loggable { +public class TestOpmode extends CommandOpMode implements Loggable { public Robot robot; public TestController testCtrl; @@ -28,10 +26,10 @@ public void uponInit() { hardware = new Hardware(hardwareMap); robot = new Robot(hardware); testCtrl = new TestController(driverGamepad, robot); - trigTest = new TriggerTestCommand( - driverGamepad.leftTrigger, - driverGamepad.leftTrigger.getAsButton(.5) - ); - CommandScheduler.scheduleJoystick(trigTest); + // trigTest = new TriggerTestCommand( + // driverGamepad.leftTrigger, + // driverGamepad.leftTrigger.getAsButton(.5) + // ); + // CommandScheduler.scheduleJoystick(trigTest); } } diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java index f0b2ee0a..3ed09527 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java @@ -52,6 +52,26 @@ public TestSubsystem(Hardware hw) { resetTicks(); } + public void servoIncrement() { + running = true; + servo.setPosition(servo.getPosition() + 0.1); + } + + public void servoDecrement() { + running = true; + servo.setPosition(servo.getPosition() - 0.1); + } + + public void servoMaxPos() { + running = true; + servo.setPosition(1); + } + + public void servoMinPos() { + running = true; + servo.setPosition(0); + } + public void servoLeft() { running = true; setPosition(0.5); From 8c1d6ee006eab62c6cf6c4b44664991149b9a15d Mon Sep 17 00:00:00 2001 From: Javier Alvarez Date: Sat, 2 Nov 2024 11:15:37 -0700 Subject: [PATCH 2/2] test bot, fixes used test subsystem --- .../java/org/firstinspires/ftc/learnbot/Robot.java | 6 ++---- .../java/org/firstinspires/ftc/learnbot/Setup.java | 2 +- .../firstinspires/ftc/learnbot/commands/Test.java | 12 ++++++++++++ .../ftc/learnbot/controllers/TestController.java | 6 ++++++ .../ftc/learnbot/subsystems/TestSubsystem.java | 3 +++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java index 6a087edb..bcef3c7f 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Robot.java @@ -12,15 +12,13 @@ public class Robot implements Loggable { public StartingPosition position; public Alliance alliance; public double initialVoltage; - public TestSubsystem test; public DrivebaseSubsystem drivebaseSubsystem; - public PlacementSubsystem placementSubsystem; public TestSubsystem testsubsystem; public Robot(Hardware hw) { this.initialVoltage = hw.voltage(); - this.test = new TestSubsystem(hw); + this.testsubsystem = new TestSubsystem(hw); if (Setup.Connected.DRIVEBASE) { this.drivebaseSubsystem = new DrivebaseSubsystem( hw.flMotor, @@ -31,7 +29,7 @@ public Robot(Hardware hw) { ); } if (Setup.Connected.TESTSUBSYSTEM) { - this.test = new TestSubsystem(hw); + this.testsubsystem = new TestSubsystem(hw); } } } diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java index bc2ee1d0..77bbbc20 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/Setup.java @@ -7,7 +7,7 @@ public class Setup { @Config public static class Connected { - public static boolean DRIVEBASE = true; + public static boolean DRIVEBASE = false; public static boolean TESTSUBSYSTEM = true; public static boolean MOTOR = false; public static boolean SERVO = true; diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java index d8ae7b39..6b95e037 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/commands/Test.java @@ -8,18 +8,30 @@ public class Test { public static Command ServoMax(Robot r) { + if (r.testsubsystem == null) { + throw new RuntimeException("null testsubsystem in robot"); + } return Command.create(r.testsubsystem::servoMaxPos, r.testsubsystem); } public static Command ServoMin(Robot r) { + if (r.testsubsystem == null) { + throw new RuntimeException("null testsubsystem in robot"); + } return Command.create(r.testsubsystem::servoMinPos, r.testsubsystem); } public static Command ServoInc(Robot r) { + if (r.testsubsystem == null) { + throw new RuntimeException("null testsubsystem in robot"); + } return Command.create(r.testsubsystem::servoIncrement, r.testsubsystem); } public static Command ServoDec(Robot r) { + if (r.testsubsystem == null) { + throw new RuntimeException("null testsubsystem in robot"); + } return Command.create(r.testsubsystem::servoDecrement, r.testsubsystem); } diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java index 62263ee6..37b527bc 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/controllers/TestController.java @@ -32,6 +32,12 @@ public class TestController implements Loggable { public AnalogMotorControlCmd motorMovement; public TestController(CommandGamepad g, Robot r) { + if (g == null) { + throw new RuntimeException("Null CommandGamepad in TestController"); + } + if (r == null) { + throw new RuntimeException("Null robot in TestController"); + } this.gamepad = g; this.robot = r; // this.liftLow = gamepad.ps_triangle; diff --git a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java index 3ed09527..131c836e 100644 --- a/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java +++ b/LearnBot/src/main/java/org/firstinspires/ftc/learnbot/subsystems/TestSubsystem.java @@ -63,6 +63,9 @@ public void servoDecrement() { } public void servoMaxPos() { + if (servo == null) { + throw new RuntimeException("Null servo in TestSubsystem"); + } running = true; servo.setPosition(1); }