Still trying to figure this out.
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / CameraFeeds.java
CommitLineData
409d6878
ME
1package org.usfirst.frc.team3501.robot;
2
3import com.ni.vision.NIVision;
4import com.ni.vision.NIVision.Image;
2ada01fd
RH
5
6import edu.wpi.cscore.AxisCamera;
7import edu.wpi.cscore.UsbCamera;
409d6878
ME
8import edu.wpi.first.wpilibj.CameraServer;
9
10public class CameraFeeds {
11 private final int intakeCam;
12 private final int climberCam;
13 private int curCam;
409d6878 14 private CameraServer server;
2ada01fd
RH
15 // private static UsbCamera intakeCam;
16 // private static AxisCamera climberCam;
409d6878 17
fbc1210e 18 @SuppressWarnings("deprecation")
409d6878
ME
19 public CameraFeeds() {
20 // Get camera ids by supplying camera name ex 'cam0', found on roborio web
21 // interface
fbc1210e 22 intakeCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
409d6878 23 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
fbc1210e 24 climberCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
409d6878
ME
25 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
26 curCam = intakeCam;
27 // Img that will contain camera img
28 frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
29 // Server that we'll give the img to
30 server = CameraServer.getInstance();
fbc1210e 31 server.setSize(Constants.CameraFeeds.imgQuality);
2ada01fd
RH
32
33 // server = CameraServer.getInstance();
34 // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11");
35 // cameraFeeds = new CameraFeeds();
409d6878
ME
36 }
37
38 public void init() {
39 changeCam(intakeCam);
40 }
41
42 public void run()
43 {
1cac6c82 44 if(/*add test for toggle*/)
409d6878
ME
45 changeCam(intakeCam);
46
1cac6c82 47 if(/*add test for toggle*/)
409d6878
ME
48 changeCam(climberCam);
49
50 updateCam();
51 }
52
53 /**
54 * Stop aka close camera stream
55 */
56 public void end() {
57 NIVision.IMAQdxStopAcquisition(curCam);
58 }
59
60 /**
61 * Change the camera to get imgs from to a different one
62 *
63 * @param newId
64 * for camera
65 */
66 public void changeCam(int newId) {
67 NIVision.IMAQdxStopAcquisition(curCam);
68 NIVision.IMAQdxConfigureGrab(newId);
69 NIVision.IMAQdxStartAcquisition(newId);
70 curCam = newId;
71 }
72
73 /**
74 * Get the img from current camera and give it to the server
75 */
76 public void updateCam() {
77 NIVision.IMAQdxGrab(curCam, frame, 1);
2ada01fd 78 server.setSize(frame);
409d6878
ME
79 }
80}