Class PhotonCamera

java.lang.Object
org.photonvision.PhotonCamera
All Implemented Interfaces:
AutoCloseable

public class PhotonCamera extends Object implements AutoCloseable
Represents a camera that is connected to PhotonVision.
  • Field Details

  • Constructor Details

    • PhotonCamera

      public PhotonCamera(NetworkTableInstance instance, String cameraName)
      Constructs a PhotonCamera from a root table.
      Parameters:
      instance - The NetworkTableInstance to pull data from. This can be a custom instance in simulation, but should *usually* be the default NTInstance from NetworkTableInstance::getDefault
      cameraName - The name of the camera, as seen in the UI.
    • PhotonCamera

      public PhotonCamera(String cameraName)
      Constructs a PhotonCamera from the name of the camera.
      Parameters:
      cameraName - The nickname of the camera (found in the PhotonVision UI).
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • setVersionCheckEnabled

      public static void setVersionCheckEnabled(boolean enabled)
    • getAllUnreadResults

      public List<PhotonPipelineResult> getAllUnreadResults()
      The list of pipeline results sent by PhotonVision since the last call to getAllUnreadResults(). Calling this function clears the internal FIFO queue, and multiple calls to getAllUnreadResults() will return different (potentially empty) result arrays. Be careful to call this exactly ONCE per loop of your robot code! FIFO depth is limited to 20 changes, so make sure to call this frequently enough to avoid old results being discarded, too!
    • getLatestResult

      @Deprecated(since="2024", forRemoval=true) public PhotonPipelineResult getLatestResult()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the latest pipeline result. This is simply the most recent result Received via NT. Calling this multiple times will always return the most recent result.

      Replaced by getAllUnreadResults() over getLatestResult, as this function can miss results, or provide duplicate ones!

    • getDriverMode

      public boolean getDriverMode()
      Returns whether the camera is in driver mode.
      Returns:
      Whether the camera is in driver mode.
    • setDriverMode

      public void setDriverMode(boolean driverMode)
      Toggles driver mode.
      Parameters:
      driverMode - Whether to set driver mode.
    • takeInputSnapshot

      public void takeInputSnapshot()
      Request the camera to save a new image file from the input camera stream with overlays. Images take up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk space and eventually cause the system to stop working. Clear out images in /opt/photonvision/photonvision_config/imgSaves frequently to prevent issues.
    • takeOutputSnapshot

      public void takeOutputSnapshot()
      Request the camera to save a new image file from the output stream with overlays. Images take up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk space and eventually cause the system to stop working. Clear out images in /opt/photonvision/photonvision_config/imgSaves frequently to prevent issues.
    • getPipelineIndex

      public int getPipelineIndex()
      Returns the active pipeline index.
      Returns:
      The active pipeline index.
    • setPipelineIndex

      public void setPipelineIndex(int index)
      Allows the user to select the active pipeline index.
      Parameters:
      index - The active pipeline index.
    • getLEDMode

      public VisionLEDMode getLEDMode()
      Returns the current LED mode.
      Returns:
      The current LED mode.
    • setLED

      public void setLED(VisionLEDMode led)
      Sets the LED mode.
      Parameters:
      led - The mode to set to.
    • getName

      public String getName()
      Returns the name of the camera. This will return the same value that was given to the constructor as cameraName.
      Returns:
      The name of the camera.
    • isConnected

      public boolean isConnected()
      Returns whether the camera is connected and actively returning new data. Connection status is debounced.
      Returns:
      True if the camera is actively sending frame data, false otherwise.
    • getCameraMatrix

      public Optional<Matrix<N3,N3>> getCameraMatrix()
    • getDistCoeffs

      public Optional<Matrix<N8,N1>> getDistCoeffs()
      The camera calibration's distortion coefficients, in OPENCV8 form. Higher-order terms are set to 0
    • getCameraTable

      public final NetworkTable getCameraTable()
      Gets the NetworkTable representing this camera's subtable. You probably don't ever need to call this.