SHARE
TWEET

DriveStation.java

a guest Feb 16th, 2013 9 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package edu.wpi.first.wpilibj.templates;
  2.  
  3. import edu.wpi.first.wpilibj.DriverStationLCD;
  4. import edu.wpi.first.wpilibj.Joystick;
  5. import org.homestead.robotics.robot.DriveTrain;
  6. import org.homestead.robotics.robot.Shooter;
  7. import org.homestead.robotics.robot.Timer;
  8.  
  9. /**
  10.  *
  11.  * @author Driver
  12.  */
  13. public class DriveStation
  14. {
  15.     private static final int TOTAL_LINES = 6;
  16.     private static String[] lines = new String[TOTAL_LINES];
  17.     private Joystick rightDriveJoystick;
  18.     private Joystick leftDriveJoystick;
  19.     private Joystick shooterJoystick;
  20.     private DriveTrain driveTrain;
  21.     private Shooter shooter;
  22.  
  23.     public DriveStation()
  24.     {
  25.         rightDriveJoystick = new Joystick(1);
  26.         leftDriveJoystick = new Joystick(2);
  27.         shooterJoystick = new Joystick(3);
  28.  
  29.         driveTrain = new DriveTrain();
  30.         shooter = new Shooter();
  31.     }
  32.  
  33.     public void operatorControl()
  34.     {
  35.         handleJoystickButtons();
  36.         driveTrain.drive(leftDriveJoystick.getX(), leftDriveJoystick.getY(), rightDriveJoystick.getX(), rightDriveJoystick.getY());
  37.         updateLCD();
  38.     }
  39.  
  40.     /**
  41.      * Autonomous: Simply shoots
  42.      */
  43.     public void autonomousControl()
  44.     {
  45.         Timer fourfifthssecond = new Timer(0.8);
  46.         Timer threesecond = new Timer(3);
  47.         Timer fivesecond = new Timer(5);
  48.         Timer fifteensecond = new Timer(15);
  49.         fivesecond.set();
  50.         fifteensecond.set();
  51.         shooter.shoot();
  52.         //shooter.voltageCompensation(getBatteryVoltage());
  53.         while (!fifteensecond.isDone())//Team670Robot.isAuto())
  54.         {
  55.             if (fivesecond.isDone())
  56.             {
  57.                 fourfifthssecond.set();
  58.                 fivesecond.unSet();
  59.             }
  60.             if (fourfifthssecond.isDone())
  61.             {
  62.                 fivesecond.set();
  63.                 fourfifthssecond.unSet();
  64.             }
  65.             fifteensecond.step();
  66.             fivesecond.step();
  67.             fourfifthssecond.step();
  68.             edu.wpi.first.wpilibj.Timer.delay(Robot2013.REFRESH_RATE);
  69.         }
  70.  
  71.         shooter.stopShooter();
  72.     }
  73.  
  74.     /**
  75.      * Autonomous: Drives and shoots
  76.      */
  77.     /*
  78.      * public void autonomousControl() { while(Team670Robot.isAuto()) {
  79.      * shooter.shoot(); } shooter.stopShooter(); }
  80.      */
  81.     private void handleJoystickButtons()
  82.     {
  83.         driveTrain.togglePrecisionMode(((leftDriveJoystick.getRawButton(2) || rightDriveJoystick.getRawButton(2)) ? true : false));
  84.         driveTrain.toggleBoostMode(((leftDriveJoystick.getTrigger() || rightDriveJoystick.getTrigger()) ? true : false));
  85.         if (rightDriveJoystick.getRawButton(7))
  86.         {
  87.             driveTrain.toggleDriveMode();
  88.         }
  89.         driveTrain.stepTimer();
  90.  
  91.         if (shooterJoystick.getRawButton(3))
  92.         {
  93.             shooter.voltageCompensation();
  94.         }
  95.         setLine(1, "Shooter throttle: " + shooter.getThrottle());
  96.        
  97.         if (shooterJoystick.getRawButton(4))
  98.         {
  99.             shooter.setForward();
  100.             DriveStation.setLine(2, "Button 4, setForward()");
  101.         }
  102.         if (shooterJoystick.getRawButton(5))
  103.         {
  104.             shooter.setReverse();
  105.             DriveStation.setLine(2, "Button 5, setReverse()");            
  106.         }
  107.         if (shooterJoystick.getRawButton(2))
  108.         {
  109.             shooter.setOff();
  110.             DriveStation.setLine(2, "Button 2, setOff()");            
  111.         }
  112.  
  113.         if (shooterJoystick.getTrigger())
  114.         {
  115.             shooter.shoot();
  116.         }
  117.         else
  118.         {
  119.             shooter.stopShooter();
  120.         }
  121.  
  122.         if (shooterJoystick.getRawButton(10))
  123.         {
  124.             shooter.throttleUp();
  125.         }
  126.         else if (shooterJoystick.getRawButton(11))
  127.         {
  128.             shooter.throttleDown();
  129.         }
  130.     }
  131.  
  132.     public static void setLine(int key, String value)
  133.     {
  134.         if (key > TOTAL_LINES || key < 1)
  135.         {
  136.             return;
  137.         }
  138.         lines[key - 1] = value;
  139.     }
  140.  
  141.     public void updateLCD()
  142.     {
  143.         for (int i = 0; i < lines.length; i++)
  144.         {
  145.             if (lines[i] == null)
  146.             {
  147.                 lines[i] = "";
  148.             }
  149.         }
  150.  
  151.         DriverStationLCD stationLCD = DriverStationLCD.getInstance();
  152.  
  153.         stationLCD.println(DriverStationLCD.Line.kMain6, 1, "                         ");
  154.         stationLCD.println(DriverStationLCD.Line.kUser2, 1, "                         ");
  155.         stationLCD.println(DriverStationLCD.Line.kUser3, 1, "                         ");
  156.         stationLCD.println(DriverStationLCD.Line.kUser4, 1, "                         ");
  157.         stationLCD.println(DriverStationLCD.Line.kUser5, 1, "                         ");
  158.         stationLCD.println(DriverStationLCD.Line.kUser6, 1, "                         ");
  159.  
  160.         stationLCD.println(DriverStationLCD.Line.kMain6, 1, lines[0]);
  161.         stationLCD.println(DriverStationLCD.Line.kUser2, 1, lines[1]);
  162.         stationLCD.println(DriverStationLCD.Line.kUser3, 1, lines[2]);
  163.         stationLCD.println(DriverStationLCD.Line.kUser4, 1, lines[3]);
  164.         stationLCD.println(DriverStationLCD.Line.kUser5, 1, lines[4]);
  165.         stationLCD.println(DriverStationLCD.Line.kUser6, 1, lines[5]);
  166.  
  167.         stationLCD.updateLCD();
  168.     }
  169. }
RAW Paste Data
Top