Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public static CANSparkMax createSparkMax(int id, MotorConfig config) {
return spark;
}

/**
* @deprecated Use {@link SensorFactory#createCANCoder(int)} instead.
*/
@Deprecated
public static CANCoder createCANCoder(int port) {
CANCoder canCoder = new CANCoder(port);
if(RobotBase.isSimulation()) new MockedCANCoder(canCoder);
Expand All @@ -156,7 +160,10 @@ public static CANCoder createCANCoder(int port) {
* This MUST be called AFTER AHRS initialization or the code will be unable to connect to the gyro.
*
* @return The configured camera
*
* @deprecated Use {@link SensorFactory#configureCamera()} instead.
*/
@Deprecated
public static UsbCamera configureCamera() {
UsbCamera camera = CameraServer.startAutomaticCapture();
camera.setConnectionStrategy(ConnectionStrategy.kKeepOpen);
Expand All @@ -171,7 +178,10 @@ public static UsbCamera configureCamera() {
*
* @param numCameras The number of cameras to configure
* @return The configured cameras.
*
* @deprecated Use {@link SensorFactory#configureCameras(int)} instead.
*/
@Deprecated
public static UsbCamera[] configureCameras(int numCameras) {
UsbCamera[] cameras = new UsbCamera[numCameras];
for(int i = 0; i < numCameras; i++) cameras[i] = configureCamera();
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/org/carlmontrobotics/lib199/SensorFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.carlmontrobotics.lib199;

import org.carlmontrobotics.lib199.sim.MockedCANCoder;

import com.ctre.phoenix.sensors.CANCoder;

import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.cscore.UsbCamera;
import edu.wpi.first.cscore.VideoSource.ConnectionStrategy;
import edu.wpi.first.wpilibj.RobotBase;

/**
* A class containing methods to create and configure sensors.
*/
public class SensorFactory {

/**
* Creates a CANCoder object, linking it to the simulator if necessary
*
* @param port The CAN ID of the CANCoder
* @return The CANCoder object
*/
public static CANCoder createCANCoder(int port) {
CANCoder canCoder = new CANCoder(port);
if (RobotBase.isSimulation())
new MockedCANCoder(canCoder);
return canCoder;
}

/**
* Configures a USB Camera.
* See {@link CameraServer#startAutomaticCapture} for more details.
* This MUST be called AFTER AHRS initialization or the code will be unable to
* connect to the gyro.
*
* @return The configured camera
*/
public static UsbCamera configureCamera() {
UsbCamera camera = CameraServer.startAutomaticCapture();
camera.setConnectionStrategy(ConnectionStrategy.kKeepOpen);
CameraServer.getServer().setSource(camera);
return camera;
}

/**
* This method is equivalent to calling {@link #configureCamera()}
* {@code numCameras} times.
* The last camera will be set as the primary Camera feed.
* To change it, call {@code CameraServer.getServer().setSource()}.
*
* @param numCameras The number of cameras to configure
* @return The configured cameras.
*/
public static UsbCamera[] configureCameras(int numCameras) {
UsbCamera[] cameras = new UsbCamera[numCameras];
for (int i = 0; i < numCameras; i++)
cameras[i] = configureCamera();
return cameras;
}

}