Class Limelight
- All Implemented Interfaces:
AutoCloseable
Quick start
Visual servoing
double turnKp = -0.02;
Limelight camera = new Limelight("limelight");
//Limelight camera = new Limelight(Limelight.SYSTEMCORE_USB0);
//Limelight camera = new Limelight(Limelight.SYSTEMCORE_USB1);
// Each loop
double turn = joystick.getRightX();
if(aimingEnabled && camera.hasTarget()){
turn = turnKp * camera.getTXDegrees();
}
drivetrain.arcadeDrive(forward, turn);
MegaTag1 localization
Pose3d cameraPoseRobotSpace = new Pose3d(0.30, 0.0, 0.20, new Rotation3d());
Limelight camera = new Limelight("limelight", cameraPoseRobotSpace);
// Each robot loop
Limelight.PoseEstimateType type = Limelight.PoseEstimateType.MT1_WPIBLUE;
for (var estimate : camera.readAcceptedPoseEstimates(type)) {
poseEstimator.addVisionMeasurement(estimate.pose, estimate.timestampSeconds, estimate.stdDevs);
}
MegaTag2 localization
Publish robot yaw before reading the queue each robot loop.
Pose3d cameraPoseRobotSpace = new Pose3d(0.30, 0.0, 0.20, new Rotation3d());
Limelight camera = new Limelight("limelight", cameraPoseRobotSpace);
// Each robot loop
Limelight.setSharedRobotOrientation(robotYawDegrees);
Limelight.PoseEstimateType type = Limelight.PoseEstimateType.MT2_WPIBLUE;
for (var estimate : camera.readAcceptedPoseEstimates(type)) {
poseEstimator.addVisionMeasurement(estimate.pose, estimate.timestampSeconds, estimate.stdDevs);
}
Configured MegaTag1 and MegaTag2
This example configures every filter and standard-deviation scaling term. MT1 scales XY uncertainty linearly with distance and clamps it to 0.05-2.0 meters. MT2 scales it by the square root of distance and clamps it to 0.0001-2.0 meters. Both divide by the square root of the fielded tag count. Vision heading is not fused. The field bounds are for the 2026 welded field. Tune the other thresholds on your robot.
double untrusted = Limelight.PoseEstimateConfig.UNTRUSTED;
// Start from the default so you do not have to set every value.
Limelight.PoseEstimateConfig mt1Config = Limelight.PoseEstimateConfig.defaultMT1()
.withMinTagCount(1)
.withMaxSingleTagAmbiguity(0.7) // MT1 needs low-ambiguity perspectives
.withMaxSingleTagDistance(3.0) // Trust a single tag only within 3 m
.withMaxAvgTagDistance(6.0) // With several tags, average distance under 6 m
.withMinAvgTagArea(0.05)
.withFieldBounds(16.541, 8.069) // Reject estimates outside the field
.withFieldBoundsMargin(0.5) // Allow 0.5 m past the field walls
.withStdDevXY(0.5, 0.05, 2.0) // 0.5 base, minimum 0.05, maximum 2.0
.withStdDevTheta(untrusted, untrusted, untrusted) // Never fuse vision heading
.withStdDevDistanceScaling(1.0, 0.0, 6.0) // Linear scaling
.withStdDevTagCountDivision(0.5);
Limelight.PoseEstimateConfig mt2Config = Limelight.PoseEstimateConfig.defaultMT2()
.withMinTagCount(1)
.withMaxSingleTagAmbiguity(1.0) // MT2 handles ambiguous perspectives, accept all
.withMaxSingleTagDistance(0.0) // 0 disables this check
.withMaxAvgTagDistance(8.0)
.withMinAvgTagArea(0.02)
.withFieldBounds(16.541, 8.069)
.withFieldBoundsMargin(0.5)
.withStdDevXY(0.3, 0.0001, 2.0)
.withStdDevTheta(untrusted, untrusted, untrusted)
.withStdDevDistanceScaling(0.5, 0.0, 8.0) // Square root of distance for MT2
.withStdDevTagCountDivision(0.5);
Pose3d cameraPoseRobotSpace = new Pose3d(0.30, 0.0, 0.20, new Rotation3d());
Limelight camera = new Limelight("limelight", cameraPoseRobotSpace)
.withPoseEstimateConfig_MT1(mt1Config)
.withPoseEstimateConfig_MT2(mt2Config)
.withTelemetry(true); // Keep accepted and rejected poses visible on dashboards
boolean useMegaTag2 = true;
// Each robot loop
Limelight.PoseEstimateType type = Limelight.PoseEstimateType.MT1_WPIBLUE;
if (useMegaTag2) {
type = Limelight.PoseEstimateType.MT2_WPIBLUE;
// Use your robot pose heading here, not your raw IMU reading.
Limelight.setSharedRobotOrientation(robotYawDegrees);
}
for (var estimate : camera.readAcceptedPoseEstimates(type)) {
poseEstimator.addVisionMeasurement(estimate.pose, estimate.timestampSeconds, estimate.stdDevs);
}
All values from one getLatestResults() call come from the same frame. This includes
tx, botpose, fiducials, latencies, and timestamps.
All 3D data uses the right-handed NWU convention in every space (field, robot, camera, target): x = forward, y = left, z = up. Raw pose arrays are [x, y, z, roll, pitch, yaw] in meters and degrees.
Getters decode at most one new frame. Otherwise they return cached data. After a disconnect,
they return the values of the last frame. Use getStatus() or Limelight.LimelightResults.getAgeSeconds() to detect a stale camera.
Use this class from one thread, the robot loop.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA barcode/QR code target.static classLive camera intrinsics for the running pipeline.static classA neural classifier result.static classA per-class object counter result from the neural counter pipeline.static classA neural detector target.static enumAprilTag detector downscaling factors.static classAn AprilTag/fiducial target.static final classAn immutable, validated shared field map.static classCamera hardware and system stats.static classThe state of the camera's internal IMU.static enumIMU sources for the robot yaw that MegaTag2 uses.static enumLED behavior modes.static classThe complete decoded results for one frame.static classFields common to all image-space targets.static enumResult of loading aLimelight.PipelineConfigurationorLimelight.FieldMap.static classAn OCR (text recognition) result.static final classAn immutable, validated pipeline configuration override.static enumPipeline configuration override state reported by the camera.static classA robot pose estimate with the metadata needed for pose-estimator fusion.static classA reusable configuration object for rejection filters and standard deviation scaling.static enumThe robot pose estimate outputs.static classA color/retroreflective target.static classRewind buffer state.static classThe robot-orientation state the camera is using for MegaTag2.static enumShared field map state reported by the camera.static enumHealth of a camera. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum size in bytes of a pipeline configuration override.static final intMaximum size in bytes of a shared field map.static final doubleNetworkTables timestamp ticks per second for the WPILib build this library targets.static final doubleDefault stale threshold.static final intThe highest camera protocol version ("protover") this library understands.static final StringName of the vision instance running on Systemcore USB port 0:new Limelight(Limelight.SYSTEMCORE_USB0).static final StringName of the vision instance running on Systemcore USB port 1.static final StringName of the vision instance running on Systemcore USB port 2.static final StringName of the vision instance running on Systemcore USB port 3.static final StringRoot telemetry table. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an interface to the Limelight with the default name ("limelight").Creates an interface to the given Limelight.Limelight(String name, double forward, double left, double up, double rollDegrees, double pitchDegrees, double yawDegrees) Creates an interface to the given Limelight and sets its camera pose in robot space.Creates an interface to the given Limelight and sets its camera pose in robot space. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the camera pose override.voidClears the crop window override, returning to the full image.voidClears the fiducial 3D offset override.voidClears the AprilTag downscaling override.voidClears the AprilTag ID filter override.voidClears the keystone override.voidClears the published pipeline configuration override.voidClears the priority AprilTag ID override.static voidClears the shared field map.voidclose()Releases this instance's NetworkTables subscriptions and removes its telemetry topics.static Limelight.LimelightResultsdecode(byte[] envelope) Decodes a results envelope from raw MessagePack bytes.static Limelight.LimelightResultsdecode(byte[] envelope, long receiveTimestampMicros) Decodes a results envelope and stamps it with its NetworkTables receive time.static voidflushNT()Flushes NetworkTables immediately.Returns the camera intrinsics that the running pipeline uses.org.wpilib.math.geometry.Pose3dReturns camera pose in robot space (meters, degrees) as a Pose3d.doubleReturns capture latency in milliseconds.intReturns active pipeline index (0-9).Returns active pipeline type, for example "pipe_fiducial", "pipe_color", or "pipe_detector".Returns hardware/system stats from the latest frame.Returns iMU state from the latest frame.org.wpilib.networktables.TimestampedRawReturns the newest raw results envelope without decoding it.Returns the latest results envelope.getName()Returns the camera's NetworkTables name.Returns the camera's pipeline configuration override state from the latest results frame.getPoseEstimate(Limelight.LimelightResults results, Limelight.PoseEstimateType type) Builds a pose estimate of the given type from one results envelope.Gets the pose estimate of the given type from the newest frame.intReturns the msgpack envelope protocol version from the camera.double[]Returns data set by a python snapscript via llpython.org.wpilib.math.geometry.Pose3dReturns the full 3D robot pose for the given estimate type.Returns the camera's shared field map state from the latest results frame.Returns the current health of the camera from the point of view of this consumer.doubleReturns target area as a percentage of the image (0-100).intReturns total number of retro, fiducial, detector, classifier, and barcode targets in the latest frame.doubleReturns 3D distance from the camera to the primary fiducial target in meters.doubleReturns targeting/pipeline latency in milliseconds.doubleReturns horizontal offset from crosshair to target in degrees.doubleReturns horizontal offset from principal pixel to target in degrees (crosshair-independent).doubleReturns vertical offset from crosshair to target in degrees.doubleReturns vertical offset from principal pixel to target in degrees (crosshair-independent).booleanReturns true if the camera is connected, sends fresh frames, and has at least one valid target.booleanReturns true if the camera is reachable.booleanReads back whether the camera runs the pipeline configuration override.booleanReturns true if the camera localizes with the shared field map published withsetSharedMap(Limelight.FieldMap).booleanReturns true if the running pipeline uses a user-uploaded camera calibration instead of a built-in default.Reads every frame received since the last queue read.Reads every frame received since the last queue read.org.wpilib.networktables.TimestampedRaw[]Reads every raw envelope received since the last queue read, without decoding.Decodes and returns every buffered results envelope received since the last queue read.voidsetCameraPose_RobotSpaceOverride(double forward, double left, double up, double roll, double pitch, double yaw, boolean flush) Sets the camera pose relative to the robot.voidsetCameraPose_RobotSpaceOverride(org.wpilib.math.geometry.Pose3d cameraPoseRobotSpace, boolean flush) Sets the camera pose relative to the robot.voidsetCropWindowOverride(double cropXMin, double cropXMax, double cropYMin, double cropYMax) Sets the crop window.voidsetFiducial3DOffsetOverride(double forward, double left, double up) Moves the 3D targeting point away from the center of the primary in-view fiducial.voidsetFiducial3DOffsetOverride(org.wpilib.math.geometry.Translation3d offset) Moves the 3D targeting point away from the center of the primary in-view fiducial.voidOverrides the AprilTag detector's downscaling factor.voidsetFiducialIDFiltersOverride(int[] validIDs) Overrides the valid AprilTag IDs for localization.voidsetIMUAssistAlpha(double alpha) Configures the complementary filter alpha for the IMU assist modes (modes 3 and 4).voidsetIMUMode(Limelight.IMUMode mode) Configures the robot-yaw source for MegaTag2 localization.voidsetKeystoneOverride(double horizontal, double vertical) Sets the keystone modification for the crop window.voidsetLEDMode(Limelight.LEDMode mode) Sets the LED behavior.voidPublishes a pipeline configuration override to this camera.voidsetPipelineIndex(int pipelineIndex) Switches to the given pipeline.voidsetPriorityTagIDOverride(int id) Sets the priority AprilTag ID for tx/ty targeting.voidsetPythonScriptData(double[] outgoingPythonData) Sends data to a running python snapscript via llrobot.voidsetRewindEnabled(boolean enabled) Enables or pauses the rewind buffer recording.voidsetRobotOrientation(double yawDegrees, boolean flush) (ADVANCED) Sets the individual robot orientation of this camera for the MegaTag2 algorithm.voidsetRobotOrientation(double yaw, double yawRate, double pitch, double pitchRate, double roll, double rollRate, boolean flush) (ADVANCED) Sets the full individual robot orientation of this camera for the MegaTag2 algorithm.static voidsetSharedMap(Limelight.FieldMap fieldMap) Publishes a shared field map on the "limelightshared" table.static voidsetSharedRobotOrientation(double yawDegrees) Sets the robot orientation for MegaTag2 on the shared "limelightshared" table.static voidsetSharedRobotOrientation(double yaw, double yawRate, double pitch, double pitchRate, double roll, double rollRate) Sets the full shared robot orientation for MegaTag2 on the "limelightshared" table.voidsetThrottle(int throttle) Configures the throttle value.voidsetUsePipelineConfigurationOverride(boolean use) Enables or disables the pipeline configuration override.voidsetUseSharedOrientation(boolean useShared) (ADVANCED) Controls whether this camera reads the shared orientation fromsetSharedRobotOrientation(double).static org.wpilib.math.geometry.Pose2dtoPose2D(double[] inData) Converts a pose array to a Pose2d.static org.wpilib.math.geometry.Pose3dtoPose3D(double[] inData) Converts a pose array to a Pose3d.voidtriggerRewindCapture(double durationSeconds) Triggers a rewind capture with the given duration.voidTriggers a snapshot capture.Configures filtering and fusion standard deviations for every MegaTag1 pose estimate.Configures filtering and fusion standard deviations for every MegaTag2 pose estimate.withStaleFrameThreshold(double seconds) Sets the maximum age of the newest frame.withTelemetry(boolean enabled) Enables or disables automatic pose-estimate telemetry.
-
Field Details
-
STALE_FRAME_SECONDS
public static final double STALE_FRAME_SECONDSDefault stale threshold.getStatus()reportsLimelight.Status.STALEfor a frame older than this. Override per instance withwithStaleFrameThreshold(double).- See Also:
-
NT_TICKS_PER_SECOND
public static final double NT_TICKS_PER_SECONDNetworkTables timestamp ticks per second for the WPILib build this library targets. WPILib 2027 alpha-7 and later use 1e9. Alpha-6 and earlier use 1e6. Divide a NetworkTables timestamp by this value to get seconds.- See Also:
-
SUPPORTED_PROTOCOL_VERSION
public static final int SUPPORTED_PROTOCOL_VERSIONThe highest camera protocol version ("protover") this library understands. If a camera publishes a higher version, the library prints one warning.- See Also:
-
MAX_PIPELINE_CONFIGURATION_OVERRIDE_BYTES
public static final int MAX_PIPELINE_CONFIGURATION_OVERRIDE_BYTESMaximum size in bytes of a pipeline configuration override. Both this library and the camera reject larger publishes.- See Also:
-
MAX_SHARED_MAP_BYTES
public static final int MAX_SHARED_MAP_BYTESMaximum size in bytes of a shared field map. Both this library and the camera reject larger publishes.- See Also:
-
SYSTEMCORE_USB0
Name of the vision instance running on Systemcore USB port 0:new Limelight(Limelight.SYSTEMCORE_USB0).- See Also:
-
SYSTEMCORE_USB1
Name of the vision instance running on Systemcore USB port 1.- See Also:
-
SYSTEMCORE_USB2
Name of the vision instance running on Systemcore USB port 2.- See Also:
-
SYSTEMCORE_USB3
Name of the vision instance running on Systemcore USB port 3.- See Also:
-
TELEMETRY_TABLE
Root telemetry table. Each camera useslimelight_telemetry/<name>/. The shared Field2d table islimelight_telemetry/Field.- See Also:
-
-
Constructor Details
-
Limelight
public Limelight()Creates an interface to the Limelight with the default name ("limelight"). -
Limelight
Creates an interface to the given Limelight.- Parameters:
name- The camera or vision instance's NetworkTables name (e.g. "limelight" or "limelight-left")
-
Limelight
Creates an interface to the given Limelight and sets its camera pose in robot space.- Parameters:
name- The NetworkTables name of the camera, for example "limelight" or "limelight-left"cameraPoseRobotSpace- The pose of the camera relative to the robot center (x = forward, y = left, z = up, in meters). This overrides the camera pose configured in the web interface. CallclearCameraPose_RobotSpaceOverride()to return to it. Null publishes nothing. An all-zero pose is the clear value, so the camera keeps the pose from the web interface.
-
Limelight
public Limelight(String name, double forward, double left, double up, double rollDegrees, double pitchDegrees, double yawDegrees) Creates an interface to the given Limelight and sets its camera pose in robot space. This overrides the camera pose configured in the web interface. CallclearCameraPose_RobotSpaceOverride()to return to it. An all-zero pose is the clear value, so the camera keeps the pose from the web interface.- Parameters:
name- The NetworkTables name of the camera, for example "limelight" or "limelight-left"forward- Forward (x) offset in metersleft- Left (y) offset in metersup- Up (z) offset in metersrollDegrees- Roll angle in degreespitchDegrees- Pitch angle in degreesyawDegrees- Yaw angle in degrees
-
-
Method Details
-
withStaleFrameThreshold
Sets the maximum age of the newest frame. Above this age,getStatus()reportsLimelight.Status.STALEandhasTarget()returns false. Raise this value when you usesetThrottle(int).- Parameters:
seconds- Stale threshold in seconds. Positive infinity disables stale detection.- Returns:
- this, for chaining with the constructor
-
withPoseEstimateConfig_MT1
Configures filtering and fusion standard deviations for every MegaTag1 pose estimate. MegaTag1 computes heading from tag geometry only. It usually needs stricter ambiguity and tag-count gates than MegaTag2. Rejected estimates reportisValid() == false.Limelight.PoseEstimate.rejectionFlagslists the failed checks.- Parameters:
config- The MegaTag1 configuration. The configuration is copied. Later changes to the object have no effect until you attach it again. Null resets toLimelight.PoseEstimateConfig.defaultMT1()- Returns:
- this, for chaining with the constructor
-
withPoseEstimateConfig_MT2
Configures filtering and fusion standard deviations for every MegaTag2 pose estimate.- Parameters:
config- The MegaTag2 configuration. The configuration is copied. Later changes to the object have no effect until you attach it again. Null resets toLimelight.PoseEstimateConfig.defaultMT2()- Returns:
- this, for chaining with the constructor
-
withTelemetry
Enables or disables automatic pose-estimate telemetry. Enabled by default. Pose estimates publish underlimelight_telemetry/<name>/<type>/:acceptedandrejected: Pose2d struct arrays for field viewsrejectionReasons: for exampleTAG_COUNT|AMBIGUITY
The camera-level
counts/topics aggregate all estimate types thatreadPoseEstimateQueue(Limelight.PoseEstimateType)andreadAcceptedPoseEstimates(Limelight.PoseEstimateType)process. One estimate can increment several rejection-reason totals. The same estimates appear on the sharedlimelight_telemetry/FieldField2d table for Glass and Elastic. Camera health publishes asconnected,customCalibration, andstatus. Pose displays clear when the camera is unhealthy. Disabling telemetry unpublishes everything and resets the counters.- Returns:
- this, for chaining with the constructor
-
getName
Returns the camera's NetworkTables name.- Returns:
- The camera's NetworkTables name
-
getProtocolVersion
public int getProtocolVersion()Returns the msgpack envelope protocol version from the camera.- Returns:
- The msgpack envelope protocol version from the camera. 0 if the camera has not connected or runs old software
-
getLatestResults
Returns the latest results envelope. Decodes the newest MessagePack frame if one arrived since the last call. This method is cheap to call many times per loop. The decoded envelope is cached until a new frame arrives. This method never consumes the frame queue. You can use it together withreadResultsQueue().- Returns:
- The latest LimelightResults, never null. Use
getStatus()for camera health. UseLimelight.LimelightResults.validfor target validity. Each new frame produces a new object. Call this getter every loop instead of keeping the returned object.
-
decode
Decodes a results envelope from raw MessagePack bytes. Decode failures are reported inLimelight.LimelightResults.error. This method never throws. Use it for unit tests.receiveTimestampSecondsstays 0. Pose estimates built from the result are rejected as NO_TIMESTAMP. Usedecode(byte[], long)for pose estimate tests.- Parameters:
envelope- The raw MessagePack results dump- Returns:
- The decoded results.
receiveTimestampSecondsstays 0
-
decode
Decodes a results envelope and stamps it with its NetworkTables receive time. This matches live decoding and timestamp handling. For log replay: record raw frames withgetLatestRawFrame()orreadRawFrameQueue(). Then pass the bytes and the timestamp to this method. Estimates built from the result have latency-compensated timestamps.- Parameters:
envelope- The raw MessagePack results dumpreceiveTimestampMicros- NetworkTables receive time in microseconds (local NetworkTables timebase, WPILib alpha-6 or older), for exampleTimestampedRaw.timestamp
-
getStatus
Returns the current health of the camera from the point of view of this consumer.- Returns:
- The current health of the camera from the point of view of this consumer.
Limelight.Status.OKmeans a decodable frame arrived within the stale threshold. The threshold isSTALE_FRAME_SECONDSunless you override it withwithStaleFrameThreshold(double).
-
isConnected
public boolean isConnected()Returns true if the camera is reachable.- Returns:
- True if the camera is reachable. The status is not
Limelight.Status.NO_DATAand notLimelight.Status.STALE
-
close
public void close()Releases this instance's NetworkTables subscriptions and removes its telemetry topics. Call from test teardown. Robot code normally never needs this.- Specified by:
closein interfaceAutoCloseable
-
hasTarget
public boolean hasTarget()Returns true if the camera is connected, sends fresh frames, and has at least one valid target.- Returns:
- True if the camera is connected, sends fresh frames, and has at least one valid target. Returns false when the newest frame is older than the stale threshold.
-
getTXDegrees
public double getTXDegrees()Returns horizontal offset from crosshair to target in degrees.- Returns:
- Horizontal offset from crosshair to target in degrees. This value holds the last
received value after a disconnect. Check
hasTarget()every loop.
-
getTYDegrees
public double getTYDegrees()Returns vertical offset from crosshair to target in degrees.- Returns:
- Vertical offset from crosshair to target in degrees. This value holds the last received
value after a disconnect. Check
hasTarget()every loop.
-
getTXDegreesNoCrosshair
public double getTXDegreesNoCrosshair()Returns horizontal offset from principal pixel to target in degrees (crosshair-independent).- Returns:
- Horizontal offset from principal pixel to target in degrees (crosshair-independent)
-
getTYDegreesNoCrosshair
public double getTYDegreesNoCrosshair()Returns vertical offset from principal pixel to target in degrees (crosshair-independent).- Returns:
- Vertical offset from principal pixel to target in degrees (crosshair-independent)
-
getTargetAreaPercent
public double getTargetAreaPercent()Returns target area as a percentage of the image (0-100).- Returns:
- Target area as a percentage of the image (0-100). This value holds the last received
value after a disconnect. Check
hasTarget()every loop.
-
getTargetDistanceMeters
public double getTargetDistanceMeters()Returns 3D distance from the camera to the primary fiducial target in meters.- Returns:
- 3D distance from the camera to the primary fiducial target in meters. 0 if not available
-
getTargetCount
public int getTargetCount()Returns total number of retro, fiducial, detector, classifier, and barcode targets in the latest frame.- Returns:
- Total number of retro, fiducial, detector, classifier, and barcode targets in the latest frame
-
getCurrentPipelineIndex
public int getCurrentPipelineIndex()Returns active pipeline index (0-9).- Returns:
- Active pipeline index (0-9). -1 before the first frame arrives
-
getCurrentPipelineType
Returns active pipeline type, for example "pipe_fiducial", "pipe_color", or "pipe_detector".- Returns:
- Active pipeline type, for example "pipe_fiducial", "pipe_color", or "pipe_detector"
-
getTargetingLatencyMillis
public double getTargetingLatencyMillis()Returns targeting/pipeline latency in milliseconds.- Returns:
- Targeting/pipeline latency in milliseconds
-
getCaptureLatencyMillis
public double getCaptureLatencyMillis()Returns capture latency in milliseconds.- Returns:
- Capture latency in milliseconds
-
getIMUData
Returns iMU state from the latest frame.- Returns:
- IMU state from the latest frame
-
getHardwareData
Returns hardware/system stats from the latest frame.- Returns:
- Hardware/system stats from the latest frame
-
getCameraIntrinsics
Returns the camera intrinsics that the running pipeline uses.- Returns:
- The camera intrinsics that the running pipeline uses. Includes the camera matrix scaled to the processing resolution, the OpenCV distortion coefficients, and the FOV
-
isUsingCustomCalibration
public boolean isUsingCustomCalibration()Returns true if the running pipeline uses a user-uploaded camera calibration instead of a built-in default.- Returns:
- True if the running pipeline uses a user-uploaded camera calibration instead of a
built-in default. See
Limelight.CameraIntrinsics.customCalibration. False before the first frame arrives.
-
getPythonScriptData
public double[] getPythonScriptData()Returns data set by a python snapscript via llpython.- Returns:
- Data set by a python snapscript via llpython
-
getPoseEstimate
Gets the pose estimate of the given type from the newest frame. This getter can return the same frame many times, also after a disconnect. UsereadAcceptedPoseEstimates(Limelight.PoseEstimateType)for fusion. UsegetStatus()for current camera health.- Parameters:
type- Which pose estimate to produce
-
getPoseEstimate
public Limelight.PoseEstimate getPoseEstimate(Limelight.LimelightResults results, Limelight.PoseEstimateType type) Builds a pose estimate of the given type from one results envelope. Applies theLimelight.PoseEstimateConfigfor the algorithm of the estimate. Use this withreadResultsQueue()to get several estimate types (for example MT1 and MT2) from one queue read.- Parameters:
results- The envelope to build fromtype- Which pose estimate to produce
-
readResultsQueue
Decodes and returns every buffered results envelope received since the last queue read. The queue holds 20 frames. If more frames arrive between reads, the oldest frames are discarded. The newest frame also becomes the result ofgetLatestResults().Use only one queue reading method per camera. The queue reading methods are this method,
readPoseEstimateQueue(Limelight.PoseEstimateType),readAcceptedPoseEstimates(Limelight.PoseEstimateType), andreadRawFrameQueue(). To get several values from each frame, read the queue here one time. Then callgetPoseEstimate(LimelightResults, PoseEstimateType)for each frame. Other getters only read the newest frame. They do not consume the queue.- Returns:
- All buffered frames, oldest first. Empty if no new frame arrived
-
readPoseEstimateQueue
Reads every frame received since the last queue read. Returns one pose estimate of the given type for each frame. This lets your pose estimator use every vision update. CheckLimelight.PoseEstimate.isValid()on each estimate before you fuse it.This method consumes the queue. Do not use another queue reading method for this camera.
- Parameters:
type- Which pose estimate to produce for each frame- Returns:
- One pose estimate per frame, oldest first
-
readAcceptedPoseEstimates
Reads every frame received since the last queue read. Returns only the pose estimates that passed validation and filtering. Each queued frame is processed one time. The pose estimator decides if the timestamp is still in range.PoseEstimateType type = PoseEstimateType.MT2_WPIBLUE; for (PoseEstimate estimate : camera.readAcceptedPoseEstimates(type)) { poseEstimator.addVisionMeasurement( estimate.pose, estimate.timestampSeconds, estimate.stdDevs); }Telemetry shows the newest estimate and keeps rejection counters. Use
readPoseEstimateQueue(Limelight.PoseEstimateType)to inspect every rejected estimate.This method consumes the queue. Do not use another queue reading method for this camera.
- Parameters:
type- Which pose estimate to produce for each frame- Returns:
- The accepted estimates, oldest first. Empty if no new frame arrived or no estimate passed
-
getLatestRawFrame
public org.wpilib.networktables.TimestampedRaw getLatestRawFrame()Returns the newest raw results envelope without decoding it. The result has the MessagePack bytes and the NetworkTables receive timestamp in microseconds (local NetworkTables timebase). This method does not consume the frame queue. Use it withdecode(byte[], long)for logging and replay.- Returns:
- The newest raw frame. The value is empty if no frame has arrived
-
readRawFrameQueue
public org.wpilib.networktables.TimestampedRaw[] readRawFrameQueue()Reads every raw envelope received since the last queue read, without decoding. Use this for logging and replay systems. These systems record raw frames and decode them withdecode(byte[], long), live or from a log.This method consumes the queue. Do not use another queue reading method for this camera.
- Returns:
- All buffered raw frames, oldest first. Empty if no new frame arrived
-
getRobotPose
Returns the full 3D robot pose for the given estimate type.- Returns:
- The full 3D robot pose for the given estimate type. The type selects the origin and the algorithm
-
getCameraPose_RobotSpace
public org.wpilib.math.geometry.Pose3d getCameraPose_RobotSpace()Returns camera pose in robot space (meters, degrees) as a Pose3d.- Returns:
- Camera pose in robot space (meters, degrees) as a Pose3d
-
setPipelineIndex
public void setPipelineIndex(int pipelineIndex) Switches to the given pipeline.- Parameters:
pipelineIndex- Pipeline index (0-9)
-
setPipelineConfigurationOverride
Publishes a pipeline configuration override to this camera. Flushes NetworkTables immediately. The camera runs the override while it is enabled withsetUsePipelineConfigurationOverride(boolean). The ten pipelines on the camera do not change. You can switch between them and the override at any time.Create the
Limelight.PipelineConfigurationduring robot initialization. Publishing is only a NetworkTables write. It does not access the disk. You can switch between several prepared configurations during a match:// robotInit PipelineConfiguration aiming = Limelight.PipelineConfiguration.fromDeployFolder("aiming"); // whenever camera.setPipelineConfigurationOverride(aiming); camera.setUsePipelineConfigurationOverride(true);- Parameters:
config- The configuration to publish. The method ignores null or a configuration that is not valid and prints a warning
-
clearPipelineConfigurationOverride
public void clearPipelineConfigurationOverride()Clears the published pipeline configuration override. Flushes NetworkTables immediately. If the override was running, the camera returns immediately to the pipeline selected bysetPipelineIndex(int). Otherwise, it returns when the override is next disabled. -
setUsePipelineConfigurationOverride
public void setUsePipelineConfigurationOverride(boolean use) Enables or disables the pipeline configuration override. While enabled, the camera runs the pipeline published withsetPipelineConfigurationOverride(Limelight.PipelineConfiguration). While disabled, the camera runs the pipeline selected bysetPipelineIndex(int). The published override stays on the camera in both states. You can switch between the two at any time.- Parameters:
use- True to run the override. False to run the indexed pipeline
-
isPipelineConfigurationOverrideEnabled
public boolean isPipelineConfigurationOverrideEnabled()Reads back whether the camera runs the pipeline configuration override. The value comes from the latest results frame. It can differ from the value requested withsetUsePipelineConfigurationOverride(boolean). For example, the camera web interface can force the override off.- Returns:
- True if the camera reports that the override is running
-
getPipelineConfigurationOverrideState
Returns the camera's pipeline configuration override state from the latest results frame.- Returns:
- The camera's pipeline configuration override state from the latest results frame
-
setPriorityTagIDOverride
public void setPriorityTagIDOverride(int id) Sets the priority AprilTag ID for tx/ty targeting.- Parameters:
id- Priority tag ID
-
clearPriorityTagIDOverride
public void clearPriorityTagIDOverride()Clears the priority AprilTag ID override. tx/ty targeting returns to the target selection of the pipeline. -
setLEDMode
Sets the LED behavior. -
setCropWindowOverride
public void setCropWindowOverride(double cropXMin, double cropXMax, double cropYMin, double cropYMax) Sets the crop window. The crop window in the web interface must be fully open (as large as possible).- Parameters:
cropXMin- Minimum X value (-1 to 1)cropXMax- Maximum X value (-1 to 1)cropYMin- Minimum Y value (-1 to 1)cropYMax- Maximum Y value (-1 to 1)
-
clearCropWindowOverride
public void clearCropWindowOverride()Clears the crop window override, returning to the full image. -
setKeystoneOverride
public void setKeystoneOverride(double horizontal, double vertical) Sets the keystone modification for the crop window.- Parameters:
horizontal- Horizontal keystone value (-0.95 to 0.95)vertical- Vertical keystone value (-0.95 to 0.95)
-
clearKeystoneOverride
public void clearKeystoneOverride()Clears the keystone override. -
setFiducial3DOffsetOverride
public void setFiducial3DOffsetOverride(double forward, double left, double up) Moves the 3D targeting point away from the center of the primary in-view fiducial. The offset is in target space (the coordinate system of the target: x = forward, y = left, z = up).- Parameters:
forward- Forward (x) offset from the target in metersleft- Left (y) offset from the target in metersup- Up (z) offset from the target in meters
-
setFiducial3DOffsetOverride
public void setFiducial3DOffsetOverride(org.wpilib.math.geometry.Translation3d offset) Moves the 3D targeting point away from the center of the primary in-view fiducial. The offset is in target space (the coordinate system of the target). Same assetFiducial3DOffsetOverride(double, double, double)with a Translation3d.- Parameters:
offset- Offset from the target in meters (x = forward, y = left, z = up). Null is ignored
-
clearFiducial3DOffsetOverride
public void clearFiducial3DOffsetOverride()Clears the fiducial 3D offset override. The 3D targeting point returns to the center of the primary in-view fiducial. -
setRobotOrientation
public void setRobotOrientation(double yawDegrees, boolean flush) (ADVANCED) Sets the individual robot orientation of this camera for the MegaTag2 algorithm. Call this every loop. Most robots should usesetSharedRobotOrientation(double)instead. It updates every camera at one time.Every call makes this camera ignore the shared orientation from
setSharedRobotOrientation(double). UsesetUseSharedOrientation(boolean)to make it use the shared orientation again.- Parameters:
yawDegrees- Robot yaw in degrees.flush- True to flush NetworkTables immediately. Pass false when you update several cameras in one loop. Then callflushNT()one time.
-
setRobotOrientation
public void setRobotOrientation(double yaw, double yawRate, double pitch, double pitchRate, double roll, double rollRate, boolean flush) (ADVANCED) Sets the full individual robot orientation of this camera for the MegaTag2 algorithm. Every call makes this camera ignore the shared orientation (seesetUseSharedOrientation(boolean)).- Parameters:
yaw- Robot yaw in degrees.yawRate- (optional, may be 0) Angular velocity of robot yaw in degrees per secondpitch- (optional, may be 0) Robot pitch in degreespitchRate- (optional, may be 0) Angular velocity of robot pitch in degrees per secondroll- (optional, may be 0) Robot roll in degreesrollRate- (optional, may be 0) Angular velocity of robot roll in degrees per secondflush- True to flush NetworkTables immediately. Pass false when you update several cameras in one loop. Then callflushNT()one time.
-
setIMUMode
Configures the robot-yaw source for MegaTag2 localization. -
setIMUAssistAlpha
public void setIMUAssistAlpha(double alpha) Configures the complementary filter alpha for the IMU assist modes (modes 3 and 4).- Parameters:
alpha- Default .001. Higher values converge on the assist source faster.
-
setThrottle
public void setThrottle(int throttle) Configures the throttle value. The Limelight skipsthrottleframes between processed frames. Set 100-200 while the robot is disabled to reduce heat. UsewithStaleFrameThreshold(double)with this sogetStatus()does not report the camera as stale.- Parameters:
throttle- Default 0. The camera processes one frame, then skips this many frames.
-
setFiducialIDFiltersOverride
public void setFiducialIDFiltersOverride(int[] validIDs) Overrides the valid AprilTag IDs for localization. Tags not in this list are ignored for robot pose estimation. They do not get the "fielded" flag.- Parameters:
validIDs- Valid AprilTag IDs to track
-
clearFiducialIDFiltersOverride
public void clearFiducialIDFiltersOverride()Clears the AprilTag ID filter override. The camera returns to the ID filters of the pipeline. -
setFiducialDownscalingOverride
Overrides the AprilTag detector's downscaling factor. -
clearFiducialDownscalingOverride
public void clearFiducialDownscalingOverride()Clears the AprilTag downscaling override. The camera returns to the downscale configured in the current pipeline. -
setCameraPose_RobotSpaceOverride
public void setCameraPose_RobotSpaceOverride(double forward, double left, double up, double roll, double pitch, double yaw, boolean flush) Sets the camera pose relative to the robot. You can call this every loop. Use it to track a camera on a moving mechanism (elevator, turret). An all-zero pose is the clear value, so the camera returns to the pose from the web interface.- Parameters:
forward- Forward (x) offset in metersleft- Left (y) offset in metersup- Up (z) offset in metersroll- Roll angle in degreespitch- Pitch angle in degreesyaw- Yaw angle in degreesflush- True to flush NetworkTables immediately. Pass false when you update several cameras in one loop. Then callflushNT()one time.
-
setCameraPose_RobotSpaceOverride
public void setCameraPose_RobotSpaceOverride(org.wpilib.math.geometry.Pose3d cameraPoseRobotSpace, boolean flush) Sets the camera pose relative to the robot. The camera applies updates live. SeesetCameraPose_RobotSpaceOverride(double, double, double, double, double, double, boolean).- Parameters:
cameraPoseRobotSpace- The pose of the camera relative to the robot center (x = forward, y = left, z = up, in meters). Null is ignored. An all-zero pose is the clear valueflush- True to flush NetworkTables immediately. Pass false when you update several cameras in one loop. Then callflushNT()one time.
-
clearCameraPose_RobotSpaceOverride
public void clearCameraPose_RobotSpaceOverride()Clears the camera pose override. Flushes NetworkTables immediately. The camera returns to the camera pose configured in its web interface. -
setPythonScriptData
public void setPythonScriptData(double[] outgoingPythonData) Sends data to a running python snapscript via llrobot. -
triggerSnapshot
public void triggerSnapshot()Triggers a snapshot capture. The Limelight firmware rate-limits this. -
setRewindEnabled
public void setRewindEnabled(boolean enabled) Enables or pauses the rewind buffer recording.- Parameters:
enabled- True to enable recording. False to pause. Default true on supported platforms.
-
triggerRewindCapture
public void triggerRewindCapture(double durationSeconds) Triggers a rewind capture with the given duration. The maximum duration is 165 seconds. The camera rate-limits this.- Parameters:
durationSeconds- Duration of the rewind capture in seconds (maximum 165)
-
flushNT
public static void flushNT()Flushes NetworkTables immediately. These methods call it automatically: the pose-setting constructors,setSharedRobotOrientation(double),setPipelineConfigurationOverride(Limelight.PipelineConfiguration),clearPipelineConfigurationOverride(),setSharedMap(Limelight.FieldMap),clearSharedMap(),clearCameraPose_RobotSpaceOverride(), andsetRobotOrientation(double, boolean)/setCameraPose_RobotSpaceOverride(double, double, double, double, double, double, boolean)when their flush argument is true. The other setters and clear methods do not flush. Call it yourself after a group of them. -
toPose3D
public static org.wpilib.math.geometry.Pose3d toPose3D(double[] inData) Converts a pose array to a Pose3d. The array has 6 values: [x, y, z, roll, pitch, yaw]. Units are meters and degrees.- Returns:
- The pose. Returns an empty Pose3d if the array is not valid
-
toPose2D
public static org.wpilib.math.geometry.Pose2d toPose2D(double[] inData) Converts a pose array to a Pose2d. The array has 6 values: [x, y, z, roll, pitch, yaw]. Units are meters and degrees. Uses only the x, y, and yaw values.- Returns:
- The pose. Returns an empty Pose2d if the array is not valid
-