X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Frobot%2FCameraFeeds.java;h=94501567cbac31e47e2ef70a9da5ae4815b3763b;hb=93d8373fe56e8036848f7d092855cb0819702b50;hp=855d32a5bcbfe6935772af9a5ea5ce7f849ed6a9;hpb=cdcbf5c68a506914a1f9960ed7dd820be707b7e3;p=3501%2F2017steamworks diff --git a/src/org/usfirst/frc/team3501/robot/CameraFeeds.java b/src/org/usfirst/frc/team3501/robot/CameraFeeds.java index 855d32a..9450156 100755 --- a/src/org/usfirst/frc/team3501/robot/CameraFeeds.java +++ b/src/org/usfirst/frc/team3501/robot/CameraFeeds.java @@ -1,87 +1,87 @@ package org.usfirst.frc.team3501.robot; -import com.ni.vision.NIVision; -import com.ni.vision.NIVision.Image; - import edu.wpi.cscore.AxisCamera; import edu.wpi.cscore.UsbCamera; +import edu.wpi.cscore.VideoSource; import edu.wpi.first.wpilibj.CameraServer; public class CameraFeeds { // private final int intakeCam; // private final int climberCam; - private Image frame; - private int curCam; + private VideoSource curCam; private CameraServer server; private static UsbCamera intakeCam; private static AxisCamera climberCam; + private static String usbCamName; + private static String axisCamName; + private static CameraFeeds cameraFeeds = null; @SuppressWarnings("deprecation") - public CameraFeeds(/* Joystick Button */) { - // Get camera ids by supplying camera name ex 'cam0', found on roborio web - // interface - /* - * intakeCam = - * NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter, - * NIVision.IMAQdxCameraControlMode.CameraControlModeController); climberCam - * = NIVision.IMAQdxOpenCamera(Constants.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 server = CameraServer.getInstance(); - * server.setSize(Constants.CameraFeeds.imgQuality); - */ - intakeCam = CameraServer.getInstance().startAutomaticCapture(); - CameraServer.getInstance().startAutomaticCapture(); + private CameraFeeds(/* Joystick Button */) { + + usbCamName = intakeCam.getName(); + axisCamName = climberCam.getName(); server = CameraServer.getInstance(); - climberCam = server.addAxisCamera("axisCamera", "10.35.1.11"); + climberCam = server.addAxisCamera(axisCamName, "10.35.1.11"); + intakeCam = server.startAutomaticCapture(); + curCam = intakeCam; + curCam = climberCam; + usbCamName = intakeCam.getName(); + axisCamName = climberCam.getName(); + } + + public static CameraFeeds getCameraFeeds() { + if (cameraFeeds == null) { + cameraFeeds = new CameraFeeds(); + } + return cameraFeeds; - // server = CameraServer.getInstance(); - // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11"); - // cameraFeeds = new CameraFeeds(); } public void init() { changeCam(intakeCam); } - public void run() - { - if(/*add test for toggle*/) - changeCam(intakeCam); - - if(/*add test for toggle*/) - changeCam(climberCam); - - updateCam(); - } - - /** - * Stop aka close camera stream - */ - public void end() { - NIVision.IMAQdxStopAcquisition(curCam); + public void toggleCamera() { + System.out.println("enter toggleCamer"); + if (curCam.equals(intakeCam)) { + // changeCam(climberCam); + curCam = climberCam; + // System.out.println("Switching to climber camera."); + } else if (curCam.equals(climberCam)) { + // changeCam(intakeCam); + curCam = intakeCam; + // System.out.println("Switching to intake camera."); + } + changeCam(curCam); } /** * - * Change the camera to get imgs from to a different one + * Change the camera to get image from to a different one * - * @param newId - * for camera + * newId for camera */ - public void changeCam(/* int newId */) { - // NIVision.IMAQdxStopAcquisition(curCam); - // NIVision.IMAQdxConfigureGrab(newId); - // NIVision.IMAQdxStartAcquisition(newId); - // curCam = newId; + public void changeCam(VideoSource cam) { + server.removeCamera(curCam.getName()); + if (curCam.equals(intakeCam)) { + server.addCamera(intakeCam); + System.out.println("Switching to climber camera."); + return; + } + + if (curCam.equals(climberCam)) { + server.addAxisCamera(axisCamName, "10.35.1.11"); + // server.addCamera(climberCam); + System.out.println("Switching to intake camera."); + return; + } + System.out.println("change camera"); + server.removeCamera(curCam.getName()); + server.addCamera(cam); } - /** - * Get the img from current camera and give it to the server - */ - public void updateCam() { - NIVision.IMAQdxGrab(curCam, frame, 1); - server.setImage(frame); + public String getCurrentCamName() { + return curCam.getName(); } }