Skip to content
This repository was archived by the owner on Feb 23, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions Limelight_NetworkTables_KL
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package org.usfirst.frc.team86.robot;

import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;

/**
* Wrapper class for getting and setting Limelight NetworkTable values.
// Kaitlyn

public class Limelight {
private static NetworkTableInstance table = null;


public static enum LightMode {
eOn, eOff, eBlink
}

/**
* Camera modes for Limelight.

*/
public static enum CameraMode {
eVision, eDriver
}

/**
* Gets whether a target is detected by the Limelight.
*
* @return true if a target is detected, false otherwise.
*/
public static boolean isTarget() {
return getValue("tv").getDouble(0) == 1;
}

/**
* Horizontal offset from crosshair to target (-27 degrees to 27 degrees).
*
* @return tx as reported by the Limelight.
*/
public static double getTx() {
return getValue("tx").getDouble(0.00);
}

/**
* Vertical offset from crosshair to target (-20.5 degrees to 20.5 degrees).
*
* @return ty as reported by the Limelight.
*/
public static double getTy() {
return getValue("ty").getDouble(0.00);
}

/**
* Area that the detected target takes up in total camera FOV (0% to 100%).
*
* @return Area of target.
*/
public static double getTa() {
return getValue("ta").getDouble(0.00);
}

/**
* Gets target skew or rotation (-90 degrees to 0 degrees).
*
* @return Target skew.
*/
public static double getTs() {
return getValue("ts").getDouble(0.00);
}

/**
* Gets target latency (ms).
*
* @return Target latency.
*/
public static double getTl() {
return getValue("tl").getDouble(0.00);
}

/**
* Sets LED mode of Limelight.
*
* @param mode
* Light mode for Limelight.
*/
public static void setLedMode(LightMode mode) {
getValue("ledMode").setNumber(mode.ordinal());
}

/**
* Sets camera mode for Limelight.
*
* @param mode
* Camera mode for Limelight.
*/
public static void setCameraMode(CameraMode mode) {
getValue("camMode").setNumber(mode.ordinal());
}

/**
* Sets pipeline number (0-9 value).
*
* @param number
* Pipeline number (0-9).
*/
public static void setPipeline(int number) {
getValue("pipeline").setNumber(number);
}

/**
* Helper method to get an entry from the Limelight NetworkTable.
*
* @param key
* Key for entry.
* @return NetworkTableEntry of given entry.
*/
private static NetworkTableEntry getValue(String key) {
if (table == null) {
table = NetworkTableInstance.getDefault();
}

return table.getTable("limelight").getEntry(key);
}
}
// work with other classes - use for network table values - Hope this helps :)