View Single Post
  #4   Spotlight this post!  
Unread 20-02-2015, 20:20
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: functions for auto

Quote:
Originally Posted by curtis0gj View Post
lol I did a very lousy job of naming things, sorry for that and I will change the names to be more descriptive and properly cased. Anyway how can I get the waits to work again? This is the function,


I'm not sure how to program it, sorry I'm still fairly new to programming.
here's what I'd do

Code:
public static void turn(Robot r, double deg) {
   if(deg < gyro.getAngle()){ //this is not right, need to have a function to handle rollovers
   //example for such a function: if Math.abs(deg-gyro.getAngle()) < 90 || Math.abs(deg-gyro.getAngle()) > 270
   //i dont know, just thinking to myself. see here for further instructions -> http://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles
         turnLeft(r,deg);
   }else{
         turnRight(r,deg);
   }
}
public static void turnRight(Robot r, double deg){
   while(true){
       //turn right
       if(distanceBetweenAngles(getGyro(),deg) <= MAX_ROTATE_ERROR){
           return; //or break; whatever
       }
       Timer.delay(0.02);
    }
}
except without the broken formatting since I made that in this text editor and not a code editor

E/ misunderstood the point of the code, fixed.

Last edited by Arhowk : 20-02-2015 at 20:27.
Reply With Quote