VisionSystem

class VisionSystem : SubsystemBase

The VisionSystem subsystem manages multiple vision cameras for robot pose estimation and target tracking.

Supports multi-camera fusion, automatic pose updates, and provides methods for accessing vision data from all connected cameras. Works with any camera implementing the Camera interface.

Usage Example:

val visionSystem = VisionSystem()

visionSystem.configure {
enablePoseUpdates = true
maxPoseAmbiguity = 0.2
}

// Add cameras
val frontCamera = PhotonModule(...)
val limelight = LimeModule("limelight")
visionSystem.addCamera(frontCamera)
visionSystem.addCamera(limelight)

// Set the pose estimator to update (typically your SwerveDrive)
visionSystem.setPoseEstimator { pose, timestamp, stdDevs ->
swerveDrive.addVisionMeasurement(pose, timestamp, stdDevs)
}

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
data class Config(var enablePoseUpdates: Boolean = true, var enableLogging: Boolean = true, var maxPoseAmbiguity: Double = 0.2, var minTargetsForPose: Int = 1, var rejectOutlierPoses: Boolean = true, var maxPoseDistance: Distance = Units.Meters.of(2.0))

Configuration for the vision system.

Properties

Link copied to clipboard
open val currentCommand: Command?
Link copied to clipboard
open var defaultCommand: Command?
Link copied to clipboard
open var name: String?
Link copied to clipboard
open var subsystem: String?

Functions

Link copied to clipboard
fun addCamera(camera: Camera)

Adds a camera to the vision system.

Link copied to clipboard
open fun addChild(name: String?, child: Sendable?)
Link copied to clipboard

Adds a Limelight camera module to the vision system.

Link copied to clipboard

Adds a PhotonVision camera module to the vision system.

Link copied to clipboard

Configures the vision system using a DSL-style configuration block.

Link copied to clipboard
open fun defer(supplier: Supplier<Command?>?): Command?
Link copied to clipboard

Gets the best available vision measurement from all cameras.

Link copied to clipboard
fun getCamera(name: String): Camera?

Gets a camera by name.

Link copied to clipboard

Gets all cameras.

Link copied to clipboard

Gets a Limelight camera module by name.

Link copied to clipboard

Gets all Limelight camera modules.

Link copied to clipboard

Gets a PhotonVision camera module by name.

Link copied to clipboard

Gets all PhotonVision camera modules.

Link copied to clipboard

Gets the number of visible targets across all cameras.

Link copied to clipboard

Checks if any camera currently sees a target.

Link copied to clipboard
open fun idle(): Command?
Link copied to clipboard
open fun initSendable(builder: SendableBuilder?)
Link copied to clipboard
open override fun periodic()
Link copied to clipboard
open fun register()
Link copied to clipboard
Link copied to clipboard
open fun run(action: Runnable?): Command?
Link copied to clipboard
open fun runEnd(run: Runnable?, end: Runnable?): Command?
Link copied to clipboard
open fun runOnce(action: Runnable?): Command?
Link copied to clipboard

Sets all Limelight LEDs to a specific mode.

Link copied to clipboard

Sets all Limelight pipelines.

Link copied to clipboard
fun setCurrentPoseSupplier(supplier: () -> Pose2d)

Sets a supplier for getting the current robot pose.

Link copied to clipboard

Enables or disables automatic pose updates.

Link copied to clipboard
fun setPoseEstimator(callback: (Pose2d, Time, Matrix<N3, N1>) -> Unit)

Sets the callback function for updating the robot's pose estimator.

Link copied to clipboard
Link copied to clipboard
open fun startEnd(start: Runnable?, end: Runnable?): Command?
Link copied to clipboard
open fun startRun(start: Runnable?, run: Runnable?): Command?