Log in

View Full Version : Loop in autonomous carries on into teleop and stops anything from working?


joelg236
31-01-2012, 20:10
I have teleop working fine when its enabled first, but (My autonomous code is not working yet but thats a separate issue) after enabling autonomous, neither it nor teleop works at all. Also, we have a do while loop set up in autonomous that doesn't actually stop when turned to teleop. Is this a driver station bug or maybe is it the fact I dont have watchdog enabled? Any suggestions?
public void autonomousPeriodic(){
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);
}

That's our autonomous.

kgabbott
31-01-2012, 20:26
This is occurring because you enter the do while loop and never reset x to a value less that 0, meaning the code continuously runs through this loop.

joelg236
31-01-2012, 20:51
Funny, we fixed that, and still have the error with our very simple fix.
This does the same thing.

timer.start();
do{
drivetrain.drive(0.5,0.0);
}while(timer.get()<4);

And yes, we did initialize the timer.

neal
31-01-2012, 20:54
Do this instead:


while (isAutonomous() && isEnabled()) {
// Autonomous code
}

eddie12390
01-02-2012, 11:49
do{
drivetrain.drive(0.5,0.0);
}while(timer.get()<4 && isAutonomous());

Derschatten
01-02-2012, 16:31
I would suggest doing it the way Neal has wrote it. You can always have if statement or switch statement handling the time base options.

joelg236
02-02-2012, 16:14
Thanks for the replies guys. What I found out was that the iterative robot class is a completely different concept than simplerobot. I was mistaken in thinking it was just more features.