Looking for how to start with Limelight! (Java)

So, our team will probably have Limelight 2 camera for the next season, and as our team’s programmer, I would like to know some essentials for me!
First of all, I know about the docs which have some code examples but I really want to see code examples of Limelight from other teams!
Secondly, I want to know how can I integrate the Limelight system into the Command-Based programming of WPILib, should I create new subsystem for that? How would commands look like for Limelight? Again, code examples will be great!
Thanks for any help!

I’d recommend creating something called a wrapper. I’ll send a example of how we did it in one second but it allows you to just call methods rather then do everything for the network tables every time you want to use it

package org.tahomarobotics.robot.vision;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.tahomarobotics.robot.UpdateIF;
public class Limelight implements UpdateIF {

private static NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight");
//x location of the target
private static NetworkTableEntry tx = table.getEntry("tx");
//y location of the target
private static NetworkTableEntry ty = table.getEntry("ty");
//area of the target
private static NetworkTableEntry ta = table.getEntry("ta");
//does the limelight have a target
private static NetworkTableEntry tv = table.getEntry("tv");

public static double getX(){
	return tx.getDouble(0.0);
}

public static double getY(){
	return ty.getDouble(0.0);
}

public static double getDistance(){
	double heightOfCamera = 43;
	double heightOfTarget = 29;
	double angleOfCamera = -20;
	double angleofTarget =  ty.getDouble(0.0);
	return (heightOfTarget - heightOfCamera) / Math.tan(Math.toRadians(angleOfCamera + angleofTarget));
}

public static double getArea(){
	return ta.getDouble(0.0);
}

public static boolean isTargetAvalible(){
	return tv.getBoolean(false);
}
//Moding the limelight to work for the individual case
public static void drivingMode(boolean driveMode){
	ledMode(!driveMode);
	double mode = driveMode ? 1 : 0;
	table.getEntry("camMode").setNumber(mode);
}
public static void ledMode(boolean on){
	double mode = on ? 0 : 1;
	NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(mode);
}
public enum VisionModes{
	LOW(0),
	LEFT(1),
	RIGHT(2);
	public double mode;
	VisionModes(double mode){
		this.mode = mode;
	}
}
public static void setVisionMode(){
	setVisionMode(VisionModes.LOW);
}
public static void setVisionMode(VisionModes visionMode){
	table.getEntry("pipeline").setNumber(visionMode.mode);
}
public static String getVisionMode(){
	return  NetworkTableInstance.getDefault().getTable("limelight").getEntry("getpipe").getString("0");
}
@Override
public void update(boolean isEnabled) {
	SmartDashboard.putNumber("limelight x", getX());
	SmartDashboard.putNumber("limelight y", getY());
	SmartDashboard.putNumber("limelight area", getArea());
	SmartDashboard.putNumber("limelight distance", getDistance());
	SmartDashboard.putBoolean("limelight has target", isTargetAvalible());
	SmartDashboard.putString("limelight mode", getVisionMode());
}

}

Thanks! Where did you write the code?

I don’t understand the question. Do you mean how did we align?

limelight is prolly the most well documented resource in frc to get up and running.
http://docs.limelightvision.io/en/latest/cs_drive_to_goal_2019.html has a good example of deep space code. The docs tell you pretty much everything you need to learn.

We recommend the same thing. This is not quite ready for prime time for an installer but there are instructions how to add the wrapper to your project on the github Lime Light folder. The team is trying to automate a way to bring in the code we use year after year. I can tell you creating your own class with the constructor, and all the getters and setters is wonderful. We added a second Lime Light mid season and it was as simple to declare a new instance using the modified LimeLight-yourName constructor. Then treat it like you would any other object you have multiples of.

Our 2019 code uses a manual copy of the our LimeLight library in the src/main/java/oi/limelightvision/limelight folder but the Gradle installer works the same. You can see in our Robot/OI we declare two Lime Lights

public class OI {
    private LimeLight limeLight;
    private LimeLight limeLight2;

...
}

and in the OI constructor instantiate them

public OI() {
....
      limeLight = new LimeLight(); 
      limeLight2 = new LimeLight("limelight-two"); 
}

Finally created a getter for each

public LimeLight get_my_LimeLight(){
      return limeLight;
    }

    public LimeLight get_my_LimeLight2(){
      return limeLight2;
    }

I mean where is the class “Limelight” found in your robot program?

Thank you!