| 1 | package org.usfirst.frc.team3501.robot; |
| 2 | |
| 3 | import edu.wpi.cscore.AxisCamera; |
| 4 | import edu.wpi.cscore.UsbCamera; |
| 5 | import edu.wpi.cscore.VideoSource; |
| 6 | import edu.wpi.first.wpilibj.CameraServer; |
| 7 | |
| 8 | public class CameraFeeds { |
| 9 | // private final int intakeCam; |
| 10 | // private final int climberCam; |
| 11 | private VideoSource curCam; |
| 12 | private CameraServer server; |
| 13 | private static UsbCamera intakeCam; |
| 14 | private static AxisCamera climberCam; |
| 15 | private static String usbCamName; |
| 16 | private static String axisCamName; |
| 17 | private static CameraFeeds cameraFeeds = null; |
| 18 | |
| 19 | |
| 20 | @SuppressWarnings("deprecation") |
| 21 | public CameraFeeds(/* Joystick Button */) { |
| 22 | // Get camera id by supplying camera name example '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; // Image that will contain camera image frame = |
| 31 | * NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); // Server that |
| 32 | * we'll give the image to server = CameraServer.getInstance(); |
| 33 | * server.setSize(Constants.CameraFeeds.imgQuality); |
| 34 | */ |
| 35 | |
| 36 | server = CameraServer.getInstance(); |
| 37 | climberCam = server.addAxisCamera("axisCamera", "10.35.1.11"); |
| 38 | intakeCam = server.startAutomaticCapture(); |
| 39 | curCam = intakeCam; |
| 40 | usbCamName = intakeCam.getName(); |
| 41 | axisCamName = climberCam.getName(); |
| 42 | |
| 43 | // server = CameraServer.getInstance(); |
| 44 | // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11"); |
| 45 | // cameraFeeds = new CameraFeeds(); |
| 46 | } |
| 47 | |
| 48 | public static CameraFeeds getCameraFeeds() { |
| 49 | if (cameraFeeds == null) { |
| 50 | cameraFeeds = new CameraFeeds(); |
| 51 | } |
| 52 | return cameraFeeds; |
| 53 | |
| 54 | |
| 55 | } |
| 56 | |
| 57 | public void init() { |
| 58 | changeCam(intakeCam); |
| 59 | } |
| 60 | |
| 61 | public void toggleCamera() { |
| 62 | if (curCam.equals(intakeCam)) { |
| 63 | changeCam(climberCam); |
| 64 | curCam = climberCam; |
| 65 | } |
| 66 | |
| 67 | if (curCam.equals(climberCam)) { |
| 68 | changeCam(intakeCam); |
| 69 | curCam = intakeCam; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * |
| 75 | * Change the camera to get image from to a different one |
| 76 | * |
| 77 | * newId |
| 78 | * for camera |
| 79 | */ |
| 80 | public void changeCam(VideoSource cam) { |
| 81 | server.removeCamera(axisCamName); |
| 82 | server.removeCamera(usbCamName); |
| 83 | server.addCamera(cam); |
| 84 | } |
| 85 | } |