It looks pretty good - you are right that you seem to have essentially everything you need - now to put it into the right place and order.
If you already have some periodic code (I don’t have your complete robot code) you could put the LL data acquisition there, too. In the mean time put it in your robotPeriodic() {}
. I would call a new LL update method that contains at the least this code moved out of the class instantiation:
double x;
double y;
double area;
public void acquire() {
//converts data to java double datatypes
x = tx.getDouble(0.0);
y = ty.getDouble(0.0);
area = ta.getDouble(0.0);
}
Then call each of the other methods as you need to get
the values.
That seems to be the minimum to get you going but I’d tweak what you have a little.
First I’d check to make sure you have a new, valid set of data from LL with code similar to other LL data
double valid = tv.getDouble(Double.NaN);
then check for + or - 1.
.
Normally you would try to get all of your inputs as fast as possible at the beginning of the loop iteration and not do extra calculations until needed. Still, I see value in doing all your calculations early on since there aren’t many. That way all the information you need is calculated once at the right time and is always available anytime in the entire loop iteration. As it is now you have to make sure you run all of the calculation methods before the data is available for the SmartDashboard posting.
So I’d make a second method for all the calculations that you run immediately after all of your sensor inputs for the iteration. Then I suggest running telemetryUpdate()
at the end of the iteration. If you are plotting your data then the telemetryUpdate()
is fine but if it’s numbers for human consumption, displaying once every 50 or so iterations is adequate and much more efficient.
You could end up with something like this:
Limelight LL = new Limelight();
@Override
public void robotPeriodic()
{
LL.acquire();
LL.calculate();
CommandScheduler.getInstance().run();
LL.updateTelemetry();
}
If you want to display in AdvantageScope
You could take a look at THIS example but caution! The Robot class
is correct and works to view a USB camera and detect an AprilTag and compute the pose and display the pose (much more code than what you are going to use - my team probably will use the roboRIO for vision this 2025 season). The LL class
has NOT BEEN TESTED! I’ve been working on updating to better methods and do not have a LL at home and haven’t used the current LL helper. The code is similar to what you have, does validation, displays data (after debugging if that’s needed), and maybe there are better LL methods to use now than what I use.