Class VisionCameraConfig

java.lang.Object
yall.VisionCameraConfig

public class VisionCameraConfig extends Object
Settings shared by every VisionCamera, whatever the vendor.
VisionCameraConfig config = new VisionCameraConfig()
    .withRobotToCamera(Inches.of(12), Inches.of(0), Inches.of(10),
                       Degrees.of(0), Degrees.of(-15), Degrees.of(0))
    .withPoseEstimationMode(PoseEstimationMode.HEADING_ASSISTED)
    .withPoseFilter(new VisionPoseFilter().withMaxAmbiguity(0.15));

Vendor settings that YALL doesn't cover go through withVendorConfig(Object), or straight to the vendor object from VisionCamera.getCamera().

  • Constructor Details

    • VisionCameraConfig

      public VisionCameraConfig()
      Creates a config with the defaults: no camera offset, the current season's field.
  • Method Details

    • withRobotToCamera

      public VisionCameraConfig withRobotToCamera(Transform3d robotToCamera)
      Sets where the camera is on the robot. Pose estimates, simulation and Synapse's robot pose all need it. On a Limelight it overrides the camera pose set in the web interface.
      Parameters:
      robotToCamera - Transform from the robot origin to the camera lens.
      Returns:
      This config, for chaining.
    • withRobotToCamera

      public VisionCameraConfig withRobotToCamera(Distance forward, Distance left, Distance up, Angle roll, Angle pitch, Angle yaw)
      Sets where the camera is on the robot, measured from the robot's center on the floor. The arguments follow the order of Limelight's own camera pose: forward, left, up, then roll, pitch, yaw.
      config.withRobotToCamera(
          Inches.of(12), Inches.of(0), Inches.of(10), // 12" forward, centered, 10" up
          Degrees.of(0), Degrees.of(-15), Degrees.of(0)); // tilted 15° up
      
      Parameters:
      forward - Distance forward of the robot center. Negative is behind it.
      left - Distance left of the robot center. Negative is right of it.
      up - Height above the floor.
      roll - Rotation about the camera's forward axis, counterclockwise positive.
      pitch - Rotation about the left axis. Negative tilts the camera up.
      yaw - Rotation about the up axis, counterclockwise positive. 180° faces backward.
      Returns:
      This config, for chaining.
      See Also:
    • withField

      public VisionCameraConfig withField(Field field)
      Sets the field, which holds the AprilTag layout. Defaults to WPILib's Fields.DEFAULT_FIELD.
      Parameters:
      field - The field.
      Returns:
      This config, for chaining.
    • withPoseEstimationMode

      public VisionCameraConfig withPoseEstimationMode(PoseEstimationMode mode)
      Sets how AprilTags become a robot pose. Defaults to PoseEstimationMode.TAGS_ONLY.
      Parameters:
      mode - The pose estimation mode.
      Returns:
      This config, for chaining.
    • withPoseFilter

      public VisionCameraConfig withPoseFilter(VisionPoseFilter filter)
      Sets the filter that accepts or rejects pose estimates and weighs them. Defaults to a new VisionPoseFilter, which has every standard check on.
      Parameters:
      filter - The filter.
      Returns:
      This config, for chaining.
    • withPipelineIndex

      public VisionCameraConfig withPipelineIndex(int index)
      Sets the pipeline to switch to when the camera is created.
      Parameters:
      index - Pipeline index.
      Returns:
      This config, for chaining.
    • withCameraProperties

      public VisionCameraConfig withCameraProperties(org.photonvision.simulation.SimCameraProperties properties)
      Sets the camera's resolution, field of view, frame rate, latency and noise. Simulation uses them, and Synapse uses them to turn pixel positions into angles. Each vendor wrapper has a default; withCameraModel(CameraModel) sets them from a camera's published specs.
      Parameters:
      properties - PhotonVision camera properties.
      Returns:
      This config, for chaining.
    • withCameraModel

      public VisionCameraConfig withCameraModel(CameraModel model)
      Sets the camera's resolution, field of view and frame rate from a camera's published specs. Use the model that matches the real camera, so simulation sees what it would.
      Parameters:
      model - The camera model.
      Returns:
      This config, for chaining.
    • withCameraProperties

      public VisionCameraConfig withCameraProperties(int widthPixels, int heightPixels, Angle diagonalFov, Frequency frameRate)
      Sets the camera's resolution and diagonal field of view, keeping the rest of the default camera properties.
      Parameters:
      widthPixels - Image width.
      heightPixels - Image height.
      diagonalFov - Diagonal field of view.
      frameRate - Frame rate.
      Returns:
      This config, for chaining.
    • withSimulation

      public VisionCameraConfig withSimulation(boolean enabled)
      Sets whether the camera gives simulated results when the robot program runs in simulation. Defaults to true.
      Parameters:
      enabled - true to simulate.
      Returns:
      This config, for chaining.
    • withSimulation

      public VisionCameraConfig withSimulation(VisionSim sim)
      Sets the simulated world the camera belongs to. Defaults to VisionSim.getDefault().
      Parameters:
      sim - The simulated world.
      Returns:
      This config, for chaining.
    • withSimulatedVideoStreams

      public VisionCameraConfig withSimulatedVideoStreams(boolean enabled)
      Sets whether the simulated camera streams what it would see: PhotonVision draws the AprilTags (and, with withSimulatedWireframe(boolean), the field) from the camera's point of view. The streams cost CPU, so they default to off.

      The streams are served by WPILib's CameraServer as YALL-<camera name>-raw and YALL-<camera name>-processed (<camera name>-raw and -processed for a PhotonVision camera). Open them in a dashboard's camera stream widget, or in a browser at http://localhost:1181, 1182 and up, one port per stream in the order they were made.

      Parameters:
      enabled - true to stream raw and processed simulated video.
      Returns:
      This config, for chaining.
    • withSimulatedWireframe

      public VisionCameraConfig withSimulatedWireframe(boolean enabled)
      Sets whether the simulated video streams also draw the field's floor and walls, which helps to see where the camera points. Drawing them costs more CPU than the AprilTags alone, so it defaults to off. Has no effect unless withSimulatedVideoStreams(boolean) is on.
      Parameters:
      enabled - true to draw the field.
      Returns:
      This config, for chaining.
    • withVendorConfig

      public VisionCameraConfig withVendorConfig(Object vendorConfig)
      Passes a vendor config object to the camera, as YAMS does for motor controllers. Each wrapper documents the types it accepts and throws IllegalArgumentException for others.
      Parameters:
      vendorConfig - Vendor config object.
      Returns:
      This config, for chaining.
    • withTelemetry

      public VisionCameraConfig withTelemetry(boolean enabled)
      Sets whether the camera publishes telemetry to NetworkTables, with the default VisionTelemetryConfig: every TelemetryVerbosity.MID field under YALL/<camera name>. Defaults to true.
      Parameters:
      enabled - true to publish.
      Returns:
      This config, for chaining.
    • withTelemetry

      public VisionCameraConfig withTelemetry(VisionTelemetryConfig telemetryConfig)
      Sets what the camera publishes to NetworkTables and logs to a DataLog, and where.
      Parameters:
      telemetryConfig - What to publish, or null to publish nothing.
      Returns:
      This config, for chaining.
    • getRobotToCamera

      public Optional<Transform3d> getRobotToCamera()
      Transform from the robot origin to the camera.
      Returns:
      The transform, if set.
    • getField

      public Field getField()
      The field holding the AprilTag layout.
      Returns:
      The configured field, or Fields.DEFAULT_FIELD.
    • getPoseEstimationMode

      public PoseEstimationMode getPoseEstimationMode()
      How AprilTags become a robot pose.
      Returns:
      The pose estimation mode.
    • getPoseFilter

      public VisionPoseFilter getPoseFilter()
      The pose estimate filter.
      Returns:
      The filter.
    • getPipelineIndex

      public Optional<Integer> getPipelineIndex()
      Pipeline to switch to on creation.
      Returns:
      The pipeline index, if set.
    • getCameraProperties

      public Optional<org.photonvision.simulation.SimCameraProperties> getCameraProperties()
      Camera properties.
      Returns:
      The properties, if set.
    • isSimulationEnabled

      public boolean isSimulationEnabled()
      Whether the camera is simulated in simulation.
      Returns:
      true to simulate.
    • getVisionSim

      public Optional<VisionSim> getVisionSim()
      The simulated world.
      Returns:
      The world, if set.
    • isSimulatedVideoStreamsEnabled

      public boolean isSimulatedVideoStreamsEnabled()
      Whether the simulated camera streams video.
      Returns:
      true to stream.
    • isSimulatedWireframeEnabled

      public boolean isSimulatedWireframeEnabled()
      Whether the simulated video streams draw the field.
      Returns:
      true to draw the field.
    • getVendorConfig

      public Optional<Object> getVendorConfig()
      Vendor config object.
      Returns:
      The object, if set.
    • isTelemetryEnabled

      public boolean isTelemetryEnabled()
      Whether the camera publishes telemetry.
      Returns:
      true to publish.
    • getTelemetryConfig

      public Optional<VisionTelemetryConfig> getTelemetryConfig()
      What the camera publishes to NetworkTables.
      Returns:
      The telemetry config, or empty to publish nothing.