Thread: Autonomous Help
View Single Post
  #5   Spotlight this post!  
Unread 16-12-2003, 13:58
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Re: Autonomous Help

It looks like you have the right general idea. Basically, what you're going to want to do is create a finite state machine to keep track of where in your autonomous program you are. In pseudocode, this would look something like:

Code:
auto_mode(){
  static int state = 0;

  updateState();

  switch(state){
  case 0:
    //do something, like drive forward, or turn left, etc
    break;
  case 1:
    //do a different something
    break;
  case 2:
     //dito
     break;
...etc...etc
  }
}
The key here is the updateState() part. Each time through the program loop, you'll want to check and see if some condition has been met that will make you want to change states. For example, let's say state 0 corresponds to driving forward, and you want to keep doing that until rc_sw1 gets triggered. You could then do something like this:
if(state == 0 && rc_sw1 == 1)
state++;

Then, you could make state 1 turn left (or anything else) for some number of seconds by doing something like:

if(state == 1 && (currLoopCount - startLoopCount) >= 20)
state++;

The easiest way to time is by counting how many times process_data_from_master_up() has been called, as it is called once every 17ms for the eduRC (it's something like 24ms for the full RC, but I don't remember exactly). You could do this with a global variable called currLoopCount that gets incremented at the start of every process_data_from_master_up() call, and then a static variable called startLoopCount inside your autonomous function that gets set to currLoopCount every time you transition from one state to another. Thus, currLoopCount - startLoopCount will give you the number of loops that you've been in the current state.

I'm sure that was about as clear as mud, so please feel free to ask questions about it and I'd be happy to answer.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php