From b87b322e4f7c9bda65eec086d8ec0c90083e032e Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 23 Oct 2023 15:12:32 -0500 Subject: [PATCH] abstract limelight to take input limelight name - quinn --- src/main/java/frc/robot/RobotContainer.java | 5 +++-- .../java/frc/robot/subsystems/Limelight.java | 22 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 8e10504..c33fa99 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -59,8 +59,9 @@ public class RobotContainer { * TODO: organize later */ /* Autotasks are mostly commented out in here for now because I don't care that they exist */ - private final Limelight limelight = new Limelight(); - private final Drive driveSubsystem = new Drive(limelight); + private final Limelight back_limelight = new Limelight("limelight-back"); + private final Limelight front_limelight = new Limelight("limelight-front"); + private final Drive driveSubsystem = new Drive(back_limelight); /* BIG CHUNGUS ARM CODE */ //private final I2CManager I2CManager = new I2CManager(); //private final ArmBase armBase = new ArmBase(); diff --git a/src/main/java/frc/robot/subsystems/Limelight.java b/src/main/java/frc/robot/subsystems/Limelight.java index dcdd236..72d9b40 100644 --- a/src/main/java/frc/robot/subsystems/Limelight.java +++ b/src/main/java/frc/robot/subsystems/Limelight.java @@ -40,20 +40,28 @@ public class Limelight extends SubsystemBase { * to understand what the heck the different indices in this array mean */ private double[] botpos; + private String name; - /** Creates a new Limelight. Should be run once from {@link frc.robot.RobotContainer}. */ - public Limelight() { - tvSubscriber = NetworkTableInstance.getDefault().getDoubleTopic("/limelight-back/tv").subscribe(0.0); - txSubscriber = NetworkTableInstance.getDefault().getDoubleTopic("/limelight-back/tx").subscribe(0.0); - tySubscriber = NetworkTableInstance.getDefault().getDoubleTopic("/limelight-back/ty").subscribe(0.0); - taSubscriber = NetworkTableInstance.getDefault().getDoubleTopic("/limelight-back/ta").subscribe(0.0); + private String fmtPath(String end) { + return "/" + name + "/" + end; + } + + /** Creates a new Limelight. Should be run once from {@link frc.robot.RobotContainer}. + * @param name The hostname of the limelight + */ + public Limelight(String name) { + this.name = name; + tvSubscriber = NetworkTableInstance.getDefault().getDoubleTopic(fmtPath("tv")).subscribe(0.0); + txSubscriber = NetworkTableInstance.getDefault().getDoubleTopic(fmtPath("tx")).subscribe(0.0); + tySubscriber = NetworkTableInstance.getDefault().getDoubleTopic(fmtPath("ty")).subscribe(0.0); + taSubscriber = NetworkTableInstance.getDefault().getDoubleTopic(fmtPath("ta")).subscribe(0.0); /* In theory this won't break. It got mad when I tried to insert the array into the * method like .subscribe({0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) so ¯\_(ツ)_/¯ */ double[] defaultBotpos = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; botposSubscriber = NetworkTableInstance.getDefault() - .getDoubleArrayTopic("/limelight-back/botpose") + .getDoubleArrayTopic(fmtPath("botpose")) .subscribe(defaultBotpos); }