Toggle between cameras (Untested).
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / CameraFeeds.java
1 package org.usfirst.frc.team3501.robot;
2
3 import com.ni.vision.NIVision.Image;
4
5 import edu.wpi.cscore.AxisCamera;
6 import edu.wpi.cscore.UsbCamera;
7 import edu.wpi.cscore.VideoSource;
8 import edu.wpi.first.wpilibj.CameraServer;
9
10 public class CameraFeeds {
11 // private final int intakeCam;
12 // private final int climberCam;
13 private Image frame;
14 private VideoSource curCam;
15 private CameraServer server;
16 private static UsbCamera intakeCam;
17 private static AxisCamera climberCam;
18 private static String usbCamName;
19 private static String axisCamName;
20
21 @SuppressWarnings("deprecation")
22 public CameraFeeds(/* Joystick Button */) {
23 // Get camera ids by supplying camera name ex 'cam0', found on roborio web
24 // interface
25 /*
26 * intakeCam =
27 * NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
28 * NIVision.IMAQdxCameraControlMode.CameraControlModeController); climberCam
29 * = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
30 * NIVision.IMAQdxCameraControlMode.CameraControlModeController); curCam =
31 * intakeCam; // Img that will contain camera img frame =
32 * NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); // Server that
33 * we'll give the img to server = CameraServer.getInstance();
34 * server.setSize(Constants.CameraFeeds.imgQuality);
35 */
36
37 server = CameraServer.getInstance();
38 climberCam = server.addAxisCamera("axisCamera", "10.35.1.11");
39 intakeCam = server.startAutomaticCapture();
40 curCam = intakeCam;
41 usbCamName = intakeCam.getName();
42 axisCamName = climberCam.getName();
43
44 // server = CameraServer.getInstance();
45 // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11");
46 // cameraFeeds = new CameraFeeds();
47 }
48
49 public void init() {
50 changeCam(intakeCam);
51 }
52
53 public void toggleCamera() {
54 if (curCam.equals(intakeCam)) {
55 changeCam(climberCam);
56 curCam = climberCam;
57 }
58
59 if (curCam.equals(climberCam)) {
60 changeCam(intakeCam);
61 curCam = intakeCam;
62 }
63 }
64
65 /**
66 *
67 * Change the camera to get imgs from to a different one
68 *
69 * @param newId
70 * for camera
71 */
72 public void changeCam(VideoSource cam) {
73 server.removeCamera(axisCamName);
74 server.removeCamera(usbCamName);
75 server.addCamera(cam);
76 }
77 }