View Single Post
  #2   Spotlight this post!  
Unread 20-02-2007, 12:02
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Sonar Function Issue

Quote:
Originally Posted by Andrew Blair View Post
As well, if anyone can quickly through up a workable averaging function I'd be much obliged.
Team 95 has a huge number of IR sensors (BigHAIR: Big Honkin Array of IR sensors), and we keep time history and a running average on them. Here's a snippet

Code:
long IR_range[6]; // current ranges, generated by another function
long IR_range_history[6][4];  // Last 4 readings, not necessarily in order (see below)
long IR_range_average[6]; // running average of last 4 readings

void Average_IR(void) {
   static counter=0;  

   index=counter++%4;  // Keeps from having to copy old data, just
                                 // overwrite one column at a time

   for (i=0;i<6;i++) {
        IR_range_history[i][index]=IR_range[i];
        IR_range_average[i]=0;
        for (j=0;j<4;j++) {
           IR_range_average[i]+=IR_range_history[i][j];
        }
        IR_range_average[i]/=4;
   }
}