Still trying to figure this out.
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / CameraFeeds.java
CommitLineData
e63d823c
ME
1package org.usfirst.frc.team3501.robot;
2
3import com.ni.vision.NIVision;
4import com.ni.vision.NIVision.Image;
f31051bd
RH
5
6import edu.wpi.cscore.AxisCamera;
7import edu.wpi.cscore.UsbCamera;
e63d823c
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;
e63d823c 14 private CameraServer server;
f31051bd
RH
15 // private static UsbCamera intakeCam;
16 // private static AxisCamera climberCam;
e63d823c 17
c6008874 18 @SuppressWarnings("deprecation")
e63d823c
ME
19 public CameraFeeds() {
20 // Get camera ids by supplying camera name ex 'cam0', found on roborio web
21 // interface
c6008874 22 intakeCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
e63d823c 23 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
c6008874 24 climberCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
e63d823c
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();
c6008874 31 server.setSize(Constants.CameraFeeds.imgQuality);
f31051bd
RH
32
33 // server = CameraServer.getInstance();
34 // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11");
35 // cameraFeeds = new CameraFeeds();
e63d823c
ME
36 }
37
38 public void init() {
39 changeCam(intakeCam);
40 }
41
42 public void run()
43 {
a1a9bb70 44 if(/*add test for toggle*/)
e63d823c
ME
45 changeCam(intakeCam);
46
a1a9bb70 47 if(/*add test for toggle*/)
e63d823c
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);
f31051bd 78 server.setSize(frame);
e63d823c
ME
79 }
80}