14
14
import edu .wpi .first .wpilibj2 .command .Command ;
15
15
import edu .wpi .first .wpilibj2 .command .Commands ;
16
16
import frc .lib .AllianceFlipHelper ;
17
- import frc .lib .LimelightHelpers ;
18
17
import frc .lib .Subsystem ;
19
18
import frc .lib .Telemetry ;
20
19
import frc .robot .odometry .GyroscopeIO .GyroscopeIOValues ;
@@ -51,6 +50,8 @@ public class Odometry extends Subsystem {
51
50
/** List of functions to be called when pose is manually updated. */
52
51
private final List <Consumer <Rotation2d >> yawUpdateConsumers ;
53
52
53
+ private final Limelight limelight ;
54
+
54
55
/** Creates a new instance of the odometry subsystem. */
55
56
private Odometry () {
56
57
gyroscope = OdometryFactory .createGyroscope (this );
@@ -72,12 +73,15 @@ private Odometry() {
72
73
initialGyroRotation ,
73
74
swerveModulePositionsSupplier .get (),
74
75
initialPose );
76
+ swervePoseEstimator .setVisionMeasurementStdDevs (VecBuilder .fill (.7 ,.7 ,9999999 ));
75
77
76
78
field = new Field2d ();
77
79
78
80
yawUpdateConsumers = new ArrayList <Consumer <Rotation2d >>();
79
81
80
- LimelightHelpers .SetFiducialIDFiltersOverride (OdometryConstants .LIMELIGHT_NAME , OdometryConstants .VALID_TAGS );
82
+ limelight = new Limelight ("limelight" );
83
+
84
+ limelight .setTagFilter (OdometryConstants .VALID_TAGS );
81
85
}
82
86
83
87
/**
@@ -97,19 +101,18 @@ public static Odometry getInstance() {
97
101
public void periodic () {
98
102
gyroscope .update (gyroscopeValues );
99
103
100
- LimelightHelpers .SetRobotOrientation (OdometryConstants .LIMELIGHT_NAME , getFieldRelativeHeading ().getDegrees (), 0 , 0 , 0 , 0 , 0 );
101
-
102
- LimelightHelpers .PoseEstimate megaTag2 = LimelightHelpers .getBotPoseEstimate_wpiBlue_MegaTag2 (OdometryConstants .LIMELIGHT_NAME );
104
+ limelight .setYaw (getFieldRelativeHeading ());
103
105
104
- final boolean spinningFast = Math .abs (gyroscopeValues .yawVelocityRotations ) > 1.0 ;
106
+ final boolean stationary = Math .abs (gyroscopeValues .yawVelocityRotations ) > 1.0 ;
105
107
106
- final boolean hasTag = megaTag2 .tagCount != 0 ;
108
+ if (stationary ) {
109
+ var pe = limelight .getPoseEstimate ();
107
110
108
- if ( hasTag && ! spinningFast ) {
109
- swervePoseEstimator .setVisionMeasurementStdDevs ( VecBuilder . fill ( .7 , .7 , 9999999 ));
110
- swervePoseEstimator . addVisionMeasurement (
111
- megaTag2 . pose ,
112
- megaTag2 . timestampSeconds );
111
+ if ( pe . isPresent () ) {
112
+ swervePoseEstimator .addVisionMeasurement (
113
+ pe . get (). pose ,
114
+ pe . get (). timestampSeconds );
115
+ }
113
116
}
114
117
115
118
swervePoseEstimator .update (
0 commit comments