SHARE
TWEET

Shooter.java

a guest Feb 16th, 2013 5 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.homestead.robotics.robot;
  2.  
  3. import edu.wpi.first.wpilibj.DriverStation;
  4. import edu.wpi.first.wpilibj.Jaguar;
  5. import edu.wpi.first.wpilibj.Relay;
  6.  
  7. /**
  8.  *
  9.  * @author Driver
  10.  */
  11. public class Shooter
  12. {
  13.     private static final double SHOOTER_SPEED = 1.0;
  14.     private static final double OPTIMAL_VOLTAGE = 12;
  15.     private static final double THROTTLE_STEP = 0.1;
  16.     private static final double DEFAULT_THROTTLE = 1;
  17.     private Jaguar shooterMotor1;
  18.     private Jaguar shooterMotor2;
  19.     private Relay pneuRelay;
  20.     private double throttle = 1;
  21.  
  22.     public Shooter()
  23.     {
  24.         shooterMotor1 = new Jaguar(6);
  25.         shooterMotor2 = new Jaguar(7);
  26.         pneuRelay = new Relay(2);
  27.     }
  28.  
  29.     public void shoot()
  30.     {
  31.         setMotorSpeed(throttle * SHOOTER_SPEED);
  32.     }
  33.  
  34.     public void stopShooter()
  35.     {
  36.         setMotorSpeed(0);
  37.     }
  38.  
  39.     public void setMotorSpeed(double speed)
  40.     {
  41.         shooterMotor1.set(speed);
  42.         shooterMotor2.set(speed);
  43.     }
  44.  
  45.     public void throttleDown()
  46.     {
  47.         throttle = Math.max(throttle - THROTTLE_STEP, 0);
  48.     }
  49.  
  50.     public void throttleUp()
  51.     {
  52.         throttle += THROTTLE_STEP;
  53.     }
  54.  
  55.     public double getThrottle()
  56.     {
  57.         return throttle;
  58.     }
  59.  
  60.     public void voltageCompensation()
  61.     {
  62.         throttle = DEFAULT_THROTTLE * OPTIMAL_VOLTAGE / DriverStation.getInstance().getBatteryVoltage();
  63.     }
  64.    
  65.     public void setForward()
  66.     {
  67.         pneuRelay.set(Relay.Value.kForward);
  68.     }
  69.     public void setOff()
  70.     {
  71.         pneuRelay.set(Relay.Value.kOff);
  72.     }
  73.     public void setReverse()
  74.     {
  75.         pneuRelay.set(Relay.Value.kReverse);
  76.     }
  77. }
RAW Paste Data
Top