Second attempt at camera server toggling.
[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
6 import edu.wpi.cscore.AxisCamera;
7 import edu.wpi.cscore.UsbCamera;
8 import edu.wpi.cscore.VideoSource;
9 import edu.wpi.first.wpilibj.CameraServer;
10
11 public class CameraFeeds {
12 // private final int intakeCam;
13 // private final int climberCam;
14 private Image frame;
15 private String curCam = "intake";
16 private CameraServer server;
17 private static UsbCamera intakeCam;
18 private static AxisCamera climberCam;
19
20 @SuppressWarnings("deprecation")
21 public CameraFeeds(/* Joystick Button */) {
22 // Get camera ids by supplying camera name ex 'cam0', found on roborio web
23 // interface
24 /*
25 * intakeCam =
26 * NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
27 * NIVision.IMAQdxCameraControlMode.CameraControlModeController); climberCam
28 * = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
29 * NIVision.IMAQdxCameraControlMode.CameraControlModeController); curCam =
30 * intakeCam; // Img that will contain camera img frame =
31 * NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); // Server that
32 * we'll give the img to server = CameraServer.getInstance();
33 * server.setSize(Constants.CameraFeeds.imgQuality);
34 */
35 intakeCam = CameraServer.getInstance().startAutomaticCapture();
36 CameraServer.getInstance().startAutomaticCapture();
37 server = CameraServer.getInstance();
38 climberCam = server.addAxisCamera("axisCamera", "10.35.1.11");
39
40 // server = CameraServer.getInstance();
41 // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11");
42 // cameraFeeds = new CameraFeeds();
43 }
44
45 public void init() {
46 changeCam(intakeCam);
47 }
48
49 public void run()
50 {
51 if(/*add test for toggle*/)
52 changeCam(intakeCam);
53
54 if(/*add test for toggle*/)
55 changeCam(climberCam);
56
57 updateCam();
58 }
59
60 /**
61 * Stop aka close camera stream
62 */
63 public void end() {
64 // NIVision.IMAQdxStopAcquisition(curCam);
65 }
66
67 /**
68 *
69 * Change the camera to get imgs from to a different one
70 *
71 * @param newId
72 * for camera
73 */
74 public void changeCam(/* int newId */) {
75 if (curCam == "climber") {
76 server.removeCamera(/* Axis Camera name */);
77 server.addCamera(intakeCam);
78 curCam = "intake";
79 } else if (curCam == "intake") {
80 server.removeCamera(/* Usb Camera name */);
81 server.addCamera(climberCam);
82 curCam = "climber";
83 }
84 // NIVision.IMAQdxStopAcquisition(curCam);
85 // NIVision.IMAQdxConfigureGrab(newId);
86 // NIVision.IMAQdxStartAcquisition(newId);
87 // curCam = newId;
88 }
89
90 /**
91 * Get the img from current camera and give it to the server
92 */
93 public void updateCam() {
94 // NIVision.IMAQdxGrab(curCam, frame, 1);
95 // server.setImage(frame);
96 }
97 }