View Single Post
  #12   Spotlight this post!  
Unread 20-02-2015, 20:38
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: functions for auto

Quote:
Originally Posted by Arhowk View Post
hm?

note that I edited that post like 5 times.

Anyway, heres a (maybe) working function

Code:
public static double angleError(double setpointDegressZeroToThreeSixty, double experimentalDegrees){
    double err = setpointDegressZeroToThreeSixty - experimentalDegrees; //0 360
    if(err < -180){
        err += 360;
    }else if(err > 180){
	err -= 360;
    }
    return err;
}

double kp_rotate = 0.01;
double MAX_ERROR = 5;

public static void turn(double deg){
    while(true){
        double deltaAngle = angleError(deg, gyro.getAngle());
        if(Math.abs(deg-deltaAngle) < MAX_ERROR){
            break;
        }else{
            robot.drive(0, deltaAngle*kp_rotate); //drive taking a move and a rotate value
        }
        Timer.delay(0.02);
    }
}
Does this turn function replace left turn and right turn?
Reply With Quote