Guest User

Untitled

a guest
Jun 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. /*
  2.  
  3. THIS CODE IS MADE BY THE BEST PEOPLE IN THE WORLD, DO NOT STEAL.
  4.  
  5. THINGS TO  ARE IN CAPS
  6.  
  7. Instructions are in sentence form.
  8.  
  9. */
  10. package edu.wpi.first.wpilibj.templates;
  11. import edu.wpi.first.wpilibj.*;
  12. // import edu.wpi.first.wpilibj.smartdashboard.SmartDashboardData; //WORKING ON THIS(1)
  13.  
  14. public class Robot4334 extends SimpleRobot {
  15.                                                    //DECLARE ALL METHODS IN INIT AND SIMPLEROBOT
  16.     public RobotDrive drivetrain;
  17.     public Joystick joystick;
  18.     public Joystick XBoxController;
  19.     public Gyro gyro; //gyro
  20.     public Timer timer;
  21.     public Encoder encoder;
  22.     public static final double DRIVE_STRAIGHT = 0;
  23.     public static final double DRIVE_FULL_SPEED = 1; //Variable set for driving full speed for ease of use
  24.     public static final int LeftX = 1;
  25.     public static final int LeftY = 2;
  26.     public static final int Triggers = 3; //(Each trigger = 0 to 1, axis value = right - left)
  27.     public static final int RightX = 4;
  28.     public static final int RightY = 5;
  29.     public static final int DPad = 6;
  30.     public static String log(String theMessage){ // Logger -System.out.println function
  31.         System.out.println(theMessage);
  32.         return theMessage;
  33.     }
  34.     public void BRAKE(){ //Brake method - stops motors
  35.         drivetrain.drive(0.0,0.0);
  36.         drivetrain.stopMotor();
  37.     }
  38.     public void EMERGENCY(){ //ADD ALL FUNCTIONS HERE TO STOP ON ROBOT DURING EMERGENCY
  39.         drivetrain.drive(0.0,0.0);
  40.             Timer.delay(10.0);
  41.         drivetrain.stopMotor();
  42.     }
  43.     public void RESET(){
  44.         gyro.reset();
  45.         timer.reset();
  46.         drivetrain.stopMotor();
  47.     }
  48.     public double returnSpeed(){
  49.             double speed = XBoxController.getRawAxis(LeftY);
  50.             return speed;
  51.     }
  52.         public double returnTurn(){
  53.             double Turn = XBoxController.getRawAxis(LeftX);
  54.             return Turn;
  55.     }
  56.  
  57. /*
  58. XBoxController index Axis: (.getRawAxis())
  59. * Set XBoxController settings in driver (.getRawButton())
  60. */
  61.     public void robotInit(){ //REMEMBER TO INITIALIZE EVERYTHING
  62.         drivetrain = new RobotDrive(1, 2, 3, 4);
  63.         joystick = new Joystick(1);  
  64.         XBoxController = new Joystick(1);
  65.         gyro = new Gyro(1); // FIND CORRECT INPUT FOR THIS
  66.    //   encoder = new Encoder(); //FIND CORRECT INPUT
  67.     }
  68.  
  69.     public void autonomous(){
  70.         while(isAutonomous()&&isEnabled()){ //Makes sure in autonomous.
  71.             drivetrain.drive(.5,.0);
  72.             Timer.delay(1);
  73.             drivetrain.drive(.1,.5);
  74.             Timer.delay(1);
  75.         }
  76.     }
  77.  
  78.     public void operatorControl() {
  79.         while (isOperatorControl() && isEnabled()){ //Make sure in driver
  80.             log("\n\n\n\n\n\n\n\n\n\n\nIn operator control");
  81.             if(XBoxController.getRawButton(2)){BRAKE();}else{
  82.                 double speed =returnSpeed();
  83.                 double turn =returnTurn();
  84.                 drivetrain.drive(speed,turn);
  85.             }
  86.         }
  87.     }
  88. }
Add Comment
Please, Sign In to add comment