34ecb42661f5a49dda7d11d91b38c1cc7295f415
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / CameraFeeds.java
1 package org.usfirst.frc.team3501.robot;
2
3 import com.ni.vision.NIVision;
4 import com.ni.vision.NIVision.Image;
5 import edu.wpi.first.wpilibj.CameraServer;
6
7 public 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
14 @SuppressWarnings("deprecation")
15 public CameraFeeds() {
16 // Get camera ids by supplying camera name ex 'cam0', found on roborio web
17 // interface
18 intakeCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
19 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
20 climberCam = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
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();
27 server.setSize(Constants.CameraFeeds.imgQuality);
28 }
29
30 public void init() {
31 changeCam(intakeCam);
32 }
33
34 public void run()
35 {
36 if(/*add test for toggle*/)
37 changeCam(intakeCam);
38
39 if(/*add test for toggle*/)
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 }