fix bugs related to Config
[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;
5import edu.wpi.first.wpilibj.CameraServer;
6
7public class CameraFeeds {
8 private final int intakeCam;
9 private final int climberCam;
10 private int curCam;
11 private Image frame;
12 private CameraServer server;
13
fbc1210e 14 @SuppressWarnings("deprecation")
409d6878
ME
15 public CameraFeeds() {
16 // Get camera ids by supplying camera name ex 'cam0', found on roborio web
17 // interface
fbc1210e 18 intakeCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
409d6878 19 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
fbc1210e 20 climberCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
409d6878
ME
21 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
22 curCam = intakeCam;
23 // Img that will contain camera img
24 frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
25 // Server that we'll give the img to
26 server = CameraServer.getInstance();
fbc1210e 27 server.setSize(Constants.CameraFeeds.imgQuality);
409d6878
ME
28 }
29
30 public void init() {
31 changeCam(intakeCam);
32 }
33
34 public void run()
35 {
1cac6c82 36 if(/*add test for toggle*/)
409d6878
ME
37 changeCam(intakeCam);
38
1cac6c82 39 if(/*add test for toggle*/)
409d6878
ME
40 changeCam(climberCam);
41
42 updateCam();
43 }
44
45 /**
46 * Stop aka close camera stream
47 */
48 public void end() {
49 NIVision.IMAQdxStopAcquisition(curCam);
50 }
51
52 /**
53 * Change the camera to get imgs from to a different one
54 *
55 * @param newId
56 * for camera
57 */
58 public void changeCam(int newId) {
59 NIVision.IMAQdxStopAcquisition(curCam);
60 NIVision.IMAQdxConfigureGrab(newId);
61 NIVision.IMAQdxStartAcquisition(newId);
62 curCam = newId;
63 }
64
65 /**
66 * Get the img from current camera and give it to the server
67 */
68 public void updateCam() {
69 NIVision.IMAQdxGrab(curCam, frame, 1);
70 server.setImage(frame);
71 }
72}