Package frc.robot.subsystems.vision
Class Vision
java.lang.Object
frc.robot.subsystems.vision.Vision
- All Implemented Interfaces:
Subsystem
Vision subsystem that manages three Limelights (back, left, right) and fuses their pose estimates
into the swerve odometry via WPILib's
SwerveDrivePoseEstimator.
Each robot loop iteration the subsystem:
- Pushes the robot's current heading to all Limelights so MegaTag2 IMU fusion remains accurate.
- Selects the Limelight with the best view (
getBestLimelight()). - Runs the MT1 (and, while disabled, MT2) rejection pipeline and adds accepted estimates to the pose estimator with appropriate std-dev vectors.
- Logs per-camera status and pose data via
VisionLogger.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStatic configuration for the Vision subsystem, including Limelight identifiers, camera-to-robot transforms, pipeline indices, and pose estimation covariance parameters.classImmutable data class that bundles a vision-derived field pose with its FPGA timestamp and covariance matrix, ready for use withSwerveDrivePoseEstimator.addVisionMeasurement(). -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a command that blinks all Limelight LEDs while active and turns them off when the command ends.Rear-facing Limelight instance.Returns the MegaTag1 (MT1) pose from the back Limelight, orPose2d.kZeroif no estimate is available.Returns the MegaTag2 (MT2) pose from the back Limelight, orPose2d.kZeroif no estimate is available.Selects and returns the Limelight with the highest combined score of visible tag count and target size.Left-facing Limelight instance.Returns the MegaTag1 (MT1) pose from the left Limelight, orPose2d.kZeroif no estimate is available.Returns the MegaTag2 (MT2) pose from the left Limelight, orPose2d.kZeroif no estimate is available.getName()Right-facing Limelight instance.Returns the MegaTag1 (MT1) pose from the right Limelight, orPose2d.kZeroif no estimate is available.Returns the MegaTag2 (MT2) pose from the right Limelight, orPose2d.kZeroif no estimate is available.static AprilTagFieldLayoutField layout loaded once at construction and shared across the robot.booleanReturnstrueif at least one Limelight reports an accurate pose (viaLimelight.hasAccuratePose()).voidLogs connection status, integration status, tag status, MT1 poses, tag count, and target size for each Limelight via theirVisionLogger.voidperiodic()Called every robot loop iteration by the WPILib scheduler.voidResets the robot pose to the best Limelight's vision pose.booleanresetPoseToVision(boolean targetInView, Pose3d botpose3D, Pose2d megaPose, double poseTimestamp) Resets the robot pose to a specific vision pose if the data passes sanity checks.voidsetLimelightPipelines(int pipeline) Sets all Limelights to the given pipeline index.Returns a command that holds all Limelight LEDs solid-on while active and turns them off when the command ends.booleanReturnstrueif any Limelight currently sees an AprilTag belonging to the current alliance's set of scoring targets.voidTriggers a rewind-capture snapshot on all Limelights (captures 165 seconds of history for post-match review).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Field Details
-
backLL
Rear-facing Limelight instance. -
leftLL
Left-facing Limelight instance. -
rightLL
Right-facing Limelight instance. -
allLimelights
All three Limelights in one array for bulk operations.
-
-
Constructor Details
-
Vision
Creates the Vision subsystem.Instantiates all three Limelights, registers their loggers, applies initial camera settings (LEDs off, IMU mode 1), loads the AprilTag field layout, and registers this subsystem with the WPILib scheduler.
- Parameters:
config- the static configuration object
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceSubsystem- Returns:
- the subsystem name defined in
Vision.VisionConfig.
-
periodic
public void periodic()Called every robot loop iteration by the WPILib scheduler.- Pushes current heading to all Limelights (required for MegaTag2).
- Runs pose-estimation updates appropriate to the current robot mode.
- Logs telemetry for all cameras.
-
logTelemetry
public void logTelemetry()Logs connection status, integration status, tag status, MT1 poses, tag count, and target size for each Limelight via theirVisionLogger. MT2 poses are only logged while disabled (they are unreliable when moving). Also updates theField2dwidget with the MT1 pose from each camera. -
getBackMegaTag1Pose
Returns the MegaTag1 (MT1) pose from the back Limelight, orPose2d.kZeroif no estimate is available. -
getLeftMegaTag1Pose
Returns the MegaTag1 (MT1) pose from the left Limelight, orPose2d.kZeroif no estimate is available. -
getRightMegaTag1Pose
Returns the MegaTag1 (MT1) pose from the right Limelight, orPose2d.kZeroif no estimate is available. -
getBackMegaTag2Pose
Returns the MegaTag2 (MT2) pose from the back Limelight, orPose2d.kZeroif no estimate is available. -
getLeftMegaTag2Pose
Returns the MegaTag2 (MT2) pose from the left Limelight, orPose2d.kZeroif no estimate is available. -
getRightMegaTag2Pose
Returns the MegaTag2 (MT2) pose from the right Limelight, orPose2d.kZeroif no estimate is available. -
getBestLimelight
Selects and returns the Limelight with the highest combined score of visible tag count and target size. Ties fall back tobackLL.- Returns:
- the Limelight currently offering the best view of AprilTags
-
hasAccuratePose
public boolean hasAccuratePose()Returnstrueif at least one Limelight reports an accurate pose (viaLimelight.hasAccuratePose()). -
tagsInView
public boolean tagsInView()Returnstrueif any Limelight currently sees an AprilTag belonging to the current alliance's set of scoring targets.Uses
DriverStation.getAlliance()and falls back to Blue if the alliance is unknown. -
triggerRewindCaptureForAllCameras
public void triggerRewindCaptureForAllCameras()Triggers a rewind-capture snapshot on all Limelights (captures 165 seconds of history for post-match review). -
resetPoseToVision
public void resetPoseToVision()Resets the robot pose to the best Limelight's vision pose. Delegates toresetPoseToVision(boolean, Pose3d, Pose2d, double). -
resetPoseToVision
public boolean resetPoseToVision(boolean targetInView, Pose3d botpose3D, Pose2d megaPose, double poseTimestamp) Resets the robot pose to a specific vision pose if the data passes sanity checks.Uses a very tight covariance (
0.00001) so the pose estimator snaps immediately to the vision measurement. The MT1 heading is preserved while MT2 provides the translation.Rejection criteria:
- No target in view.
- Pose outside field boundary.
- Camera height
|z| > 0.25 m(robot floating / bad solve). - Roll or pitch > 5° (camera physically disturbed).
- Parameters:
targetInView- whether the Limelight has a targetbotpose3D- the MT1 Pose3d from the LimelightmegaPose- the MT2 Pose2d (provides translation for the reset)poseTimestamp- the FPGA timestamp of the pose estimate- Returns:
trueif the pose was accepted and the reset was applied
-
setLimelightPipelines
public void setLimelightPipelines(int pipeline) Sets all Limelights to the given pipeline index.- Parameters:
pipeline- the zero-indexed pipeline number to activate
-
blinkLimelights
Returns a command that blinks all Limelight LEDs while active and turns them off when the command ends.- Returns:
- the blink command
-
solidLimelight
Returns a command that holds all Limelight LEDs solid-on while active and turns them off when the command ends.- Returns:
- the solid-LED command
-
getBackLL
Rear-facing Limelight instance. -
getLeftLL
Left-facing Limelight instance. -
getRightLL
Right-facing Limelight instance. -
getTagLayout
Field layout loaded once at construction and shared across the robot.
-