Class VisionSim
java.lang.Object
yall.sim.VisionSim
The simulated world every simulated
VisionCamera sees, whatever its vendor. It is
PhotonVision's VisionSystemSim: each camera projects the field's AprilTags (and any extra
targets) through a simulated lens, with noise and latency.
Cameras join getDefault() unless their config names another world. Update the world
once per loop with the robot's true pose:
public void simulationPeriodic() {
VisionSim.getDefault().update(drivetrainSim.getPose());
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCamera(org.photonvision.simulation.PhotonCameraSim cameraSim, Transform3d robotToCamera) Adds a simulated camera.voidaddVisionTargets(String type, org.photonvision.simulation.VisionTargetSim... targets) Adds targets other than the field's AprilTags, such as game pieces for object detection: useVisionTargetSim(Pose3d, org.photonvision.estimation.TargetModel, int, float)with a class ID.voidadjustCamera(org.photonvision.simulation.PhotonCameraSim cameraSim, Transform3d robotToCamera) Moves a simulated camera, for a camera on a turret or other mechanism.applyFieldTagJitter(Pose3d pose) Applies configured Gaussian X/Y field-tag placement jitter to a simulated robot pose.voidClears any active blackout, stochastic dropout probability, and field-tag jitter.static org.photonvision.simulation.PhotonCameraSimcreateCameraSim(String name, VisionCameraConfig config, CameraModel defaultModel, org.photonvision.PhotonCamera camera) Makes the PhotonVision simulation of a camera and adds it to the camera's world (the config's, orgetDefault()), if the robot program runs in simulation and the config allows it.Optional<org.photonvision.simulation.PhotonCameraSim> getCameraSim(String name) Finds a simulated camera by its PhotonVision name.A field drawing of the simulated robot, cameras and the targets they see.static VisionSimThe world cameras join when their config doesn't name one.getField()The field whose AprilTags the cameras see.org.photonvision.simulation.VisionSystemSimThe PhotonVision simulation underneath, for settings YALL doesn't cover.injectBlackout(double currentTimeSeconds, Time duration) Injects a deterministic camera blackout lastingdurationstarting atcurrentTimeSeconds.booleanisBlackedOut(double nowSeconds) Whether this simulated world is currently in an injected blackout window atnowSeconds.static StringprivateCameraName(String cameraName) Name of the private PhotonVision camera made for a camera that isn't a PhotonVision camera.voidremoveCamera(org.photonvision.simulation.PhotonCameraSim cameraSim) Removes a simulated camera.voidremoveVisionTargets(String type) Removes a group of targets added withaddVisionTargets(String, VisionTargetSim...).voidresetRobotPose(Pose2d robotPose) Moves the simulated robot without processing frames, for example when resetting the robot pose.static voidsetDefault(VisionSim sim) Replaces the default world, for example to use another field.booleanshouldDropFrame(double nowSeconds) Evaluates whether a simulated frame arriving atnowSecondsshould be dropped due to an active blackout or stochastic dropout probability.voidMoves the simulated robot and processes a frame on each camera that is due one.voidMoves the simulated robot and processes a frame on each camera that is due one.withDropoutProbability(double probability, long seed) Configures deterministic per-frame stochastic dropout probability for simulated cameras.withFieldTagJitter(Distance stdDev, long seed) Configures Gaussian X/Y field-tag placement jitter (for example,Millimeters.of(13)to model Welded vs.
-
Constructor Details
-
VisionSim
-
-
Method Details
-
getDefault
The world cameras join when their config doesn't name one. It holds the AprilTags of WPILib'sFields.DEFAULT_FIELD.- Returns:
- The default world.
-
setDefault
Replaces the default world, for example to use another field. Call it before creating cameras.- Parameters:
sim- The new default world.
-
createCameraSim
public static org.photonvision.simulation.PhotonCameraSim createCameraSim(String name, VisionCameraConfig config, CameraModel defaultModel, org.photonvision.PhotonCamera camera) Makes the PhotonVision simulation of a camera and adds it to the camera's world (the config's, orgetDefault()), if the robot program runs in simulation and the config allows it. Camera wrappers call this; robot code doesn't need to.- Parameters:
name- Name of the camera.config- The camera's config.defaultModel- Camera to simulate when the config sets no camera properties.camera- PhotonVision camera the simulation publishes to, or null to make a private one namedYALL-<name>.- Returns:
- The simulated camera, or null when not simulating.
-
privateCameraName
-
addCamera
public void addCamera(org.photonvision.simulation.PhotonCameraSim cameraSim, Transform3d robotToCamera) Adds a simulated camera.VisionCameracalls this; teams don't need to.- Parameters:
cameraSim- The simulated camera.robotToCamera- Where the camera is on the robot.
-
removeCamera
public void removeCamera(org.photonvision.simulation.PhotonCameraSim cameraSim) Removes a simulated camera.- Parameters:
cameraSim- The simulated camera.
-
adjustCamera
public void adjustCamera(org.photonvision.simulation.PhotonCameraSim cameraSim, Transform3d robotToCamera) Moves a simulated camera, for a camera on a turret or other mechanism.- Parameters:
cameraSim- The simulated camera.robotToCamera- Where the camera is on the robot now.
-
addVisionTargets
Adds targets other than the field's AprilTags, such as game pieces for object detection: useVisionTargetSim(Pose3d, org.photonvision.estimation.TargetModel, int, float)with a class ID.- Parameters:
type- Name of the group of targets, for the debug field.targets- The targets.
-
removeVisionTargets
Removes a group of targets added withaddVisionTargets(String, VisionTargetSim...).- Parameters:
type- Name of the group.
-
update
Moves the simulated robot and processes a frame on each camera that is due one.- Parameters:
robotPose- The robot's true pose.
-
update
Moves the simulated robot and processes a frame on each camera that is due one.- Parameters:
robotPose- The robot's true pose.
-
resetRobotPose
Moves the simulated robot without processing frames, for example when resetting the robot pose.- Parameters:
robotPose- The robot's new true pose.
-
getDebugField
A field drawing of the simulated robot, cameras and the targets they see.- Returns:
- The debug field.
-
getField
-
getVisionSystemSim
public org.photonvision.simulation.VisionSystemSim getVisionSystemSim()The PhotonVision simulation underneath, for settings YALL doesn't cover.- Returns:
- PhotonVision's vision system simulation.
-
getCameraSim
-
injectBlackout
Injects a deterministic camera blackout lastingdurationstarting atcurrentTimeSeconds. Useful for testing vision-loss fallback and recovery in simulation.- Parameters:
currentTimeSeconds- Current monotonic simulation timestamp in seconds.duration- Blackout duration (must be non-negative).- Returns:
- This simulated world, for chaining.
-
isBlackedOut
public boolean isBlackedOut(double nowSeconds) Whether this simulated world is currently in an injected blackout window atnowSeconds.- Parameters:
nowSeconds- Current monotonic timestamp in seconds.- Returns:
- true if frames should be suppressed at
nowSeconds.
-
withDropoutProbability
Configures deterministic per-frame stochastic dropout probability for simulated cameras.- Parameters:
probability- Per-frame drop probability in[0.0, 1.0].seed- Deterministic RNG seed for reproducible CI runs.- Returns:
- This simulated world, for chaining.
-
withFieldTagJitter
Configures Gaussian X/Y field-tag placement jitter (for example,Millimeters.of(13)to model Welded vs. AndyMark AprilTag field tolerances) applied to simulated pose estimates.- Parameters:
stdDev- Standard deviation of X and Y pose jitter (zero disables jitter).seed- Deterministic RNG seed for reproducible CI runs.- Returns:
- This simulated world, for chaining.
-
clearFaults
public void clearFaults()Clears any active blackout, stochastic dropout probability, and field-tag jitter. -
shouldDropFrame
public boolean shouldDropFrame(double nowSeconds) Evaluates whether a simulated frame arriving atnowSecondsshould be dropped due to an active blackout or stochastic dropout probability.- Parameters:
nowSeconds- Current monotonic timestamp in seconds.- Returns:
- true if the simulated frame should be dropped.
-
applyFieldTagJitter
-