Class LimelightSim
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 Summary
ConstructorsConstructorDescriptionLimelightSim(Limelight limelight) Construct aLimelightSimfor the givenLimelightusing default camera settings, the current season's AprilTag field layout and no robot-to-camera offset.LimelightSim(Limelight limelight, LimelightSimSettings settings) Construct aLimelightSimfor the givenLimelight. -
Method Summary
Modifier and TypeMethodDescriptionvoidUpdate the simulatedLimelightwith the robot's current pose, projecting visible AprilTags and publishing the resulting NetworkTables data.voidUpdate the simulatedLimelightwith the robot's current pose, projecting visible AprilTags and publishing the resulting NetworkTables data.withAprilTagFieldLayout(AprilTagFieldLayout fieldLayout) Override the AprilTag field layout used to source simulated targets.withField2d(Field2d field2d) Set theField2dused to visualize simulated AprilTag raycasts.withRobotToCameraTransform(Transform3d robotToCamera) Set the transform from the robot's origin to the camera's lens.withSettings(LimelightSimSettings settings) Set the camera properties/noise/latency configuration.
-
Constructor Details
-
LimelightSim
Construct aLimelightSimfor the givenLimelightusing default camera settings, the current season's AprilTag field layout and no robot-to-camera offset.- Parameters:
limelight-Limelightto simulate.
-
LimelightSim
Construct aLimelightSimfor the givenLimelight.- Parameters:
limelight-Limelightto simulate.settings- Camera settings to use.
-
-
Method Details
-
withRobotToCameraTransform
Set the transform from the robot's origin to the camera's lens. Equivalent in effect toLimelightSettings.withCameraOffset(Pose3d)on real hardware.- Parameters:
robotToCamera- Transform from the robot origin to the camera.- Returns:
LimelightSimfor chaining.
-
withAprilTagFieldLayout
Override the AprilTag field layout used to source simulated targets. Defaults to the current season's official field.- Parameters:
fieldLayout-AprilTagFieldLayoutto use.- Returns:
LimelightSimfor chaining.
-
withField2d
Set theField2dused to visualize simulated AprilTag raycasts.The simulator does not set the built-in robot pose on the
Field2d. Instead, it creates a singleFieldObject2dnamed"Limelight Raycasts"containing the path:robot -> tag1 -> robot -> tag2 -> robot -> ...
If
nullis supplied, visualization is disabled and any existing raycast path is cleared.- Parameters:
field2d-Field2dto draw the raycasts on.- Returns:
LimelightSimfor chaining.
-
withSettings
Set the camera properties/noise/latency configuration.- Parameters:
settings-LimelightSimSettingsto use.- Returns:
LimelightSimfor chaining.
-
update
Update the simulatedLimelightwith the robot's current pose, projecting visible AprilTags and publishing the resulting NetworkTables data. Call this periodically, typically fromRobot#simulationPeriodic().No-op if not running in simulation.
- Parameters:
robotPoseMeters- Ground-truth robot pose, in meters.
-
update
Update the simulatedLimelightwith the robot's current pose, projecting visible AprilTags and publishing the resulting NetworkTables data. Call this periodically, typically fromRobot#simulationPeriodic().No-op if not running in simulation.
- Parameters:
robotPose- Ground-truth robot pose, in meters.
-