From 9ea6a533269dd1a8f9f684b3bbd90ae4b17478db Mon Sep 17 00:00:00 2001 From: Meryem Esa Date: Tue, 7 Feb 2017 20:47:01 -0800 Subject: [PATCH] fix ToggleCameraFeed command --- .../frc/team3501/robot/CameraFeeds.java | 34 ++++++------------- src/org/usfirst/frc/team3501/robot/Robot.java | 14 ++++---- .../accessories/ToggleCameraFeed.java | 24 +++++++------ 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/org/usfirst/frc/team3501/robot/CameraFeeds.java b/src/org/usfirst/frc/team3501/robot/CameraFeeds.java index 4e1d919..ac72556 100755 --- a/src/org/usfirst/frc/team3501/robot/CameraFeeds.java +++ b/src/org/usfirst/frc/team3501/robot/CameraFeeds.java @@ -17,32 +17,15 @@ public class CameraFeeds { private static CameraFeeds cameraFeeds = null; @SuppressWarnings("deprecation") - public CameraFeeds(/* Joystick Button */) { - // Get camera id by supplying camera name example '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; // Image that will contain camera image frame = - * NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); // Server that - * we'll give the image to server = CameraServer.getInstance(); - * server.setSize(Constants.CameraFeeds.imgQuality); - */ + private CameraFeeds(/* Joystick Button */) { server = CameraServer.getInstance(); climberCam = server.addAxisCamera("axisCamera", "10.35.1.11"); intakeCam = server.startAutomaticCapture(); - curCam = intakeCam; + curCam = climberCam; usbCamName = intakeCam.getName(); axisCamName = climberCam.getName(); - // server = CameraServer.getInstance(); - // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11"); - // cameraFeeds = new CameraFeeds(); } public static CameraFeeds getCameraFeeds() { @@ -54,11 +37,11 @@ public class CameraFeeds { } public void init() { - changeCam(climberCam); + changeCam(intakeCam); } public void toggleCamera() { - System.out.println("enter toggleCamer"); + System.out.println("enter toggleCamer"); if (curCam.equals(intakeCam)) { changeCam(climberCam); curCam = climberCam; @@ -81,9 +64,12 @@ public class CameraFeeds { * newId for camera */ public void changeCam(VideoSource cam) { - System.out.println("change camera"); - server.removeCamera(axisCamName); - server.removeCamera(usbCamName); + System.out.println("change camera"); + server.removeCamera(curCam.getName()); server.addCamera(cam); } + + public String getCurrentCamName() { + return curCam.getName(); + } } diff --git a/src/org/usfirst/frc/team3501/robot/Robot.java b/src/org/usfirst/frc/team3501/robot/Robot.java index b0e32a7..d467182 100644 --- a/src/org/usfirst/frc/team3501/robot/Robot.java +++ b/src/org/usfirst/frc/team3501/robot/Robot.java @@ -26,15 +26,15 @@ public class Robot extends IterativeRobot { shooter = Shooter.getShooter(); intake = Intake.getIntake(); + cameraFeeds = CameraFeeds.getCameraFeeds(); + // usbCamera = CameraServer.getInstance().startAutomaticCapture(); // cameraServer2 = CameraServer;getInstance(); // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11"); - cameraServer2 = CameraServer.getInstance(); - axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11"); - - cameraFeeds = new CameraFeeds(); + // cameraServer2 = CameraServer.getInstance(); + // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11"); // usbCamera = CameraServer.getInstance().startAutomaticCapture(); // CameraServer.getInstance().startAutomaticCapture(); @@ -53,6 +53,10 @@ public class Robot extends IterativeRobot { return Shooter.getShooter(); } + public static CameraFeeds getCameraFeeds() { + return cameraFeeds; + } + public static OI getOI() { return OI.getOI(); } @@ -77,8 +81,6 @@ public class Robot extends IterativeRobot { @Override public void teleopInit() { - cameraFeeds.init(); - } @Override diff --git a/src/org/usfirst/frc/team3501/robot/commands/accessories/ToggleCameraFeed.java b/src/org/usfirst/frc/team3501/robot/commands/accessories/ToggleCameraFeed.java index b42b961..4515b82 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/accessories/ToggleCameraFeed.java +++ b/src/org/usfirst/frc/team3501/robot/commands/accessories/ToggleCameraFeed.java @@ -1,20 +1,24 @@ package org.usfirst.frc.team3501.robot.commands.accessories; import org.usfirst.frc.team3501.robot.CameraFeeds; +import org.usfirst.frc.team3501.robot.Robot; import edu.wpi.first.wpilibj.command.Command; public class ToggleCameraFeed extends Command { - public void init() { - CameraFeeds cf = CameraFeeds.getCameraFeeds(); - - cf.toggleCamera(); - } - - @Override - protected boolean isFinished() { - return true; - } + @Override + protected void execute() { + CameraFeeds cf = Robot.getCameraFeeds(); + System.out.println(cf.getCurrentCamName()); + cf.toggleCamera(); + System.out.println(cf.getCurrentCamName()); + + } + + @Override + protected boolean isFinished() { + return true; + } } -- 2.30.2