1
1
package frc .robot .vision ;
2
2
3
3
import edu .wpi .first .math .geometry .Pose2d ;
4
+ import frc .robot .vision .LimelightHelpers .LimelightResults ;
4
5
import frc .robot .vision .interpolation .InterpolatedVision ;
5
6
import java .util .Optional ;
6
7
8
+ import dev .doglog .DogLog ;
9
+
7
10
public class Limelight {
8
11
private Optional <VisionResult > rawVisionResult ;
9
12
private Optional <VisionResult > processedVisionResult ;
10
- public String limeLightName = "" ;
11
-
12
- public Optional <VisionResult > getRawVisionResult () {
13
- var estimatePose = LimelightHelpers .getBotPoseEstimate_wpiBlue_MegaTag2 (limeLightName );
13
+ private final String limelightTableName ;
14
+ private final String name ;
14
15
15
- if (estimatePose == null ) {
16
- return Optional .empty ();
17
- }
16
+ public Limelight (String name ) {
17
+ limelightTableName = "limelight-" + name ;
18
+ this .name = name ;
19
+ }
18
20
19
- if (estimatePose .tagCount == 0 ) {
20
- return Optional .empty ();
21
- }
21
+ public Optional <VisionResult > getInterpolatedVisionResult () {
22
+ var rawResult = getRawVisionResult ();
22
23
23
- // This prevents pose estimator from having crazy poses if the Limelight loses power
24
- if (estimatePose .pose .getX () == 0.0 && estimatePose .pose .getY () == 0.0 ) {
24
+ if (rawResult .isEmpty ()) {
25
25
return Optional .empty ();
26
26
}
27
-
28
- return Optional .of (new VisionResult (estimatePose .pose , estimatePose .timestampSeconds ));
27
+
28
+ Pose2d interpolatedPose = InterpolatedVision .interpolatePose (rawResult .get ().pose ());
29
+ return Optional .of (new VisionResult (interpolatedPose , rawResult .get ().timestamp ()));
29
30
}
30
31
31
- public Optional <VisionResult > getInterpolatedVisionResult () {
32
- var estimatePose = LimelightHelpers .getBotPoseEstimate_wpiBlue_MegaTag2 (limeLightName );
32
+ private Optional <VisionResult > getRawVisionResult () {
33
+ var estimatePose = LimelightHelpers .getBotPoseEstimate_wpiBlue_MegaTag2 (limelightTableName );
33
34
34
35
if (estimatePose == null ) {
35
36
return Optional .empty ();
36
37
}
37
38
39
+ DogLog .log ("Vision/" + name + "/RawLimelightPose" , estimatePose .pose );
40
+
38
41
if (estimatePose .tagCount == 0 ) {
39
42
return Optional .empty ();
40
43
}
@@ -43,7 +46,7 @@ public Optional<VisionResult> getInterpolatedVisionResult() {
43
46
if (estimatePose .pose .getX () == 0.0 && estimatePose .pose .getY () == 0.0 ) {
44
47
return Optional .empty ();
45
48
}
46
- Pose2d interpolatedPose = InterpolatedVision . interpolatePose ( estimatePose . pose );
47
- return Optional .of (new VisionResult (interpolatedPose , estimatePose .timestampSeconds ));
49
+
50
+ return Optional .of (new VisionResult (estimatePose . pose , estimatePose .timestampSeconds ));
48
51
}
49
52
}
0 commit comments