Package frc.spectrumLib.vision
Class Limelight
java.lang.Object
frc.spectrumLib.vision.Limelight
Provides a high-level interface to a single Limelight camera for AprilTag-based pose estimation
and basic targeting.
All methods are safe to call when the camera is not attached (isAttached() returns
false); they return zero / false / empty values in that case.
Two pose estimation flavors are supported:
- MegaTag1 — full 3-D pose estimation using one or more AprilTags.
- MegaTag2 — fused estimate that incorporates the robot heading supplied via
setRobotOrientation(double).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration for a single Limelight camera, including its network-table name and physical mounting position on the robot. -
Constructor Summary
ConstructorsConstructorDescriptionLimelight(Limelight.LimelightConfig config) Constructs a Limelight wrapper from a fully populatedLimelight.LimelightConfig.Constructs a Limelight wrapper with a default configuration for the given camera name.Constructs a Limelight wrapper, explicitly setting whether the camera is attached.Constructs a Limelight wrapper and immediately sets its active pipeline.Limelight(String name, int pipeline, Limelight.LimelightConfig config) Constructs a Limelight wrapper with an explicit configuration and immediately sets its active pipeline. -
Method Summary
Modifier and TypeMethodDescriptionvoidSet LL LED's to blinkNetwork-table name of this camera (mirrorsLimelight.LimelightConfig.getName()).doubleGets the ID of the apriltag most centered in the LL's view (or based on differentdoubleGet the distance of the 2d vector from the camera to closest apriltagdoublegetDistanceToTarget(double targetHeight) get distance in meters to a targetdoubleGet the horizontal offset from crosshair to targetHuman-readable string describing the current integration status, logged for diagnostics.Get the corresponding LL Pose3d (MEGATAG1) for the alliance in DriverStation.javaReturns the full MegaTag1LimelightHelpers.PoseEstimate, including timestamp, tag count, and raw fiducials.doubleReturns the timestamp of the MEGATAG1 pose estimation from the Limelight camera.Get the corresponding LL Pose2d (MEGATAG1) for the alliance in DriverStation.javaReturns the full MegaTag2LimelightHelpers.PoseEstimate(heading-fused), including timestamp and tag count.doubleReturns the timestamp of the MEGATAG2 pose estimation from the Limelight camera.getName()Returns the network-table name of this camera.doubleDeprecated, for removal: This API element is subject to removal in a future version.Returns the raw fiducial data for all currently detected AprilTags.doubleReturns the number of AprilTags included in the current MegaTag1 pose estimate.doubleReturns the Z-axis rotation of the primary target in robot space (yaw in radians, converted to degrees).Human-readable string describing the currently visible tag(s), logged for diagnostics.doublegetTagTA()Returns the area of the primary target as a percentage of the camera image.doublegetTagTx()Returns the X offset of the primary target in robot space (meters along the robot's left/right axis).doubleReturns the area of the primary target as a percentage of the camera image (0–100).doubleGet the vertical offset from crosshair to targetbooleanReturnstruewhen the pose estimate is considered accurate — i.e., multiple tags are visible and the combined target area exceeds a minimum threshold.booleanReturns whether this camera is physically connected to the robot.booleanChecks if the camera is connected by looking for an empty botpose array from camera.booleanWhether pose measurements from this camera are currently being integrated.booleanChecks if the LL sees multiple tagsvoidPrints the vision, estimated, and odometry pose to SmartDashboardvoidsendInvalidStatus(String message) Marks this camera as not integrating and updates the log status message.voidsendValidStatus(String message) Marks this camera as actively integrating and updates the log status message.voidsetIMUmode(int mode) Sets the IMU mode on the Limelight.voidsetIntegrating(boolean isIntegrating) Whether pose measurements from this camera are currently being integrated.voidsetLEDMode(boolean enabled) Sets the LED mode of the LL.voidsetLimelightPipeline(int pipelineIndex) Sets the LL pipeline to the given index.voidsetLogStatus(String logStatus) Human-readable string describing the current integration status, logged for diagnostics.voidsetRobotOrientation(double degrees) Sets the robot orientation in degrees for the Limelight's internal IMU.voidsetRobotOrientation(double degrees, double angularRate) Sets the robot orientation and yaw rate for the Limelight's internal IMU fusion (MegaTag2).voidsetTagStatus(String tagStatus) Human-readable string describing the currently visible tag(s), logged for diagnostics.booleanReturns whether the LL has any valid targets (April tags or other vision targets)
-
Constructor Details
-
Limelight
Constructs a Limelight wrapper from a fully populatedLimelight.LimelightConfig.- Parameters:
config- the camera configuration
-
Limelight
Constructs a Limelight wrapper with a default configuration for the given camera name.- Parameters:
name- the network-table name of the camera
-
Limelight
Constructs a Limelight wrapper, explicitly setting whether the camera is attached.- Parameters:
name- the network-table name of the cameraattached-trueif the camera is physically present on the robot
-
Limelight
Constructs a Limelight wrapper and immediately sets its active pipeline.- Parameters:
name- the network-table name of the camerapipeline- the pipeline index to activate (refer to robot vision configuration for pipeline indexes)
-
Limelight
Constructs a Limelight wrapper with an explicit configuration and immediately sets its active pipeline.- Parameters:
name- the network-table name of the camerapipeline- the pipeline index to activateconfig- the fully populatedLimelight.LimelightConfigto use
-
-
Method Details
-
getName
Returns the network-table name of this camera.- Returns:
- the camera name as configured in the LL dashboard
-
isAttached
public boolean isAttached()Returns whether this camera is physically connected to the robot.- Returns:
trueif attached
-
getHorizontalOffset
public double getHorizontalOffset()Get the horizontal offset from crosshair to target- Returns:
- Horizontal Offset From Crosshair To Target (LL1: -27 degrees to 27 degrees / LL2: -29.8 to 29.8 degrees)
-
getVerticalOffset
public double getVerticalOffset()Get the vertical offset from crosshair to target- Returns:
- Vertical Offset From Crosshair To Target in degrees (LL1: -20.5 degrees to 20.5 degrees / LL2: -24.85 to 24.85 degrees)
-
targetInView
public boolean targetInView()Returns whether the LL has any valid targets (April tags or other vision targets)- Returns:
- Whether the LL has any valid targets (April tags or other vision targets)
-
multipleTagsInView
public boolean multipleTagsInView()Checks if the LL sees multiple tags- Returns:
- whether the LL sees multiple tags or not
-
getTagCountInView
public double getTagCountInView()Returns the number of AprilTags included in the current MegaTag1 pose estimate.- Returns:
- number of tags contributing to the current pose estimate, or
0if not attached or no estimate is available
-
getClosestTagID
public double getClosestTagID()Gets the ID of the apriltag most centered in the LL's view (or based on different- Returns:
- the tag ID of the apriltag most centered in the LL's view (or based on different criteria set in LL dasbhoard)
-
getTargetSize
public double getTargetSize()Returns the area of the primary target as a percentage of the camera image (0–100).- Returns:
- target area percentage, or
0if not attached
-
getMegaTag1_Pose3d
Get the corresponding LL Pose3d (MEGATAG1) for the alliance in DriverStation.java- Returns:
- the corresponding LL Pose3d (MEGATAG1) for the alliance in DriverStation.java
-
getMegaTag2_Pose2d
Get the corresponding LL Pose2d (MEGATAG1) for the alliance in DriverStation.java- Returns:
- the corresponding LL Pose3d (MEGATAG2) for the alliance in DriverStation.java
-
getMegaTag1_PoseEstimate
Returns the full MegaTag1LimelightHelpers.PoseEstimate, including timestamp, tag count, and raw fiducials. Returns an empty estimate when not attached or when no estimate is available.- Returns:
- the MegaTag1 pose estimate in the WPILib Blue origin frame
-
getMegaTag2_PoseEstimate
Returns the full MegaTag2LimelightHelpers.PoseEstimate(heading-fused), including timestamp and tag count. Returns an empty estimate when not attached or when no estimate is available.- Returns:
- the MegaTag2 pose estimate in the WPILib Blue origin frame
-
hasAccuratePose
public boolean hasAccuratePose()Returnstruewhen the pose estimate is considered accurate — i.e., multiple tags are visible and the combined target area exceeds a minimum threshold.- Returns:
trueif the pose estimate meets the accuracy criteria
-
getDistanceToTagFromCamera
public double getDistanceToTagFromCamera()Get the distance of the 2d vector from the camera to closest apriltag- Returns:
- the distance of the 2d vector from the camera to closest apriltag
-
getRawFiducial
Returns the raw fiducial data for all currently detected AprilTags.- Returns:
- array of
LimelightHelpers.RawFiducialentries from the MegaTag1 estimate; empty array if not attached or no estimate is available
-
getMegaTag1PoseTimestamp
public double getMegaTag1PoseTimestamp()Returns the timestamp of the MEGATAG1 pose estimation from the Limelight camera.- Returns:
- The timestamp of the pose estimation in seconds.
-
getMegaTag2PoseTimestamp
public double getMegaTag2PoseTimestamp()Returns the timestamp of the MEGATAG2 pose estimation from the Limelight camera.- Returns:
- The timestamp of the pose estimation in seconds.
-
getPoseLatency
Deprecated, for removal: This API element is subject to removal in a future version.Returns the latency of the pose estimation from the Limelight camera.- Returns:
- The latency of the pose estimation in seconds.
-
getDistanceToTarget
public double getDistanceToTarget(double targetHeight) get distance in meters to a target- Parameters:
targetHeight- meters- Returns:
- distance in meters to a target
-
sendValidStatus
Marks this camera as actively integrating and updates the log status message.- Parameters:
message- a human-readable description of why integration is valid
-
sendInvalidStatus
Marks this camera as not integrating and updates the log status message.- Parameters:
message- a human-readable description of why integration is invalid
-
setLimelightPipeline
public void setLimelightPipeline(int pipelineIndex) Sets the LL pipeline to the given index.- Parameters:
pipelineIndex- the pipeline index (refer to robot vision configuration for pipeline indexes)
-
setRobotOrientation
public void setRobotOrientation(double degrees) Sets the robot orientation in degrees for the Limelight's internal IMU. -
setRobotOrientation
public void setRobotOrientation(double degrees, double angularRate) Sets the robot orientation and yaw rate for the Limelight's internal IMU fusion (MegaTag2).- Parameters:
degrees- robot heading in degrees (positive counter-clockwise)angularRate- current yaw rate in degrees per second
-
setIMUmode
public void setIMUmode(int mode) Sets the IMU mode on the Limelight.- Parameters:
mode- the IMU mode index (refer to the LL documentation for valid values)
-
getTagTx
public double getTagTx()Returns the X offset of the primary target in robot space (meters along the robot's left/right axis).- Returns:
- target X translation in meters, or
-99999if not attached or no target in view
-
getTagTA
public double getTagTA()Returns the area of the primary target as a percentage of the camera image.- Returns:
- target area (0–100 %), or
-99999if not attached or no target in view
-
getTagRotationDegrees
public double getTagRotationDegrees()Returns the Z-axis rotation of the primary target in robot space (yaw in radians, converted to degrees).- Returns:
- target yaw rotation in degrees, or
-99999if not attached or no target in view
-
setLEDMode
public void setLEDMode(boolean enabled) Sets the LED mode of the LL.- Parameters:
enabled- true to enable the LED mode, false to disable it
-
blinkLEDs
public void blinkLEDs()Set LL LED's to blink -
isCameraConnected
public boolean isCameraConnected()Checks if the camera is connected by looking for an empty botpose array from camera. -
printDebug
public void printDebug()Prints the vision, estimated, and odometry pose to SmartDashboard -
isIntegrating
public boolean isIntegrating()Whether pose measurements from this camera are currently being integrated. -
setIntegrating
public void setIntegrating(boolean isIntegrating) Whether pose measurements from this camera are currently being integrated. -
getCameraName
Network-table name of this camera (mirrorsLimelight.LimelightConfig.getName()). -
getLogStatus
Human-readable string describing the current integration status, logged for diagnostics. -
setLogStatus
Human-readable string describing the current integration status, logged for diagnostics. -
getTagStatus
Human-readable string describing the currently visible tag(s), logged for diagnostics. -
setTagStatus
Human-readable string describing the currently visible tag(s), logged for diagnostics.
-