Try to understand why axis camera does turn on while toggling.
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / CameraFeeds.java
CommitLineData
409d6878
ME
1package org.usfirst.frc.team3501.robot;
2
2ada01fd
RH
3import edu.wpi.cscore.AxisCamera;
4import edu.wpi.cscore.UsbCamera;
b7b608d6 5import edu.wpi.cscore.VideoSource;
409d6878
ME
6import edu.wpi.first.wpilibj.CameraServer;
7
8public class CameraFeeds {
50a075d8
RH
9 // private final int intakeCam;
10 // private final int climberCam;
4dff9cc3 11 private VideoSource curCam;
409d6878 12 private CameraServer server;
50a075d8
RH
13 private static UsbCamera intakeCam;
14 private static AxisCamera climberCam;
4dff9cc3
RH
15 private static String usbCamName;
16 private static String axisCamName;
4bc0cb18 17 private static CameraFeeds cameraFeeds = null;
409d6878 18
fbc1210e 19 @SuppressWarnings("deprecation")
50a075d8 20 public CameraFeeds(/* Joystick Button */) {
7638f542
RH
21 // Get camera id by supplying camera name example 'cam0', found on roborio
22 // web
409d6878 23 // interface
50a075d8
RH
24 /*
25 * intakeCam =
26 * NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
27 * NIVision.IMAQdxCameraControlMode.CameraControlModeController); climberCam
28 * = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
29 * NIVision.IMAQdxCameraControlMode.CameraControlModeController); curCam =
4bc0cb18 30 * intakeCam; // Image that will contain camera image frame =
50a075d8 31 * NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); // Server that
4bc0cb18 32 * we'll give the image to server = CameraServer.getInstance();
50a075d8
RH
33 * server.setSize(Constants.CameraFeeds.imgQuality);
34 */
4dff9cc3 35
85c0135e
RH
36 usbCamName = intakeCam.getName();
37 axisCamName = climberCam.getName();
409d6878 38 server = CameraServer.getInstance();
85c0135e 39 climberCam = server.addAxisCamera(axisCamName, "10.35.1.11");
4dff9cc3
RH
40 intakeCam = server.startAutomaticCapture();
41 curCam = intakeCam;
2ada01fd
RH
42
43 // server = CameraServer.getInstance();
44 // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11");
45 // cameraFeeds = new CameraFeeds();
409d6878 46 }
7638f542 47
4bc0cb18 48 public static CameraFeeds getCameraFeeds() {
7638f542
RH
49 if (cameraFeeds == null) {
50 cameraFeeds = new CameraFeeds();
51 }
52 return cameraFeeds;
53
4bc0cb18 54 }
409d6878
ME
55
56 public void init() {
85c0135e 57 changeCam(intakeCam);
409d6878
ME
58 }
59
4dff9cc3
RH
60 public void toggleCamera() {
61 if (curCam.equals(intakeCam)) {
85c0135e 62 // changeCam(climberCam);
4dff9cc3 63 curCam = climberCam;
85c0135e
RH
64 // System.out.println("Switching to climber camera.");
65 } else if (curCam.equals(climberCam)) {
66 // changeCam(intakeCam);
4dff9cc3 67 curCam = intakeCam;
85c0135e 68 // System.out.println("Switching to intake camera.");
4dff9cc3 69 }
85c0135e 70 changeCam(curCam);
409d6878
ME
71 }
72
73 /**
50a075d8 74 *
4bc0cb18 75 * Change the camera to get image from to a different one
409d6878 76 *
7638f542 77 * newId for camera
409d6878 78 */
4dff9cc3 79 public void changeCam(VideoSource cam) {
85c0135e
RH
80 server.removeCamera(curCam.getName());
81 if (curCam.equals(intakeCam)) {
82 server.addCamera(intakeCam);
83 System.out.println("Switching to climber camera.");
84 return;
85 }
86
87 if (curCam.equals(climberCam)) {
88 server.addAxisCamera(axisCamName, "10.35.1.11");
89 // server.addCamera(climberCam);
90 System.out.println("Switching to intake camera.");
91 return;
92 }
409d6878
ME
93 }
94}