add code for switching b/w cameras
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / CameraFeeds.java
CommitLineData
7236fc11
ME
1package org.usfirst.frc.team3501.robot;
2
3import com.ni.vision.NIVision;
4import com.ni.vision.NIVision.Image;
5
6import edu.wpi.first.wpilibj.CameraServer;
7
8public class CameraFeeds {
9
10 // camera id's
11 private int camIntake;
12 private int camShooter;
13 private int currentCam;
14
15 private Image frame;
16 private CameraServer server;
17
18 public CameraFeeds() {
19 // get camera id's by giving camera name on roboRio web interface
20 camIntake = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameIntake,
21 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
22 camShooter = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameIntake,
23 NIVision.IMAQdxCameraControlMode.CameraControlModeController);
24
25 // img that will contain camera img
26 frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
27
28 // server we will give the image to
29 server = CameraServer.getInstance();
30 server.setQuality(Constants.CameraFeeds.imgQuality);
31
32 }
33
34 public void init() {
35 changeCam(camShooter);
36 }
37
38 public void run() {
39 // change camera based on direction robot is moving in (whatever is front)
40 // (initial front is shooter)
41 if (currentCam != camIntake && Robot.driveTrain.isFlipped())
42 changeCam(camIntake);
43 else if (currentCam != camShooter) {
44 changeCam(camShooter);
45 }
46 updateCam();
47 }
48
49 /***
50 * Close camera stream
51 */
52 public void end() {
53 NIVision.IMAQdxStopAcquisition(currentCam);
54 }
55
56 /***
57 * switch which camera your getting images from
58 *
59 * @param newId
60 * for camera
61 */
62 public void changeCam(int newId) {
63 NIVision.IMAQdxStopAcquisition(currentCam);
64 NIVision.IMAQdxConfigureGrab(newId);
65 NIVision.IMAQdxStartAcquisition(newId);
66 currentCam = newId;
67 }
68
69 /***
70 * Get img from current camera and give it to server
71 */
72 public void updateCam() {
73 NIVision.IMAQdxGrab(currentCam, frame, 1);
74 server.setImage(frame);
75 }
76}