X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Frobot%2FCameraFeeds.java;h=f04abbeed6bad84533cf633c1dc9ad29e1963456;hb=2c6d3e5f98543dc4a6de79b348ee78ded0a651cc;hp=c6cd477e7b159b61039437f8dd7d7c3cf9603f1d;hpb=e63d823c662c1a48339ea9091a0e03c27c1c7c8e;p=3501%2F2017steamworks diff --git a/src/org/usfirst/frc/team3501/robot/CameraFeeds.java b/src/org/usfirst/frc/team3501/robot/CameraFeeds.java index c6cd477..f04abbe 100755 --- a/src/org/usfirst/frc/team3501/robot/CameraFeeds.java +++ b/src/org/usfirst/frc/team3501/robot/CameraFeeds.java @@ -1,71 +1,65 @@ package org.usfirst.frc.team3501.robot; -import com.ni.vision.NIVision; -import com.ni.vision.NIVision.Image; +import edu.wpi.cscore.UsbCamera; import edu.wpi.first.wpilibj.CameraServer; public class CameraFeeds { - private final int intakeCam; - private final int climberCam; - private int curCam; - private Image frame; + // private final int intakeCam; + // private final int climberCam; + private String curCam; private CameraServer server; + private static UsbCamera intakeCam; + private static UsbCamera climberCam; + private static String intakeCamName; + private static String climberCamName; + private static CameraFeeds cameraFeeds = null; - public CameraFeeds() { - // Get camera ids by supplying camera name ex 'cam0', found on roborio web - // interface - intakeCam = NIVision.IMAQdxOpenCamera(Config.CameraFeeds.camNameCenter, - NIVision.IMAQdxCameraControlMode.CameraControlModeController); - climberCam = NIVision.IMAQdxOpenCamera(Config.CameraFeeds.camNameRight, - NIVision.IMAQdxCameraControlMode.CameraControlModeController); - curCam = intakeCam; - // Img that will contain camera img - frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); - // Server that we'll give the img to + @SuppressWarnings("deprecation") + private CameraFeeds(/* Joystick Button */) { + System.out.println("Enter CameraFeeds constructor"); server = CameraServer.getInstance(); - server.setQuality(Config.CameraFeeds.imgQuality); + climberCam = server.startAutomaticCapture(); + intakeCam = server.startAutomaticCapture(); + intakeCamName = intakeCam.getName(); + climberCamName = climberCam.getName(); + curCam = "intakeCam"; + changeCam(); + System.out.println("Leaving CameraFeeds constructor"); } - public void init() { - changeCam(intakeCam); + public static CameraFeeds getCameraFeeds() { + System.out.println("Enter CameraFeeds.getCameraFeeds"); + if (cameraFeeds == null) { + cameraFeeds = new CameraFeeds(); + } + System.out.println("Leaving CameraFeeds.getCameraFeeds"); + return cameraFeeds; } - public void run() - { - if() - changeCam(intakeCam); - - if() - changeCam(climberCam); - - updateCam(); + public void init() { + System.out.println("Initializing..."); } - /** - * Stop aka close camera stream - */ - public void end() { - NIVision.IMAQdxStopAcquisition(curCam); + public void toggleCamera() { + changeCam(); } /** - * Change the camera to get imgs from to a different one * - * @param newId - * for camera - */ - public void changeCam(int newId) { - NIVision.IMAQdxStopAcquisition(curCam); - NIVision.IMAQdxConfigureGrab(newId); - NIVision.IMAQdxStartAcquisition(newId); - curCam = newId; - } - - /** - * Get the img from current camera and give it to the server + * Change the camera to get image from to a different one + * + * newId for camera */ - public void updateCam() { - NIVision.IMAQdxGrab(curCam, frame, 1); - server.setImage(frame); + public void changeCam() { + System.out.println("enter toggleCamera"); + if (curCam == "intakeCam") { + server.getVideo(climberCamName); + curCam = "climberCam"; + System.out.println("Switching to climber camera, curCam = " + curCam); + } else if (curCam == "climberCam") { + server.getVideo(intakeCamName); + curCam = "intakeCam"; + System.out.println("Switching to intake camera, curCam = " + curCam); + } } }