With limelightlib, how do I get the timestamp of the vision measurement (ts from the json file)? Also, is it in nano seconds or milliseconds.
Also also, is there a way to get the distance between the limelight and the closest april tag it sees?
I can at least answer a few of your questions, maybe not all of them so bear with me here.
First: how to get a video timestamp
I don’t know, but I’d recommend looking through CTRE’s docs and their API to see if you can find anything about. However, what are you needing the timestamp for? If limelight doesn’t have a way to do this, I’m pretty sure there’s a way you can get the match time from the FMS. I would also say it’s a safe bet to assume any response would either be in seconds or miliseconds, since nanoseconds are 1 billionth of a second and the RoboRIO’s scheduler cycle is 20ms.
Second: Calculating distance to an AprilTag:
Yes, that is entirely possible and actually pretty easy. Now, I don’t have as much knowledge on the LimelightLib because I use PhotonVision, but you should once again check the Limelight docs/API to see if there’s a “get distance to target” method you could call. If you can’t find something that returns the distance, it won’t be all that difficult to get an approximation with some quick math.
To get the latency we do this
lResults = LimelightResults.getLatestResults();
double latency = lResults.targetingResults.latency_capture + lResults.targetingResults.latency_pipeline + lResults.targetingResults.latency_jsonParse;
For the distance, you get the target pose in the robot space of the first April tag and get the norm.
The norm in this context is basically just finding the hypotenuse of a triangle with legs target_x and target_y to get the distance from the robot to the target.
Pose2d targetPose = lResults.targetingResults.targets_Fiducials.getTargetPose_RobotSpace2D();
double distance = targetPose.getTranslation().getNorm();
It’s not a CTRE API it’s a copied and pasted java source file. Before replying please know what you’re talking about this is just potentially confusing and misguiding.
Yes I am talking about that. It isn’t working that well for me right now. Do you have any idea why this is happening? I copied and pasted it into our robot folder.
Oh you just need to change
So instead of
int numAprilTags = limelighthResults.results.targets_Fiducials.length;
int numAprilTags = limelighthResults.targetingResults.targets_Fiducials.length;