View Single Post
  #4   Spotlight this post!  
Unread 20-06-2008, 13:23
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,356
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: BEI Gyro Accuracy

Quote:
Originally Posted by John Gutmann View Post
I guess the part I am really interested in is this, because this is what I am having troubles with:

Code:
/*************************************************
Timer ISR to get Gyro value at rate 
determined in SetuoTimer2
**************************************************/
ISR(TIMER2_OVF_vect)
{
  //Toggle the IO pin to the other state.
  //digitalWrite(TOGGLE_IO,!digitalRead(TOGGLE_IO));
sample_accum  += analogRead(GyroPin);
sample_counter ++;
  if (sample_counter == SAMPLES_PER_UPDATE)
  {
    val = (sample_accum/SAMPLES_PER_UPDATE)-gyroBias;
    if (val < -DEADBAND || val > DEADBAND)
    {
    gyro_angle += (long)val;
    }
    sample_accum = 0;
    sample_counter = 0;
  }
  //Capture the current timer value. This is how much error we
  //have due to interrupt latency and the work in this function
latency=TCNT2;
  //Reload the timer and correct for latency.
TCNT2=(latency + timerLoadValue);
}

What why are you toggling a pin?
The latency part is just accounting for the time spent processing?

Other then those 2 things my ISR is basically the same.
I cant really post the code now because I am at work, but I can give a brief pseudo coding of it.

Code:
get adc reading
if it is less then dead band
     then subtract from position
if it is greater then dead band
     then add to position
else do nothing

send position over USART
I know I am technically using an accumulated rate but lets assume I am using a Riemann sum with a coefficient of 1.

Thanks,
John Gutmann

EDIT: I think when I get home I will try to eliminate the dead band, and see if that will help any.
Well, that is what happens when you have compiled bits and pieces of different code, from various times during the creation process together and forget to remove the commented out sections you don't use anymore.

If you will notice, those two lines are commented out. I had originally used them to toggle an LED on and off so I could measure the rate at which I was generating the ISR. I just attached an o-scope to the LED pins to do the measuring and verification. Once I proved to my self I actually made good assumptions, I commented those lines out. Sorry for the confusion.

The latency part is exactly as you described. It adjusts for the various time spent in the ISR and keeps the sample rate consistent. I suppose I could have streamlined it by doing this.

Code:
TCNT2 += timerLoadValue;
I'll have to verify this later.
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist