1717import com .revrobotics .CANSparkMaxLowLevel ;
1818import com .revrobotics .SparkMaxPIDController ;
1919
20+ import edu .wpi .first .cameraserver .CameraServer ;
21+ import edu .wpi .first .cscore .UsbCamera ;
22+ import edu .wpi .first .cscore .VideoSource .ConnectionStrategy ;
2023import edu .wpi .first .wpilibj .RobotBase ;
2124import frc .robot .lib .MotorErrors .TemperatureLimit ;
2225import frc .robot .lib .sim .MockSparkMax ;
@@ -116,4 +119,32 @@ public static CANCoder createCANCoder(int port) {
116119 if (RobotBase .isSimulation ()) new MockedCANCoder (canCoder );
117120 return canCoder ;
118121 }
122+
123+ /**
124+ * Configures a USB Camera.
125+ * See {@link CameraServer#startAutomaticCapture} for more details.
126+ * This MUST be called AFTER AHRS initialization or the code will be unable to connect to the gyro.
127+ *
128+ * @return The configured camera
129+ */
130+ public static UsbCamera configureCamera () {
131+ UsbCamera camera = CameraServer .startAutomaticCapture ();
132+ camera .setConnectionStrategy (ConnectionStrategy .kKeepOpen );
133+ CameraServer .getServer ().setSource (camera );
134+ return camera ;
135+ }
136+
137+ /**
138+ * This method is equivilent to calling {@link #configureCamera()} {@link numCameras} times.
139+ * The last camera will be set as the primary Camera feed.
140+ * To change it, call {@code CameraServer.getServer().setSource()}.
141+ *
142+ * @param numCameras The number of cameras to configure
143+ * @return The configured cameras.
144+ */
145+ public static UsbCamera [] configureCameras (int numCameras ) {
146+ UsbCamera [] cameras = new UsbCamera [numCameras ];
147+ for (int i = 0 ; i < numCameras ; i ++) cameras [i ] = configureCamera ();
148+ return cameras ;
149+ }
119150}
0 commit comments