Skip to content

Commit

Permalink
abstract limelight to take input limelight name
Browse files Browse the repository at this point in the history
- quinn
  • Loading branch information
quackitsquinn committed Oct 23, 2023
1 parent b684f46 commit b87b322
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/frc/robot/subsystems/Limelight.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit b87b322

Please sign in to comment.