View Single Post
  #11   Spotlight this post!  
Unread 30-03-2004, 23:21
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: More automonous help:ending stuff

Try this. In user_routines_fast.c replace the User_Autonomous_Code function with the function below. It's not a state machine, but it incorporates elements that you probably understand better.

All: Please check this for bugs!

Code:
void User_Autonomous_Code( void )
{
  static unsigned int Old_Clock = 0;

  static unsigned int time = 0;  // cycle counter
  
  while (autonomous_mode)
  {
    if (statusflag.NEW_SPI_DATA)
    {
      Getdata(&rxdata);   // bad things will happen if you move or delete this
      
      // Autonomous code goes here.
      
      if (Clock > Old_Clock) // stay synchronized to beacon data updates (this is important)
      {
        /////////////////////// CUSTOM CODE /////////////////////////
        if ( time < 456 )  // still less than 12 seconds have elapsed
        {

          // LINE FOLLOWING
          // there are 3 bits which means 8 combinations.  
          // only 4 are tested here. ??
          if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 0)
          {
            pwm13 = 127;  // stop
            pwm15 = 127;
          }
          else if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 1)
          {
            pwm13 = 139;  // turn one way
            pwm15 = 175;
          }
          else if (rc_dig_in01 == 1 && rc_dig_in02 == 0 && rc_dig_in03 == 0)
          {
            pwm13 = 175;  // turn the other way
            pwm15 = 139;
          }
          else if (rc_dig_in01 == 0 && rc_dig_in02 == 1 && rc_dig_in03 == 0)
          {
            pwm13 = 249;  // go straight and fast
            pwm15 = 249;
          } 
          
        }
        else if ( time < 532 )  // 12 seconds have gone by, but less than 14
        {
          // stop wheels
          pwm13 = 127;
          pwm15 = 127;
          
          // raise arm
          pwm03 = 175; 
        }
        else  // more than 14 seconds have gone by
        {
          // stop raising arm
          pwm03 = 127; 
        }
        
        time++;  //  count another cycle

        /////////////////////// END OF CUSTOM CODE /////////////////////////
        
        Old_Clock = Clock; // take a snapshot of the clock
        
      } // clock > oldclock
      
      Generate_Pwms( pwm13, pwm14, pwm15, pwm16 );
      
      Putdata(&txdata);   // even more bad things will happen if you mess with this
      
    } //  statusflag.NEW_SPI_DATA
  }  // while (auotnomous) 
}
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.