Package limelight.sim

Class LimelightSim

java.lang.Object
limelight.sim.LimelightSim

public class LimelightSim extends Object
Simulates a Limelight running the AprilTag/fiducial pipeline, publishing to the same NetworkTables keys a real Limelight would populate ("tx", "ty", "ta", "tv", "tid", "botpose*", "rawfiducials", "t2d", "targetpose_*"/"camerapose_*"/"botpose_targetspace", "tl"/"cl"/"getpipe"/"getpipetype", "json", ...) so that code written against LimelightData, LimelightTargetData and LimelightPoseEstimator behaves the same in simulation as on real hardware.

Minimal usage:


 Limelight limelight = new Limelight("limelight");
 LimelightSim limelightSim = new LimelightSim(limelight);

 // Optional Field2d visualization:
 limelightSim.withField2d(field);

 // in Robot#simulationPeriodic()
 limelightSim.update(drivebase.getPose());
 
By default the current season's official AprilTag field is used and the camera is assumed to be mounted at the robot's origin. Call withRobotToCameraTransform(Transform3d) and/or withSettings(LimelightSimSettings) to refine it.

The overall approach (a per camera simulation object that is fed the ground truth robot pose every loop and projects field targets into a simple pinhole camera model to publish simulated NetworkTables output) is modeled after PhotonVision's VisionSystemSim/PhotonCameraSim simulation classes. Credit to the PhotonVision project for that design; this implementation is a from scratch, self contained port of the idea onto the Limelight NetworkTables schema and does not depend on PhotonVision at runtime.

Implementation Note:
Only the fiducial/AprilTag pipeline is simulated (retroreflective, neural classifier/detector and barcode pipelines are not). Robot pose and tag geometry are known exactly by the simulator, so rather than re-deriving a pose estimate via solvePnP like the real Limelight firmware does, the published botpose values are the ground truth robot pose with configurable Gaussian noise applied. This is an approximation, not a physically derived uncertainty model.
  • Constructor Details

  • Method Details

    • withRobotToCameraTransform

      public LimelightSim withRobotToCameraTransform(Transform3d robotToCamera)
      Set the transform from the robot's origin to the camera's lens. Equivalent in effect to LimelightSettings.withCameraOffset(Pose3d) on real hardware.
      Parameters:
      robotToCamera - Transform from the robot origin to the camera.
      Returns:
      LimelightSim for chaining.
    • withAprilTagFieldLayout

      public LimelightSim withAprilTagFieldLayout(AprilTagFieldLayout fieldLayout)
      Override the AprilTag field layout used to source simulated targets. Defaults to the current season's official field.
      Parameters:
      fieldLayout - AprilTagFieldLayout to use.
      Returns:
      LimelightSim for chaining.
    • withField2d

      public LimelightSim withField2d(Field2d field2d)
      Set the Field2d used to visualize simulated AprilTag raycasts.

      The simulator does not set the built-in robot pose on the Field2d. Instead, it creates a single FieldObject2d named "Limelight Raycasts" containing the path:

       robot -> tag1 -> robot -> tag2 -> robot -> ...
       

      If null is supplied, visualization is disabled and any existing raycast path is cleared.

      Parameters:
      field2d - Field2d to draw the raycasts on.
      Returns:
      LimelightSim for chaining.
    • withSettings

      public LimelightSim withSettings(LimelightSimSettings settings)
      Set the camera properties/noise/latency configuration.
      Parameters:
      settings - LimelightSimSettings to use.
      Returns:
      LimelightSim for chaining.
    • update

      public void update(Pose2d robotPoseMeters)
      Update the simulated Limelight with the robot's current pose, projecting visible AprilTags and publishing the resulting NetworkTables data. Call this periodically, typically from Robot#simulationPeriodic().

      No-op if not running in simulation.

      Parameters:
      robotPoseMeters - Ground-truth robot pose, in meters.
    • update

      public void update(Pose3d robotPose)
      Update the simulated Limelight with the robot's current pose, projecting visible AprilTags and publishing the resulting NetworkTables data. Call this periodically, typically from Robot#simulationPeriodic().

      No-op if not running in simulation.

      Parameters:
      robotPose - Ground-truth robot pose, in meters.