View Single Post
  #3   Spotlight this post!  
Unread 31-01-2012, 19:17
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: New to FRC programming... How does this look?

Thanks so much for the help
Look better?

Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.*;
 
public class RobotTemplate extends IterativeRobot {
 
    public RobotDrive drivetrain;
    public Joystick joystick;
    public Joystick KTrigger;
    public Gyro gyro; //gyro
   
   
 
    public void robotInit(){
        drivetrain = new RobotDrive(1, 2, 3, 4); 
        joystick = new Joystick(1);   
        KTrigger = new Joystick(1);
        gyro = new Gyro(1);
    }
 
 
    public void autonomousContinous(){
        int x = 1;
        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.15); //TURN
                    Timer.delay(0.5);
                    angle += gyro.getAngle(); //
                    gyro.reset();
                    log("Gyro reads "+angle);
                }while(angle<90); //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++;
            }
        }while(x>0);
    }
 
    public void teleopContinous() {
        while (isOperatorControl() && isEnabled()){
            if(KTrigger.getTrigger())
                {drivetrain.drive(0,0);
                log("Brake enabled");}
            double YAxis = joystick.getAxis(Joystick.AxisType.kY);
            double XAxis = joystick.getAxis(Joystick.AxisType.kX);
            drivetrain.drive(YAxis,XAxis);
        }
    }
    public static String log(String aMessage){
        System.out.println(aMessage);
        return aMessage;
    }
}
Reply With Quote