Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/CameraSwitching
- Timestamp:
- Feb 14, 2020, 12:53:10 AM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/CameraSwitching
v1 v2 16 16 @Override 17 17 public void robotInit() { 18 cameras = new Cameras(); 19 cameras.start(); 18 cameras = new Cameras(); // create the Cameras thread 19 cameras.start(); // start thread and launch its run() method 20 20 } 21 21 } … … 30 30 import edu.wpi.cscore.UsbCamera; 31 31 import edu.wpi.first.wpilibj.XboxController; 32 import edu.wpi.first.wpilibj.Timer;33 32 34 33 class Cameras extends Thread { … … 36 35 UsbCamera frontCam, rearCam; 37 36 XboxController xbox; 38 Timer debounce;39 37 40 38 public Cameras() { 39 // Camera server manages all cameras and streams 41 40 camServer = CameraServer.getInstance(); 42 frontCam = camServer.startAutomaticCapture("front", 0);43 rearCam = camServer.startAutomaticCapture("rear", 1);44 45 xbox = new XboxController(0);46 debounce = new Timer();41 // Create and start front and rear cameras 42 frontCam = camServer.startAutomaticCapture("front", 0); 43 rearCam = camServer.startAutomaticCapture("rear", 1); 44 // Use Xbox controller to select camera stream 45 xbox = new XboxController(0); 47 46 } 48 47 49 48 public void run() { 50 debounce.start();51 49 while (true) { 52 50 if (xbox.getAButton()) { 53 if (debounce.hasPeriodPassed(0.5)) { 54 if (camServer.getServer().getSource().getName().contentEquals("front")) { 55 camServer.getServer().setSource(rearCam); 56 } else { 57 camServer.getServer().setSource(frontCam); 58 } 59 debounce.reset(); 60 } 51 // A button selects front camera 52 camServer.getServer().setSource(frontCam); 53 } 54 if (xbox.getBButton()) { 55 // B button selects rear camera 56 camServer.getServer().setSource(rearCam); 61 57 } 62 58 }