Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/CameraSwitching


Ignore:
Timestamp:
Feb 14, 2020, 12:53:10 AM (5 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/CameraSwitching

    v1 v2  
    1616  @Override
    1717  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
    2020  }
    2121}
     
    3030import edu.wpi.cscore.UsbCamera;
    3131import edu.wpi.first.wpilibj.XboxController;
    32 import edu.wpi.first.wpilibj.Timer;
    3332
    3433class Cameras extends Thread {
     
    3635    UsbCamera      frontCam, rearCam;
    3736    XboxController xbox;
    38     Timer          debounce;
    3937
    4038    public Cameras() {
     39        // Camera server manages all cameras and streams
    4140        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);
    4746    }
    4847
    4948    public void run() {
    50         debounce.start();
    5149        while (true) {
    5250            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);
    6157            }
    6258        }