View Single Post
  #1   Spotlight this post!  
Unread 16-12-2007, 09:01
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: user_routines_fast

The user_autonomous_code function is indeed fast:
Code:
void User_Autonomous_Code(void)
{
  // ... stuff deleted for clarity
  while (autonomous_mode)   /* DO NOT CHANGE! */
  {
    // this part here happens over and over very very quickly
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {		
        // ... stuff deleted for clarity
        // this code is only executed once every 26.2ms
    }
    // back to really really fast code here
  }
}
When you're waiting the RC to indicate that there is new data, you're just doing a busy loop spinning around the while(autonomous_mode) loop. This will happen as fast as the RC can do it, which is entirely dependant on how much code is there.

If you wanted to know how fast that is without any code to execute, you could do this (note that lots of default code here is omitted for clarity):
Code:
void User_Autonomous_Code(void)
{
  int cExecutions;
  
  while (autonomous_mode)   /* DO NOT CHANGE! */
  {    
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {  
        // I don't remember the exact printf syntax, it has been awhile
        printf("%d\r\n cycles in 26.2ms means %d per second",cExecutions,(10000*cExecutions)/262)); 
        cExecutions = 0;
    }
    cExecutions++;
    // back to really really fast code here
  }
}
So cExecutions will increment on every fast loop, then once you get into the 26.2ms code, you print it out and reset it to zero. This way, you can tell how many fast loops occurred per slow loop, and thus derive how many fast loops you get per second. But keep in mind, the fast loops per second count will change dramatically as you add new code to the fast-loop portion.

Last edited by Bongle : 16-12-2007 at 12:50.