YWLAElektraBots

Robot.java

Jan 26th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.23 KB | None | 0 0
  1. package org.usfirst.frc.team6155.robot;
  2.  
  3. import edu.wpi.first.wpilibj.Compressor;
  4. import edu.wpi.first.wpilibj.DoubleSolenoid;
  5. import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
  6. import edu.wpi.first.wpilibj.GenericHID.Hand;
  7. import edu.wpi.first.wpilibj.IterativeRobot;
  8. import edu.wpi.first.wpilibj.Joystick;
  9. import edu.wpi.first.wpilibj.SpeedControllerGroup;
  10. import edu.wpi.first.wpilibj.Timer;
  11. import edu.wpi.first.wpilibj.VictorSP;
  12. import edu.wpi.first.wpilibj.XboxController;
  13. import edu.wpi.first.wpilibj.drive.DifferentialDrive;
  14.  
  15. /**
  16.  * The VM is configured to automatically run this class, and to call the
  17.  * functions corresponding to each mode, as described in the IterativeRobot
  18.  * documentation. If you change the name of this class or the package after
  19.  * creating this project, you must also update the manifest file in the resource
  20.  * directory.
  21.  */
  22. public class Robot extends IterativeRobot {
  23.     VictorSP frontLeftMotor = new VictorSP(0);
  24.     VictorSP rearLeftMotor = new VictorSP(1);
  25.     VictorSP frontRightMotor = new VictorSP(2);
  26.     VictorSP rearRightMotor = new VictorSP(3);
  27.     SpeedControllerGroup leftSide = new SpeedControllerGroup(frontLeftMotor, rearLeftMotor);
  28.     SpeedControllerGroup rightSide = new SpeedControllerGroup(frontRightMotor, rearRightMotor);
  29.     DifferentialDrive myRobot = new DifferentialDrive(leftSide, rightSide);
  30.     XboxController controller = new XboxController(1);
  31.     Joystick stick = new Joystick(2);
  32.     Compressor compressor = new Compressor(0);
  33.     DoubleSolenoid solenoid = new DoubleSolenoid(0, 1);
  34.     Timer timer = new Timer();
  35.  
  36.     /**
  37.      * This function is run when the robot is first started up and should be
  38.      * used for any initialization code.
  39.      */
  40.     @Override
  41.     public void robotInit() {
  42.     }
  43.    
  44.     /**
  45.      * This function is called periodically during all robot modes
  46.      */
  47.     @Override
  48.     public void robotPeriodic() {
  49.        
  50.     }
  51.  
  52.     /**
  53.      * This function is run once each time the robot enters autonomous mode
  54.      */
  55.     @Override
  56.     public void autonomousInit() {
  57.         timer.reset();
  58.         timer.start();
  59.     }
  60.  
  61.     /**
  62.      * This function is called periodically during autonomous
  63.      */
  64.     @Override
  65.     public void autonomousPeriodic() {
  66.     }
  67.  
  68.     /**
  69.      * This function is called once each time the robot enters operator control
  70.      */
  71.     @Override
  72.     public void teleopInit() {
  73.         compressor.start();
  74.     }
  75.  
  76.     /**
  77.      * This function is called periodically during operator control
  78.      */
  79.     @Override
  80.     public void teleopPeriodic() {
  81.         myRobot.tankDrive(-controller.getY(Hand.kLeft), -controller.getY(Hand.kRight));
  82.         if(stick.getY() > 0) {
  83.             solenoid.set(DoubleSolenoid.Value.kForward);
  84.         } else if(stick.getY() < 0) {
  85.             solenoid.set(DoubleSolenoid.Value.kReverse);
  86.         } else {
  87.             solenoid.set(DoubleSolenoid.Value.kOff);
  88.         }
  89.     }
  90.    
  91.     /**
  92.      * This function is called once each time the robot enters test mode
  93.      */
  94.     @Override
  95.     public void testInit() {
  96.        
  97.     }
  98.  
  99.     /**
  100.      * This function is called periodically during test mode
  101.      */
  102.     @Override
  103.     public void testPeriodic() {
  104.     }
  105.    
  106.     /**
  107.      * This function is called once each time the robot enters disabled mode
  108.      */
  109.     @Override
  110.     public void disabledInit() {
  111.        
  112.     }
  113.    
  114.     /**
  115.      * This function is called periodically during disabled mode
  116.      */
  117.     @Override
  118.     public void disabledPeriodic() {
  119.        
  120.     }
  121. }
Add Comment
Please, Sign In to add comment