View Single Post
  #3   Spotlight this post!  
Unread 11-02-2011, 13:49
professorX professorX is offline
Registered User
AKA: Xavier
FRC #1660 (The Harlem Knights)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: New York
Posts: 62
professorX is an unknown quantity at this point
Re: Issue with autonomous mode and some newbie questions

Quote:
Originally Posted by Robby Unruh View Post
Your problem lies here:
Code:
for(int i =0; i < 10; i=+1){
    getWatchdog().feed();
    robotdrive.drive(1,0);
    Timer.delay(3);
    getWatchdog().feed();
}
You're using a timer delay in a loop. That means that everytime the loop is called (which is two, for whatever reason) you will have a 3 second delay. Plus, since you're wanting to drive for a set amount of time in autonomous, why not use the nifty Timer class?

Code:
Timer timer = new Timer(); // you should put this in your constructor.

public void autonomous() {
    while(isAutonomous()) {
        timer.start();
        while(timer.get() < 3) { // while the timer is < 3, drive forward.
            robotDrive.drive(1,0);
            timer.stop(); // stop the timer after 3 seconds
        }
        robotDrive.drive(0,0); // stop the robot from driving any further.
    }
}
I thought the timer delay pauses the code. Since the motors weren't told to stop before the timer delay so it should continue straight for 3 seconds. And it should do it 10 times according the for loop.
I think the issue is that the watchdog is not being fed during the pause so the robot shuts down. Could this be the issue and how could it be fixed?
Reply With Quote