Add code for toggling the camera on and off with a button (Still does not work yet) advay/ToggleCamera
authoryavda <advay.anand@gmail.com>
Tue, 24 Jan 2017 05:16:44 +0000 (21:16 -0800)
committeryavda <advay.anand@gmail.com>
Tue, 24 Jan 2017 05:16:44 +0000 (21:16 -0800)
src/org/usfirst/frc/team3501/robot/Robot.java

index 5fbfe4043d6b58bca46b2daffc35783c2ae74251..4c0e9d1804a15eaab05ad11bcd39bdf4ab8983cd 100644 (file)
@@ -5,7 +5,12 @@ import org.usfirst.frc.team3501.robot.subsystems.Climber;
 import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
 import org.usfirst.frc.team3501.robot.subsystems.Shooter;
 
+import edu.wpi.cscore.AxisCamera;
+import edu.wpi.cscore.UsbCamera;
+import edu.wpi.first.wpilibj.CameraServer;
 import edu.wpi.first.wpilibj.IterativeRobot;
+import edu.wpi.first.wpilibj.Timer;
+import edu.wpi.first.wpilibj.command.Command;
 import edu.wpi.first.wpilibj.command.Scheduler;
 
 public class Robot extends IterativeRobot {
@@ -13,6 +18,9 @@ public class Robot extends IterativeRobot {
   private static OI oi;
   private static Climber climber;
   private static Shooter shooter;
+  private static UsbCamera camera1;
+  private static CameraServer cameraServer2;
+  private static AxisCamera camera2;
 
   @Override
   public void robotInit() {
@@ -20,7 +28,46 @@ public class Robot extends IterativeRobot {
     oi = OI.getOI();
     climber = Climber.getClimber();
     shooter = Shooter.getShooter();
+    camera1 = CameraServer.getInstance().startAutomaticCapture();
+    cameraServer2 = CameraServer.getInstance();
+    camera2 = cameraServer2.addAxisCamera("camera2", "10.35.1.11");
 
+    Timer.delay(3);
+    System.out.println("====> 1");
+    cameraServer2.removeCamera("camera2");
+    Timer.delay(3);
+    // Joystick leftJoystick = new Joystick(0);
+    // Button button1 = new JoystickButton(leftJoystick, 1);
+    camera2 = cameraServer2.addAxisCamera("camera2", "10.35.1.11");
+    System.out.println("====> 2");
+    Timer.delay(3);
+    cameraServer2.removeCamera("camera2");
+
+    // button1.whenPressed(new JoystickButton1Pressed());
+    // button1.whenReleased(new JoystickButton1Released());
+
+  }
+
+  public class JoystickButton1Pressed extends Command {
+    public JoystickButton1Pressed() {
+      // camera2.addAxisCamera("camera2", "10.35.1.11");
+    }
+
+    @Override
+    public boolean isFinished() {
+      return true;
+    }
+  }
+
+  public class JoystickButton1Released extends Command {
+    public JoystickButton1Released() {
+      cameraServer2.removeCamera("camera2");
+    }
+
+    @Override
+    public boolean isFinished() {
+      return true;
+    }
   }
 
   public static DriveTrain getDriveTrain() {