Skip to content

Commit ad67d3a

Browse files
committed
add camera configuration helpers to MotorControllerFactory
1 parent 58338f5 commit ad67d3a

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/main/java/frc/robot/lib/MotorControllerFactory.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import com.revrobotics.CANSparkMaxLowLevel;
1818
import 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;
2023
import edu.wpi.first.wpilibj.RobotBase;
2124
import frc.robot.lib.MotorErrors.TemperatureLimit;
2225
import 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

Comments
 (0)