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