Quote:
Originally Posted by notmattlythgoe
Yes you can, but you are going to want to make sure that you put the distance variable in the second loop so it gets updated when you are driving.
Another thing I forgot to have you do is reset the encoder prior to the second loop. You can do this in the same place you reset the gyro.
|
I think this is perfect now I am very excited to test this.
Code:
public void autonomousPeriodic() {
gyro1.reset();
while(isAutonomous() && isEnabled()) {
double angle = gyro1.getAngle();
double distance = encoder.getDistance();
SmartDashboard.putNumber("Angle", angle);
SmartDashboard.putNumber("Distance", distance);
robot.drive(-0.25, 1);
if(angle > 150) {
robot.drive(0,0);
gyro1.reset();
encoder.reset();
Timer.delay(1.00);
break;
}
Timer.delay(0.1);
}
while (isAutonomous() && isEnabled()) {
double distance2 = encoder.getDistance();
double angle2 = gyro1.getAngle();
robot.drive(-0.20, -angle2 * Kp);
if(distance2 > 50) {
robot.drive(0,0);
break;
}
Timer.delay(0.1);
}
}