1919import frc .lib .Subsystem ;
2020import frc .lib .sendables .SwerveDriveSendable ;
2121import frc .lib .swerves .SwerveOutput ;
22+ import frc .robot .LimelightHelpers ;
23+
2224import java .util .function .Supplier ;
2325
2426public class Drive extends Subsystem {
@@ -42,6 +44,23 @@ public Drive(SwerveOutput swerve) {
4244 this .driverAssistance =
4345 new DriverAssistance (MetersPerSecond .per (Meter ).ofNative (8 ), Meters .of (1 ), Meters .of (2 ));
4446 this .targetSupplier = Pose2d ::new ;
47+
48+ LimelightHelpers .setCameraPose_RobotSpace (
49+ "limelight-east" ,
50+ 0.2715768 ,
51+ 0.0809498 ,
52+ 0.1539494 ,
53+ 5 ,
54+ 25 ,
55+ 30 );
56+ LimelightHelpers .setCameraPose_RobotSpace (
57+ "limelight-west" ,
58+ 0.2715768 ,
59+ -0.0812292 ,
60+ 0.1539494 ,
61+ 5 ,
62+ 25 ,
63+ -30 );
4564 }
4665
4766 @ Override
@@ -63,10 +82,33 @@ public void periodic() {
6382 field .setRobotPose (state .Pose );
6483 driverAssistance .drawDebugObjects (field , getPose (), getTargetPose ());
6584 SmartDashboard .putBoolean (
66- "Dead Spots?" , driverAssistance .hasDeadSpots (TunerConstants .kSpeedAt12Volts ));
85+ "Dead Spots?" , driverAssistance .hasDeadSpots (TunerConstants .kSpeedAt12Volts ));
6786
6887 // NOTE This was taken from the generated project, unsure if it is needed
6988 // trySettingPerspective();
89+
90+ LimelightHelpers .SetRobotOrientation (
91+ "limelight-east" ,
92+ state .Pose .getRotation ().getDegrees (),
93+ state .Speeds .omegaRadiansPerSecond *(180 /Math .PI ),
94+ 0 ,
95+ 0 ,
96+ 0 ,
97+ 0 );
98+ LimelightHelpers .SetRobotOrientation (
99+ "limelight-west" ,
100+ state .Pose .getRotation ().getDegrees (),
101+ state .Speeds .omegaRadiansPerSecond *(180 /Math .PI ),
102+ 0 ,
103+ 0 ,
104+ 0 ,
105+ 0 );
106+
107+ LimelightHelpers .PoseEstimate mt2EstimateEast = LimelightHelpers .getBotPoseEstimate_wpiBlue_MegaTag2 ("limelight-east" );
108+ LimelightHelpers .PoseEstimate mt2EstimateWest = LimelightHelpers .getBotPoseEstimate_wpiBlue_MegaTag2 ("limelight-west" );
109+
110+ swerve .addVisionMeasurement (mt2EstimateEast .pose , mt2EstimateEast .timestampSeconds );
111+ swerve .addVisionMeasurement (mt2EstimateWest .pose , mt2EstimateWest .timestampSeconds );
70112 }
71113
72114 private void trySettingPerspective () {
@@ -163,4 +205,12 @@ public Command driveToTarget(Supplier<ChassisSpeeds> fieldSpeeds) {
163205 () -> driverAssistance .applyDriverAssistance (fieldSpeeds .get (), getPose (), getTargetPose ()),
164206 () -> getTargetPose ().getRotation ());
165207 }
208+
209+ public Command trustMegatag1Estimate (String limelightName ) {
210+ return runOnce (
211+ () -> {
212+ LimelightHelpers .PoseEstimate mt1Estimate = LimelightHelpers .getBotPoseEstimate_wpiBlue (limelightName );
213+ swerve .resetPose (mt1Estimate .pose );
214+ });
215+ }
166216}
0 commit comments