PhotonModule

class PhotonModule(cameraName: String, val cameraPos: Transform3d, fieldLayout: AprilTagFieldLayout) : Camera

The PhotonModule class represents a single PhotonVision camera setup with its associated PhotonPoseEstimator and position information.

Integrates with WPILib 2026 vision estimation APIs for improved pose accuracy. Implements the Camera interface for unified vision system integration.

Usage Example:

val camera = PhotonModule(
cameraName = "frontCamera",
cameraPos = Transform3d(Translation3d(0.3, 0.0, 0.2), Rotation3d(0.0, Math.toRadians(-15.0), 0.0)),
fieldLayout = AprilTagFields.k2024Crescendo.loadAprilTagLayoutField()
)

// Get latest measurement
val measurement = camera.getLatestMeasurement()
measurement?.let {
swerveDrive.addVisionMeasurement(it.pose, it.timestampSeconds, it.stdDevs)
}

Constructors

Link copied to clipboard
constructor(cameraName: String, cameraPos: Transform3d, fieldLayout: AprilTagFieldLayout)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val cameraPos: Transform3d

The position of the camera relative to robot center as a Transform3d.

Link copied to clipboard
var currentStdDevs: Matrix<N3, N1>

The current standard deviations for pose estimation as a Matrix.

Link copied to clipboard
open override val name: String

The name of this camera.

Functions

Link copied to clipboard

Gets all unprocessed vision measurements since the last call.

Link copied to clipboard
fun getAllUnreadResults(): List<PhotonPipelineResult>

Gets all unread PhotonPipelineResults from the PhotonCamera.

Link copied to clipboard
open override fun getDistanceToTag(tagId: Int?): Distance?

Gets the distance to a tag.

Link copied to clipboard
open override fun getLatestMeasurement(referencePose: Pose2d?): VisionMeasurement?

Gets the latest vision measurement from the camera.

Link copied to clipboard
fun getLatestResult(): PhotonPipelineResult

Gets the latest PhotonPipelineResult from the camera.

Link copied to clipboard
open override fun getTargetHorizontalOffset(): Angle?

Gets the horizontal offset to the currently tracked target.

Link copied to clipboard
open override fun getTargetVerticalOffset(): Angle?

Gets the vertical offset to the currently tracked target.

Link copied to clipboard
open override fun hasTarget(): Boolean

Checks if the camera currently sees any valid targets.

Link copied to clipboard
fun updateEstimatedStdDevs(result: PhotonPipelineResult, estimatedPose: EstimatedRobotPose?, singleTargetVector: Matrix<N3, N1> = DEFAULT_SINGLE_TARGET_STD_DEVS, multiTargetVector: Matrix<N3, N1> = DEFAULT_MULTI_TARGET_STD_DEVS)

Updates the estimated standard deviations based on the provided result.