Limelight programming help

Can someone explain to me how i program my limelight to interact with my launcher and drive train? Sorry i don’t know what i’m talking about. I’ll post my code that i have so far down below.

/----------------------------------------------------------------------------/

/* Copyright © 2018-2019 FIRST. All Rights Reserved. */

/* Open Source Software - may be modified and shared by FRC teams. The code */

/* must be accompanied by the FIRST BSD license file in the root directory of */

/* the project. */

/----------------------------------------------------------------------------/

package frc.robot.Sensors;

import edu.wpi.first.networktables.NetworkTable;

import edu.wpi.first.networktables.NetworkTableInstance;

/**

  • Add your docs here.

*/

public class Limelight implements INetworkTablesTrackingCamera {

private final NetworkTable table;

public Limelight() {

table = NetworkTableInstance.getDefault().getTable("limelight");

}

public double getX() {

return table.getEntry("tx").getDouble(0);

}

public double getY() {

return table.getEntry("ty").getDouble(0);

}

public boolean isValid() {

return table.getEntry("tv").getDouble(0) == 1;

}

public void setDriverMode(boolean driverMode) {

if (driverMode) {

  table.getEntry("camMode").setDouble(1.0);

} else {

  table.getEntry("camMode").setDouble(0.0);

}

}

public void setPipeline(int pipeline) {

table.getEntry("pipeline").setDouble(pipeline);

}

}

So I do not use Java, however I have used the limelight with robotpy, a python implementation.

Basically, you want to receive values such as tx, ty, and manipulate them and provide them access to the mechanisms. If you are using a commandbased build, I’d recommend creating a subsystem or mechanism for the limelight, and then referencing it when needed, whether it’s in a drivetrain, turret, shooter, or some other mechanism.

When you get these values from the limelight subsystem, it is important to remember that these values are built around the calibration. So in this game, calibrating the limelight from somewhere such as the initiation line might be useful, as you know specific distances and heights. The rest comes down to trigonometry, and calculating the angle, or difference, and combining that with the current offset to get your total.

So with these, I would recommend returning these values, and simply applying the error to a function that allows you to set a rotation or shift solely based off of these values, that way as it gets closer and closer to the target, it naturally slows down, and from there you add a “dead zone”

If you are interested in distance calculations, please let me know. Hope this helps to some extent!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.