Skip to content

Commit 1a33cff

Browse files
authored
Remove deprecated APIs in Limelight code (#115)
Also fix problems found via IntelliJ IDEA Inspection Results.
1 parent cb923f0 commit 1a33cff

10 files changed

Lines changed: 54 additions & 254 deletions

File tree

limelight/src/main/java/com/team2813/lib2813/limelight/AprilTagMapPoseHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2025 Prospect Robotics SWENext Club
2+
Copyright 2025-2026 Prospect Robotics SWENext Club
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public List<Pose3d> getVisibleTagPoses(Set<Integer> ids) {
6969
return List.of();
7070
}
7171
return retriever.getFiducialMap().values().stream()
72-
.filter(fidicual -> ids.contains(fidicual.getId()))
72+
.filter(fiducial -> ids.contains(fiducial.getId()))
7373
.map(Fiducial::getPosition)
7474
.toList();
7575
}

limelight/src/main/java/com/team2813/lib2813/limelight/BotPoseEstimate.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2025 Prospect Robotics SWENext Club
2+
Copyright 2025-2026 Prospect Robotics SWENext Club
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -25,10 +25,5 @@
2525
* @param timestampSeconds The timestamp, in seconds, using the drivetrain clock
2626
* @param visibleAprilTags All April Tags that are visible from the vision source.
2727
*/
28-
public record BotPoseEstimate(Pose2d pose, double timestampSeconds, Set<Integer> visibleAprilTags) {
29-
30-
@Deprecated
31-
public BotPoseEstimate(Pose2d pose, double timestampSeconds) {
32-
this(pose, timestampSeconds, Set.of());
33-
}
34-
}
28+
public record BotPoseEstimate(
29+
Pose2d pose, double timestampSeconds, Set<Integer> visibleAprilTags) {}

limelight/src/main/java/com/team2813/lib2813/limelight/DataCollection.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024-2025 Prospect Robotics SWENext Club
2+
Copyright 2024-2026 Prospect Robotics SWENext Club
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -60,9 +60,7 @@ public BodySubscriber<Result> apply(ResponseInfo responseInfo) {
6060

6161
return BodySubscribers.mapping(
6262
BodyHandlers.ofString(Charset.defaultCharset()).apply(responseInfo),
63-
body -> {
64-
return new Result(new JSONObject(body), responseTimestamp);
65-
});
63+
body -> new Result(new JSONObject(body), responseTimestamp));
6664
}
6765
}
6866

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024-2025 Prospect Robotics SWENext Club
2+
Copyright 2024-2026 Prospect Robotics SWENext Club
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -15,14 +15,11 @@
1515
*/
1616
package com.team2813.lib2813.limelight;
1717

18-
import edu.wpi.first.math.geometry.Pose3d;
1918
import edu.wpi.first.wpilibj.Filesystem;
20-
import java.io.*;
21-
import java.util.List;
22-
import java.util.Optional;
23-
import java.util.OptionalDouble;
24-
import java.util.Set;
25-
import org.json.JSONObject;
19+
import java.io.File;
20+
import java.io.FileInputStream;
21+
import java.io.IOException;
22+
import java.io.InputStream;
2623

2724
public interface Limelight {
2825

@@ -35,20 +32,6 @@ static Limelight getDefaultLimelight() {
3532
return RestLimelight.getDefaultLimelight();
3633
}
3734

38-
/**
39-
* @deprecated use methods in {@link LocationalData} that return a {@link BotPoseEstimate}.
40-
*/
41-
@Deprecated
42-
OptionalDouble getTimestamp();
43-
44-
/**
45-
* Returns {@code true} if the limelight has identified a target.
46-
*
47-
* @deprecated use {@link LocationalData#hasTarget()}
48-
*/
49-
@Deprecated
50-
boolean hasTarget();
51-
5235
/** Gets an object for getting locational data. */
5336
LocationalData getLocationalData();
5437

@@ -59,7 +42,7 @@ static Limelight getDefaultLimelight() {
5942
* may also upload the field map to the Limelight if desired. This will likely be a slow
6043
* operation, and should not be regularly called.
6144
*
62-
* @param filepath The path to the file from the deploy directory (using UNIX file seperators)
45+
* @param filepath The path to the file from the deploy directory (using UNIX file separators)
6346
* @param updateLimelight If the limelight should be updated with this field map
6447
* @throws IOException If the given filepath does not exist in the deploy directory or could not
6548
* be read
@@ -70,26 +53,4 @@ default void setFieldMap(String filepath, boolean updateLimelight) throws IOExce
7053
setFieldMap(stream, updateLimelight);
7154
}
7255
}
73-
74-
/**
75-
* Gets the locations of the given AprilTags.
76-
*
77-
* @deprecated use {@link LocationalData#getVisibleAprilTagPoses()}
78-
*/
79-
@Deprecated
80-
List<Pose3d> getLocatedAprilTags(Set<Integer> visibleTags);
81-
82-
/**
83-
* @deprecated use {@link LocationalData#getCaptureLatency()}
84-
*/
85-
@Deprecated
86-
OptionalDouble getCaptureLatency();
87-
88-
/**
89-
* Gets the most recent JSON from the Limelight. Does not work for all implementations.
90-
*
91-
* @deprecated use {@link LocationalData#isValid()}.
92-
*/
93-
@Deprecated
94-
Optional<JSONObject> getJsonDump();
9556
}

limelight/src/main/java/com/team2813/lib2813/limelight/LimelightHelpers.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2025 Prospect Robotics SWENext Club
2+
Copyright 2025-2026 Prospect Robotics SWENext Club
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -919,16 +919,10 @@ public static String[] getLimelightNTStringArray(String tableName, String entryN
919919
return getLimelightNTTableEntry(tableName, entryName).getStringArray(new String[0]);
920920
}
921921

922-
public static URL getLimelightURLString(String tableName, String request) {
922+
public static URL getLimelightURLString(String tableName, String request)
923+
throws MalformedURLException {
923924
String urlString = "http://" + sanitizeName(tableName) + ".local:5807/" + request;
924-
URL url;
925-
try {
926-
url = new URL(urlString);
927-
return url;
928-
} catch (MalformedURLException e) {
929-
System.err.println("bad LL URL");
930-
}
931-
return null;
925+
return new URL(urlString);
932926
}
933927

934928
/////
@@ -1658,8 +1652,8 @@ public static CompletableFuture<Boolean> takeSnapshot(String tableName, String s
16581652
}
16591653

16601654
private static boolean SYNCH_TAKESNAPSHOT(String tableName, String snapshotName) {
1661-
URL url = getLimelightURLString(tableName, "capturesnapshot");
16621655
try {
1656+
URL url = getLimelightURLString(tableName, "capturesnapshot");
16631657
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
16641658
connection.setRequestMethod("GET");
16651659
if (snapshotName != null && !snapshotName.isEmpty()) {
@@ -1672,6 +1666,8 @@ private static boolean SYNCH_TAKESNAPSHOT(String tableName, String snapshotName)
16721666
} else {
16731667
System.err.println("Bad LL Request");
16741668
}
1669+
} catch (MalformedURLException e) {
1670+
System.err.println("bad Limelight URL: " + e.getMessage());
16751671
} catch (IOException e) {
16761672
System.err.println(e.getMessage());
16771673
}

limelight/src/main/java/com/team2813/lib2813/limelight/LocationalData.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024-2025 Prospect Robotics SWENext Club
2+
Copyright 2024-2026 Prospect Robotics SWENext Club
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.util.Map;
2020
import java.util.Optional;
2121
import java.util.OptionalDouble;
22-
import java.util.Set;
2322

2423
/**
2524
* Get positional data from limelight
@@ -69,47 +68,16 @@ public interface LocationalData {
6968
*
7069
* <p>Per the Limelight docs, this is the time between the end of the exposure of the middle row
7170
* to the beginning of the tracking loop.
72-
*
73-
* @deprecated Use {@link #getBotPoseEstimateBlue()} or {@link #getBotPoseEstimateRed()}
7471
*/
75-
@Deprecated
7672
OptionalDouble getCaptureLatency();
7773

7874
/**
7975
* Targeting latency in milliseconds.
8076
*
8177
* <p>Per the Limelight docs, this is the time consumed by the tracking loop this frame.
82-
*
83-
* @deprecated Use {@link #getBotPoseEstimateBlue()} or {@link #getBotPoseEstimateRed()}
8478
*/
85-
@Deprecated
8679
OptionalDouble getTargetingLatency();
8780

88-
/**
89-
* @deprecated use methods that return a {@link BotPoseEstimate}.
90-
*/
91-
@Deprecated
92-
OptionalDouble getTimestamp();
93-
94-
@Deprecated
95-
default OptionalDouble lastMSDelay() {
96-
OptionalDouble a = getCaptureLatency();
97-
OptionalDouble b = getTargetingLatency();
98-
if (a.isPresent() && b.isPresent()) {
99-
return OptionalDouble.of(a.getAsDouble() + b.getAsDouble());
100-
}
101-
return OptionalDouble.empty();
102-
}
103-
104-
/**
105-
* Gets the set of all visible tags
106-
*
107-
* @return The visible tags
108-
* @deprecated use {@link #getVisibleAprilTagPoses()}
109-
*/
110-
@Deprecated
111-
Set<Integer> getVisibleTags();
112-
11381
/** Gets the visible AprilTags as a map from ID to position. */
11482
Map<Integer, Pose3d> getVisibleAprilTagPoses();
11583
}

limelight/src/main/java/com/team2813/lib2813/limelight/NetworkTablesLimelight.java

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2025 Prospect Robotics SWENext Club
2+
Copyright 2025-2026 Prospect Robotics SWENext Club
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -23,12 +23,12 @@
2323
import edu.wpi.first.math.geometry.Pose3d;
2424
import java.io.IOException;
2525
import java.io.InputStream;
26-
import java.util.*;
2726
import java.util.Arrays;
27+
import java.util.HashMap;
28+
import java.util.Map;
2829
import java.util.Optional;
2930
import java.util.OptionalDouble;
30-
import java.util.stream.Collectors;
31-
import org.json.JSONObject;
31+
import java.util.Set;
3232

3333
class NetworkTablesLimelight implements Limelight {
3434
private static final double[] ZEROS = new double[6];
@@ -40,38 +40,13 @@ class NetworkTablesLimelight implements Limelight {
4040
aprilTagMapPoseHelper = new AprilTagMapPoseHelper(new LimelightClient(limelightName));
4141
}
4242

43-
@Override
44-
public OptionalDouble getTimestamp() {
45-
return getLocationalData().getTimestamp();
46-
}
47-
48-
@Override
49-
public boolean hasTarget() {
50-
return getLocationalData().hasTarget();
51-
}
52-
5343
@Override
5444
public void setFieldMap(InputStream stream, boolean updateLimelight) throws IOException {
5545
// The updateLimelight assumes we have the hostname of the limelight, which we don't. For now,
5646
// this won't update the limelight.
5747
aprilTagMapPoseHelper.setFieldMap(stream, false);
5848
}
5949

60-
@Override
61-
public List<Pose3d> getLocatedAprilTags(Set<Integer> visibleTags) {
62-
return aprilTagMapPoseHelper.getVisibleTagPoses(visibleTags);
63-
}
64-
65-
@Override
66-
public Optional<JSONObject> getJsonDump() {
67-
return Optional.empty();
68-
}
69-
70-
@Override
71-
public OptionalDouble getCaptureLatency() {
72-
return getLocationalData().getCaptureLatency();
73-
}
74-
7550
@Override
7651
public LocationalData getLocationalData() {
7752
LimelightHelpers.LimelightResults results = LimelightHelpers.getLatestResults(limelightName);
@@ -109,7 +84,7 @@ private Map<Integer, Pose3d> getVisibleAprilTagPoses(LimelightResults results) {
10984
return unmodifiableMap(map);
11085
}
11186

112-
private class NTLocationalData implements LocationalData {
87+
private static class NTLocationalData implements LocationalData {
11388
private final LimelightResults results;
11489
private final Optional<BotPoseEstimate> poseEstimate;
11590
private final Optional<BotPoseEstimate> redPoseEstimate;
@@ -179,18 +154,6 @@ public OptionalDouble getTargetingLatency() {
179154
return OptionalDouble.of(results.latency_pipeline);
180155
}
181156

182-
@Override
183-
public OptionalDouble getTimestamp() {
184-
return OptionalDouble.of(results.timestamp_LIMELIGHT_publish);
185-
}
186-
187-
@Override
188-
public Set<Integer> getVisibleTags() {
189-
return Arrays.stream(results.targets_Fiducials)
190-
.map(fiducial -> (int) fiducial.fiducialID)
191-
.collect(Collectors.toUnmodifiableSet());
192-
}
193-
194157
@Override
195158
public Map<Integer, Pose3d> getVisibleAprilTagPoses() {
196159
return aprilTags;

0 commit comments

Comments
 (0)