View Single Post
  #3   Spotlight this post!  
Unread 30-04-2010, 15:01
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,856
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Older FRC autonomous code

Those are the break;'s
The break statement concludes individual cases. Without it one case statement blends right into the next without a "break".
That is one of the reasons for stopping all motors at the end.

I unfortunately duplicated one block and missed copying the original break statement as part of the block of code.
Sorry about that...

Corrected version:
Code:
// Drive forward, turn, return, and stop
 
void Autonomous()
{
 static int counter=0; //keep track of loops to use as a crude timer - static keeps it around from call to call
 static int autostate=1;   //keep track of what step we're supposed to be doing
 
  switch (autostate)
  {
    case 1:   // Drive forward
        pwm01 = pwm02 = 200;
        pwm03 = pwm04 = 54;  //motor is reversed
        if (counter>38)  //1 second
        {  
           autostate = 2;  // move on to the next step
           counter = 0;    // reset our timer for the next step
        }
        break;
 
    case 2:   // Turnaround
        pwm01 = pwm02 = 200;
        pwm03 = pwm04 = 200;  //motor is reversed
        if (counter>76)  //2 seconds
        {  
           autostate = 3;
           counter = 0;
        }
        break;

 
    case 3:   // Drive forward (returning now)
        pwm01 = pwm02 = 200;
        pwm03 = pwm04 = 54;  //motor is reversed
        if (counter>38)  //1 second
        {  
           autostate = 4;
           counter = 0;
        }
        break;

 
     case 4:   // Stop - What to do when everything else is done
     default:  // also what to do if an invalid autostate occurs
 
       pwm01 = pwm02 = pwm03 = pwm04 = 127;   // Make sure the last thing you do is always stop
  }
  counter++;
}
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 30-04-2010 at 15:13.