3636import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
3737import edu .wpi .first .wpilibj2 .command .sysid .SysIdRoutine .Config ;
3838import frc .robot .Constants ;
39- import frc .robot .subsystems .swervedrive .Vision .Cameras ;
39+ // import frc.robot.subsystems.swervedrive.Vision.Cameras;
4040import java .io .File ;
4141import java .io .IOException ;
4242import java .util .Arrays ;
4545import java .util .function .DoubleSupplier ;
4646import java .util .function .Supplier ;
4747import org .json .simple .parser .ParseException ;
48- import org .photonvision .targeting .PhotonPipelineResult ;
48+ // import org.photonvision.targeting.PhotonPipelineResult;
4949import swervelib .SwerveController ;
5050import swervelib .SwerveDrive ;
5151import swervelib .SwerveDriveTest ;
@@ -74,7 +74,7 @@ public class SwerveSubsystem extends SubsystemBase
7474 /**
7575 * PhotonVision class to keep an accurate odometry.
7676 */
77- private Vision vision ;
77+ // private Vision vision;
7878
7979 /**
8080 * Initialize {@link SwerveDrive} with the directory provided.
@@ -83,20 +83,6 @@ public class SwerveSubsystem extends SubsystemBase
8383 */
8484 public SwerveSubsystem (File directory )
8585 {
86- // Angle conversion factor is 360 / (GEAR RATIO * ENCODER RESOLUTION)
87- // In this case the gear ratio is 12.8 motor revolutions per wheel rotation.
88- // The encoder resolution per motor revolution is 1 per motor revolution.
89- double angleConversionFactor = SwerveMath .calculateDegreesPerSteeringRotation (12.8 );
90- // Motor conversion factor is (PI * WHEEL DIAMETER IN METERS) / (GEAR RATIO * ENCODER RESOLUTION).
91- // In this case the wheel diameter is 4 inches, which must be converted to meters to get meters/second.
92- // The gear ratio is 6.75 motor revolutions per wheel rotation.
93- // The encoder resolution per motor revolution is 1 per motor revolution.
94- double driveConversionFactor = SwerveMath .calculateMetersPerRotation (Units .inchesToMeters (4 ), 6.75 );
95- System .out .println ("\" conversionFactors\" : {" );
96- System .out .println ("\t \" angle\" : {\" factor\" : " + angleConversionFactor + " }," );
97- System .out .println ("\t \" drive\" : {\" factor\" : " + driveConversionFactor + " }" );
98- System .out .println ("}" );
99-
10086 // Configure the Telemetry before creating the SwerveDrive to avoid unnecessary objects being created.
10187 SwerveDriveTelemetry .verbosity = TelemetryVerbosity .HIGH ;
10288 try
@@ -118,10 +104,10 @@ public SwerveSubsystem(File directory)
118104 0.1 ); //Correct for skew that gets worse as angular velocity increases. Start with a coefficient of 0.1.
119105 swerveDrive .setModuleEncoderAutoSynchronize (false ,
120106 1 ); // Enable if you want to resynchronize your absolute encoders and motor encoders periodically when they are not moving.
121- swerveDrive .pushOffsetsToEncoders (); // Set the absolute encoder to be used over the internal encoder and push the offsets onto it. Throws warning if not possible
107+ // swerveDrive.pushOffsetsToEncoders(); // Set the absolute encoder to be used over the internal encoder and push the offsets onto it. Throws warning if not possible
122108 if (visionDriveTest )
123109 {
124- setupPhotonVision ();
110+ // setupPhotonVision();
125111 // Stop the odometry thread if we are using vision that way we can synchronize updates better.
126112 swerveDrive .stopOdometryThread ();
127113 }
@@ -143,13 +129,13 @@ public SwerveSubsystem(SwerveDriveConfiguration driveCfg, SwerveControllerConfig
143129 Rotation2d .fromDegrees (0 )));
144130 }
145131
146- /**
147- * Setup the photon vision class.
148- */
149- public void setupPhotonVision ()
150- {
151- vision = new Vision (swerveDrive ::getPose , swerveDrive .field );
152- }
132+ // /**
133+ // * Setup the photon vision class.
134+ // */
135+ // public void setupPhotonVision()
136+ // {
137+ // vision = new Vision(swerveDrive::getPose, swerveDrive.field);
138+ // }
153139
154140 @ Override
155141 public void periodic ()
@@ -158,7 +144,7 @@ public void periodic()
158144 if (visionDriveTest )
159145 {
160146 swerveDrive .updateOdometry ();
161- vision .updatePoseEstimation (swerveDrive );
147+ // vision.updatePoseEstimation(swerveDrive);
162148 }
163149 }
164150
@@ -238,75 +224,29 @@ public void setupPathPlanner()
238224 PathfindingCommand .warmupCommand ().schedule ();
239225 }
240226
241- /**
242- * Get the distance to the speaker.
243- *
244- * @return Distance to speaker in meters.
245- */
246- public double getDistanceToSpeaker ()
247- {
248- int allianceAprilTag = DriverStation .getAlliance ().get () == Alliance .Blue ? 7 : 4 ;
249- // Taken from PhotonUtils.getDistanceToPose
250- Pose3d speakerAprilTagPose = aprilTagFieldLayout .getTagPose (allianceAprilTag ).get ();
251- return getPose ().getTranslation ().getDistance (speakerAprilTagPose .toPose2d ().getTranslation ());
252- }
253-
254- /**
255- * Get the yaw to aim at the speaker.
256- *
257- * @return {@link Rotation2d} of which you need to achieve.
258- */
259- public Rotation2d getSpeakerYaw ()
260- {
261- int allianceAprilTag = DriverStation .getAlliance ().get () == Alliance .Blue ? 7 : 4 ;
262- // Taken from PhotonUtils.getYawToPose()
263- Pose3d speakerAprilTagPose = aprilTagFieldLayout .getTagPose (allianceAprilTag ).get ();
264- Translation2d relativeTrl = speakerAprilTagPose .toPose2d ().relativeTo (getPose ()).getTranslation ();
265- return new Rotation2d (relativeTrl .getX (), relativeTrl .getY ()).plus (swerveDrive .getOdometryHeading ());
266- }
267-
268- /**
269- * Aim the robot at the speaker.
270- *
271- * @param tolerance Tolerance in degrees.
272- * @return Command to turn the robot to the speaker.
273- */
274- public Command aimAtSpeaker (double tolerance )
275- {
276- SwerveController controller = swerveDrive .getSwerveController ();
277- return run (
278- () -> {
279- ChassisSpeeds speeds = ChassisSpeeds .fromFieldRelativeSpeeds (0 , 0 ,
280- controller .headingCalculate (getHeading ().getRadians (),
281- getSpeakerYaw ().getRadians ()),
282- getHeading ());
283- drive (speeds );
284- }).until (() -> Math .abs (getSpeakerYaw ().minus (getHeading ()).getDegrees ()) < tolerance );
285- }
286-
287- /**
288- * Aim the robot at the target returned by PhotonVision.
289- *
290- * @return A {@link Command} which will run the alignment.
291- */
292- public Command aimAtTarget (Cameras camera )
293- {
294-
295- return run (() -> {
296- Optional <PhotonPipelineResult > resultO = camera .getBestResult ();
297- if (resultO .isPresent ())
298- {
299- var result = resultO .get ();
300- if (result .hasTargets ())
301- {
302- drive (getTargetSpeeds (0 ,
303- 0 ,
304- Rotation2d .fromDegrees (result .getBestTarget ()
305- .getYaw ()))); // Not sure if this will work, more math may be required.
306- }
307- }
308- });
309- }
227+ // /**
228+ // * Aim the robot at the target returned by PhotonVision.
229+ // *
230+ // * @return A {@link Command} which will run the alignment.
231+ // */
232+ // public Command aimAtTarget(Cameras camera)
233+ // {
234+ //
235+ // return run(() -> {
236+ // Optional<PhotonPipelineResult> resultO = camera.getBestResult();
237+ // if (resultO.isPresent())
238+ // {
239+ // var result = resultO.get();
240+ // if (result.hasTargets())
241+ // {
242+ // drive(getTargetSpeeds(0,
243+ // 0,
244+ // Rotation2d.fromDegrees(result.getBestTarget()
245+ // .getYaw()))); // Not sure if this will work, more math may be required.
246+ // }
247+ // }
248+ // });
249+ // }
310250
311251 /**
312252 * Get the path follower with events.
0 commit comments