Introducing Limelight Lib

Introducing Limelight Lib

Java
CPP

Limelight Lib is a single-file library that makes Limelight easier than ever. With one line of code, you can start using the full JSON output of Limelight to build more versatile software.

All you need to do is copy the file into your robot project.

You don’t need to instantiate any objects to interact with your Limelights. The library is meant to be used in a stateless/functional manner.

Java:

LimelightResults llresults = LimelightHelpers.getLatestResults("");
int numAprilTags = llresults.results.targets_Fiducials.length;

CPP:

LimelightHelpers::LimelightResultsClass llresults = LimelightHelpers::getLatestResults();
int numAprilTags = llresults.targetingResults.FiducialResults.size();

It also has helper functions for all networktables controls

Java

LimelightHelpers.setCropWindow("",-1,1,-1,1);
LimelightHelpers.setLEDMode_ForceBlink("")
double tx = LimelightHelpers.getTX("");
LimelightHelpers.takeSnapshot("","snapshotname");

CPP

LimelightHelpers::setCropWindow("",-1,1,-1,1);
LimelightHelpers::setLEDMode_ForceBlink("")
double tx = LimelightHelpers::getTX("");

Here are the current classes and methods. The naming is currently a bit different for the CPP library:

LimelightTarget_Retro
LimelightTarget_Fiducial
LimelightTarget_Barcode
LimelightTarget_Classifier
LimelightTarget_Detector
Results
LimelightResults
(Pure Static) LimelightHelpers
getLimelightNTTable()
getLimelightNTTableEntry()
getLimelightNTDouble()
setLimelightNTDouble()
setLimelightNTDoubleArray()
getLimelightNTDouleArray()
getLimelightNTString()
getLimelightURLString()

getTX()
getTY()
getTA()
getLatency_Pipeline()
getLatency_Capture()
getCurrentPipelineIndex()
getJsonDump()

getBotpose()
getBotpose_wpiRed()
getBotpose_wpiBlue()
getBotpose_TargetSpace()
getCameraPsoe_TargetSpace()
getTargetPose_CameraSpace()
getTargetPose_RobotSpace()

getTargetColor()
getFiducialID()
getNeuralClassID()

setPipelineIndex()

setLEDMode_PipelineControl()
setLEDMode_ForceOff()
setLEDMode_ForceBlink()
setLEDMode_ForceOn()

setStreamMode_Standard()
setStreamMode_PiPMain()
setStreamMode_PiPSecondary()

setCropWindow()

setPythonScriptData()
getPythonScriptData()

takeSnapshot()
getLatestResults()

Code reviews, PRs, and feature requests are welcome.

29 Likes

This is super sweet! Thanks!

Let’s go Brandon!

23 Likes

How long you been saving that one?

31 Likes

Good stuff, should be helpful for teams! Some minor nitpicks:

limelightlib-wpijava/LimelightHelpers.java at main · LimelightVision/limelightlib-wpijava (github.com)

IMO this should just return a Pose3d (or whatever WPILib equivalent) rather than a double array, currently requires extra work from the user which shouldn’t be necessary.

limelightlib-wpijava/LimelightHelpers.java at main · LimelightVision/limelightlib-wpijava (github.com)
More docs should be added on this. I don’t know what a CompleteableFuture is and I expect most HS student’s won’t either.

limelightlib-wpijava/LimelightHelpers.java at main · LimelightVision/limelightlib-wpijava (github.com)

Does this new latency calculation system make it so you should still be adding the 11ms or equivalent as recommended previously to account for the other sources of latency).

(message not affiliated with PV, just me as a person if it wasn’t already clear).

16 Likes

LimelightHelpers line 67 @JsonProperty should be “fID” not “fid”

2 Likes

More of a LimeLight suggestion but the ability to save all pipelines in a specific location and to reload them all at once would be really useful.

3 Likes

Futures are a standard part of asynchronous programming, IMO its pretty weird to see it in the FRC realm, but its a good skill to know.

1 Like

The limelight name string that each of the methods require is what? The pipeline name? or the actual camera name? such as “limelight”

1 Like

Seems great! I haven’t looked much, but is there a way to switch the camera zoom level during runtime?
Thanks

Switch pipeline

2 Likes

It appears that this code uses an HTTP-based interface running on port 5807. Is this interface documented and supported?

1 Like

By any chance, does this answer your question?

Building a Retroreflective/Color Pipeline — Limelight 1.0 documentation (limelightvision.io)

2 Likes

I don’t think so. I don’t see any mention of port 5807 there, HTTP GET URLs, etc.

@icemannie Implemented your fix, thanks. I like your idea.

@Gavo9649 The camera name (eg limelight, limelight-upper). Blank or null will automatically get sanitized to “limelight”

@rjbell4 REST/HTTP and Websocket APIs — Limelight 1.0 documentation - The REST Api should grow significantly over the course of the season

2 Likes

I was so tempted to give a down finger for this mostly in retaliation to “kids” who have given me that not understanding that I have been making computer systems work right for 65 years. :laughing: LOL, etc.

You forgot about the explanatory part

Futures and promises are a popular abstraction for asynchronous programming, especially in the context of distributed systems

and that FRC doesn’t have much call for distributed systems (IMO a RPi for vision doesn’t qualify although “simpler” concepts of syncing tasks are used for it).

I’m not really picking on you - you’re the future of computing and it’s amazing you have such depth already. Thanks for the insight about new stuff. I might not live long enough to use it in FRC but maybe I will if you push the boundaries for the rest of us to follow!

3 Likes

Yes, I was intentionally pretty vague because I enjoy when other people learn on there own, rather than being explicitly taught, as thats how Ive learned and I think its a better option, and sticks way better when they look it up on their own.

Thank you though, ideally yes, I intend to push not just my team but others (#openalliance) through all contributions; for instance working with graph theory in robot code, not that its entirely useful, but very cool. I have just tons of things in my head that hopefully I will get to publish and allow everyone to use, just these pesky teachers and their homework are a bit much atm.

2 Likes

Awesome, I learned something today. I definitely want to experiment with Futures now in robot code, possibly applied to autonomous routines or taking action following completion an mechanism positional change. Do you know if Future can be applied to any Runnable, or specifically to a FutureTask implementation of it?

2 Likes

Thankfully wpilib has done a pretty good job with Commands imo. If your really curious, I would look into CompletableFuture its probably what your looking for. Yes it should work with any runnable.

Lets try to keep this on topic though lol, if you have any questions, feel free to reach out to me.

2 Likes

Cool idea but not ready for primetime, at least on the Java side.

The biggest problem is that the JSON features can’t be used outside of frc.robot package because all of the types are package private. In practice, this means I can’t use any of the data in a command or subsystem.

I agree with @mdurrani834, methods shouldn’t return arrays of undocumented numbers, they should return named types. True/False values should be boolean (just add @JsonFormat(shape = Shape.NUMBER)) and WPILib classes should be used for WPI poses. Jackson custom deserializers can make this work.

On the same line of thinking, there shouldn’t be four variations of setLEDMode_X, and similar. These should be parameterized methods that accept an enum for the mode. This is common across other vendor libraries, like Rev and CTRE, so it would be familiar.

There’s no JavaDoc. It would be hugely helpful for the fields and methods to be documented.

Why isn’t this a vendor library? It looks like there have been a few commits since the initial announcement, but the comment at the top still says v1.0 February 3rd. How are you going to handle releases?

7 Likes

I might be misunderstanding how use this class but it looks like the LimelightResults that you highlighted is the only one that @Brandon_Hjelstrom forgot to make public and must be fixed to be of use (preferably by a new version today and not by my students having to patch their copy).