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