All pastes #2108473 Raw Edit

Miscellany

public text v1 · immutable
#2108473 ·published 2012-02-01 02:44 UTC
rendered paste body
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.*;

public class RobotTemplate extends IterativeRobot {

    public RobotDrive drivetrain;
    public Joystick joystick;
    public Gyro gyro; //gyro
    public Timer timer; 
    
    

    public void robotInit(){
        drivetrain = new RobotDrive(1, 4, 3, 2);  
        joystick = new Joystick(1);    
        gyro = new Gyro(1);
        gyro.reset();
        timer = new Timer();
    }


    public void autonomousPeriodic(){
        int x = 1;
        timer.reset();
        timer.start();
        do {
           // timer.stop();
            log(""+ timer.get());
            drivetrain.drive(0.5,0.0); //START GOING STRAIGHT
        }while(timer.get()<2.0);

       drivetrain.drive(0.0,0.0);
       timer.delay(20); 
        /*
        do{    
            gyro.reset();

            int i = 0;
           
            while(i<4){    
                drivetrain.drive(0.5,0.0); //START GOING STRAIGHT
                Timer.delay(4.0);
                drivetrain.drive(0.0,0.0); //STOP
                Timer.delay(4.0);
                gyro.reset();
                double angle = 0;
                do {
                    drivetrain.drive(0.0, 0.25); //TURN 
                    Timer.delay(0.5);
                    angle += gyro.getAngle() - 0.0009; //
                    gyro.reset();
                    log("Gyro reads "+angle);
                    i++;
                }while(angle<90||i>9); //Keep going in increments of .15 until gyro returns more than 90 degrees
                drivetrain.drive(0.0,0.0); //STOP
                Timer.delay(4.0);
                i++;
            }
            x++;
        }while(x>1);
        * 
        */
    } 

    public void teleopPeriodic() {
        while (isOperatorControl() && isEnabled()){
            if(joystick.getTrigger())
                {drivetrain.drive(0,0);
                log("Brake enabled");}
            double YAxis = joystick.getAxis(Joystick.AxisType.kY);
            double XAxis = joystick.getAxis(Joystick.AxisType.kX);
            drivetrain.drive((-1*YAxis),XAxis);
        }
    }
    public static String log(String logText){
        System.out.println(logText);
        return logText;
    }
}