Class Limelight

java.lang.Object
frc.spectrumLib.vision.Limelight

public class Limelight extends Object
Wraps one Limelight camera for AprilTag pose estimation and basic targeting.

Every getter is safe on a detached camera (isAttached() is false) and returns zero, false, or an empty value.

Getters share one NetworkTables sample per robot loop. The first getter to need a topic reads it, and every later getter in that loop reuses the sample, so pose, tag count, fiducials, and timestamp all describe the same camera frame. The owning subsystem calls invalidate() once per loop before any getter. Returned LimelightHelpers.PoseEstimate and LimelightHelpers.RawFiducial objects belong to that sample and must not be mutated.

MegaTag1 solves pose from the tags alone. MegaTag2 fuses in the heading the owning subsystem passes to setRobotOrientation(double).

  • Constructor Details

    • Limelight

      public Limelight(Limelight.LimelightConfig config)
    • Limelight

      public Limelight(String name)
    • Limelight

      public Limelight(String name, boolean attached)
    • Limelight

      public Limelight(String name, int pipeline)
      Parameters:
      pipeline - index to activate; the indexes come from the robot's vision configuration
    • Limelight

      public Limelight(String name, int pipeline, Limelight.LimelightConfig config)
      Parameters:
      pipeline - index to activate; the indexes come from the robot's vision configuration
  • Method Details

    • invalidate

      public void invalidate()
      Drops the per-loop snapshot so the next getter re-reads the camera.

      The owning subsystem calls this once per loop before any getter (see Vision.periodic()). Safe on a detached camera.

    • getName

      public String getName()
    • getCameraName

      public String getCameraName()
      Same as getName().
    • isAttached

      public boolean isAttached()
    • getHorizontalOffset

      public double getHorizontalOffset()
      Horizontal offset from the crosshair to the target, in degrees. LL1 spans -27 to 27, LL2 -29.8 to 29.8.
    • getVerticalOffset

      public double getVerticalOffset()
      Vertical offset from the crosshair to the target, in degrees. LL1 spans -20.5 to 20.5, LL2 -24.85 to 24.85.
    • targetInView

      public boolean targetInView()
    • multipleTagsInView

      public boolean multipleTagsInView()
    • getTagCountInView

      public double getTagCountInView()
    • getClosestTagID

      public double getClosestTagID()
    • getTargetSize

      public double getTargetSize()
      Area of the primary target as a percentage of the camera image (0-100).
    • getMegaTag1_Pose3d

      public Pose3d getMegaTag1_Pose3d()
    • getMegaTag2_Pose2d

      public Pose2d getMegaTag2_Pose2d()
    • getMegaTag1_PoseEstimate

      public LimelightHelpers.PoseEstimate getMegaTag1_PoseEstimate()
      Full MegaTag1 estimate, including timestamp, tag count, and raw fiducials, in the WPILib Blue origin frame.
    • getMegaTag2_PoseEstimate

      public LimelightHelpers.PoseEstimate getMegaTag2_PoseEstimate()
      Full heading-fused MegaTag2 estimate, including timestamp and tag count, in the WPILib Blue origin frame.
    • hasAccuratePose

      public boolean hasAccuratePose()
      Needs more than one tag and a target area above 0.1 percent of the frame.
    • getDistanceToTagFromCamera

      public double getDistanceToTagFromCamera()
      Distance to the closest tag, from the X and Z axes of the camera-in-tag-space pose.
    • getRawFiducial

      public LimelightHelpers.RawFiducial[] getRawFiducial()
      Raw fiducials from the MegaTag1 estimate, or an empty array when there is no estimate.
    • getMegaTag1PoseTimestamp

      public double getMegaTag1PoseTimestamp()
      Timestamp of the MegaTag1 pose estimate, in seconds.
    • getMegaTag2PoseTimestamp

      public double getMegaTag2PoseTimestamp()
      Timestamp of the MegaTag2 pose estimate, in seconds.
    • getDistanceToTarget

      public double getDistanceToTarget(double targetHeight)
      Distance to a target at a known height, from the camera's height above the floor and the camera's pitch plus the reported vertical offset.
      Parameters:
      targetHeight - height of the target above the floor, in metres
    • sendValidStatus

      public void sendValidStatus(String message)
      Marks this camera as integrating and records why.
      Parameters:
      message - status text the caller wants on the dashboard
    • sendInvalidStatus

      public void sendInvalidStatus(String message)
      Marks this camera as not integrating and records why.
      Parameters:
      message - status text the caller wants on the dashboard
    • setLimelightPipeline

      public void setLimelightPipeline(int pipelineIndex)
      Activates a pipeline by index; the indexes come from the robot's vision configuration.
    • setRobotOrientation

      public void setRobotOrientation(double degrees)
      Sets the robot heading the camera's internal IMU fuses, in degrees.

      Does not flush NetworkTables. The owning subsystem flushes once after all per-loop writes.

    • updateCameraPose

      public void updateCameraPose(Pose3d pose)
    • pushConfiguredCameraPose

      public void pushConfiguredCameraPose()
      Writes the configured mount offsets (Limelight.LimelightConfig.withTranslation(double, double, double) and Limelight.LimelightConfig.withRotation(double, double, double)) to the camera, so the code is the source of truth instead of the values typed into the web UI. The six values cross in the order and sign the camera wants, so a config value can be read straight against the matching web UI box.

      A camera keeps its own copy in flash and falls back to it on boot, so this has to run again periodically: one that reboots mid-match reverts to whatever was last typed into it. See the resend loop in Vision.periodic(). Does not flush NetworkTables.

    • setRobotOrientation

      public void setRobotOrientation(double degrees, double angularRate)
      Sets the heading and yaw rate the camera's internal IMU fuses, for MegaTag2.

      Does not flush NetworkTables. The owning subsystem flushes once after all per-loop writes.

      Parameters:
      degrees - robot heading in degrees, positive counter-clockwise
      angularRate - current yaw rate in degrees per second
    • setIMUmode

      public void setIMUmode(int mode)
      Parameters:
      mode - IMU mode index; valid values are in the Limelight documentation
    • getTagTx

      public double getTagTx()
      X offset of the primary target in robot space, in metres along the robot's left/right axis. Returns -99999 when no target is in view.
    • getTagTA

      public double getTagTA()
      Area of the primary target as a percentage of the camera image. Returns -99999 when no target is in view.
    • getTagRotationDegrees

      public double getTagRotationDegrees()
      Z-axis rotation of the primary target in robot space, in degrees. Returns -99999 when no target is in view.
    • setLEDMode

      public void setLEDMode(boolean enabled)
    • blinkLEDs

      public void blinkLEDs()
    • isCameraConnected

      public boolean isCameraConnected()
      True when the raw MT1 sample is long enough to hold a pose.
    • printDebug

      public void printDebug()
    • isIntegrating

      public boolean isIntegrating()
      Whether the pose estimator is currently fusing a measurement from this camera.
    • setIntegrating

      public void setIntegrating(boolean isIntegrating)
      Whether the pose estimator is currently fusing a measurement from this camera.
    • getLogStatus

      public String getLogStatus()
    • setLogStatus

      public void setLogStatus(String logStatus)
    • getTagStatus

      public String getTagStatus()
    • setTagStatus

      public void setTagStatus(String tagStatus)
    • isIntegratedThisLoop

      public boolean isIntegratedThisLoop()
      Written by the owning subsystem as it accepts or rejects each estimate.
    • setIntegratedThisLoop

      public void setIntegratedThisLoop(boolean integratedThisLoop)
      Written by the owning subsystem as it accepts or rejects each estimate.
    • getLastEstimateAgeSeconds

      public double getLastEstimateAgeSeconds()
      Seconds from the last estimate's capture time to now, or NaN if this camera produced none this loop. A large value means the camera's timestamps are not trustworthy.
    • setLastEstimateAgeSeconds

      public void setLastEstimateAgeSeconds(double lastEstimateAgeSeconds)
      Seconds from the last estimate's capture time to now, or NaN if this camera produced none this loop. A large value means the camera's timestamps are not trustworthy.