Class Limelight
All methods are safe to call when the camera is not attached (isAttached() returns
false); they return zero / false / empty values in that case.
NetworkTables reads are snapshotted per robot loop: the first getter to need a topic reads it
once and every later getter in the same loop reuses that sample, so pose, tag count, raw
fiducials and timestamp always describe the same camera frame. The owning subsystem must call
invalidate() exactly once per loop before any getter. Returned LimelightHelpers.PoseEstimate and
LimelightHelpers.RawFiducial instances are shared for the rest of the loop and must not be mutated.
Two pose estimation flavors are supported:
- MegaTag1 is full 3-D pose estimation using one or more AprilTags.
- MegaTag2 is a 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.doubleGet 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 targetdoubleAge in seconds (capture time to now) of the last estimate this camera produced this loop, or NaN if it produced none.Human-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 (MEGATAG2) 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 to 100).doubleGet the vertical offset from crosshair to targetbooleanReturnstruewhen the pose estimate is considered accurate: multiple tags are visible and the combined target area exceeds a minimum threshold.voidClears the per-loop NetworkTables snapshot so the next getter re-reads the camera.booleanReturns whether this camera is physically connected to the robot.booleanChecks if the camera is connected by looking for a full botpose array from the camera.booleanWhether an estimate from this camera was fused into the pose estimator this loop.booleanWhether pose measurements from this camera are currently being integrated.booleanChecks if the LL sees multiple tagsvoidPrints the vision, estimated, and odometry pose to SmartDashboardvoidWrites this camera's configured mount pose (Limelight.LimelightConfig.withTranslation(double, double, double)andLimelight.LimelightConfig.withRotation(double, double, double)) to the camera over NetworkTables, making the code the source of truth for the offsets instead of the values typed into the web UI.voidsendInvalidStatus(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.voidsetIntegratedThisLoop(boolean integratedThisLoop) Whether an estimate from this camera was fused into the pose estimator this loop.voidsetIntegrating(boolean isIntegrating) Whether pose measurements from this camera are currently being integrated.voidsetLastEstimateAgeSeconds(double lastEstimateAgeSeconds) Age in seconds (capture time to now) of the last estimate this camera produced this loop, or NaN if it produced none.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)voidupdateCameraPose(Pose3d pose)
-
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
-
invalidate
public void invalidate()Clears the per-loop NetworkTables snapshot so the next getter re-reads the camera.Must be called exactly once per robot loop, before any pose/target getter, by the owning subsystem (see
Vision.periodic()). Between calls, every getter on this object returns data from the same NetworkTables sample. Safe to call on a detached camera. -
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.- Returns:
- the tag ID of the apriltag most centered in the LL's view, or the tag chosen by the criteria set in the LL dashboard
-
getTargetSize
public double getTargetSize()Returns the area of the primary target as a percentage of the camera image (0 to 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 (MEGATAG2) for the alliance in DriverStation.java- Returns:
- the corresponding LL Pose2d (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: 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.Does not flush NetworkTables; the caller is responsible for a single flush after all per-loop writes (see
Vision.periodic()). -
updateCameraPose
-
pushConfiguredCameraPose
public void pushConfiguredCameraPose()Writes this camera's configured mount pose (Limelight.LimelightConfig.withTranslation(double, double, double)andLimelight.LimelightConfig.withRotation(double, double, double)) to the camera over NetworkTables, making the code the source of truth for the offsets instead of the values typed into the web UI.The six values are stored in exactly the convention the camera wants: forward, right, up in metres, then roll, pitch, yaw in degrees. They go across unchanged. That is the same order and sign as the boxes in the web UI, so what is in
VisionConfigcan be read straight off against what a camera is showing.A Limelight keeps its own copy in flash and falls back to it on boot, so this has to be republished rather than written once: a camera that reboots mid-match otherwise silently reverts to whatever was last typed into it. See the resend loop in
Vision.periodic().Does not flush NetworkTables; the caller flushes once after all per-loop writes.
-
setRobotOrientation
public void setRobotOrientation(double degrees, double angularRate) Sets the robot orientation and yaw rate for the Limelight's internal IMU fusion (MegaTag2).Does not flush NetworkTables; the caller is responsible for a single flush after all per-loop writes (see
Vision.periodic()).- 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 to 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 a full botpose array from the 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. -
isIntegratedThisLoop
public boolean isIntegratedThisLoop()Whether an estimate from this camera was fused into the pose estimator this loop. -
setIntegratedThisLoop
public void setIntegratedThisLoop(boolean integratedThisLoop) Whether an estimate from this camera was fused into the pose estimator this loop. -
getLastEstimateAgeSeconds
public double getLastEstimateAgeSeconds()Age in seconds (capture time to now) of the last estimate this camera produced this loop, or NaN if it produced none. A large value means the camera's timestamps are not trustworthy. -
setLastEstimateAgeSeconds
public void setLastEstimateAgeSeconds(double lastEstimateAgeSeconds) Age in seconds (capture time to now) of the last estimate this camera produced this loop, or NaN if it produced none. A large value means the camera's timestamps are not trustworthy.
-