Go Down

Topic: Arduino 3DOF Head Tracker (Read 18 times) previous topic - next topic

tufan

Well Done work..Does your code eliminate bias drift of the yaw gyro, exactly?

zitron

No, it does not eliminate gyro drift. I've programmed it to recentre when I lower my head. You can see me do that a couple of times in the video.

tufan

I have some questions.if you could answer i would be glad.In your code,

void A2Ddata(unsigned int n) {
 long tempG = 0, tempX = 0, tempY = 0, tempZ = 0;

 for(unsigned int k = 1; k <= n; k++){
   tempG += analogRead(gPin);  
 }
 gRaw = tempG*10/n;  ????
}



???? what the value you get ?   is it radians/sec or deg/sec ?   is tempG  given you as raw value of the sensor ?
especially i didnt understand the  temG*10/n ?    what this calc. do?




A2Ddata(8);   ????   why did you send 8 ?

   //Calculate gyro turn rate
   rate = (gRaw*Vin/100-gOffset)*0.0150;   ??

   if (abs(rate) > 2.5) {
     angle += (rateold+rate)*0.010;  //trapz intergration   ???
   }
   rateold = rate;


??  what this rate means ?
??? this should be the integration to calculate angle.




// code to reduce gyro drift under steady conditions
   if (rate < 5) {
     if (rate > 0) {
       gOffset++;
     }
     else{
       gOffset--;
     }
   }

Did you use this in your code?



I am sorry about these question, it is a lot. But really i need these because i am at the end of edge my thesis. Thanks your help

zitron

Quote
void A2Ddata(unsigned int n) {
long tempG = 0, tempX = 0, tempY = 0, tempZ = 0;

for(unsigned int k = 1; k <= n; k++){
  tempG += analogRead(gPin);  
}
gRaw = tempG*10/n;  ????
}



???? what the value you get ?   is it radians/sec or deg/sec ?   is tempG  given you as raw value of the sensor ?
especially i didnt understand the  temG*10/n ?    what this calc. do?


Uhm... A2Ddata(n) simply averages n readings from the A2D converter. If you take the average of many readings from a noisy sensor, the average will have more resolution than the A2D converter readings, so by using temG*10/n I keep some of the increased resolution. So A2Ddata(8) takes the average of 8 readings. These are just raw A2D readings.

Code: [Select]
rate = (gRaw*Vin/100-gOffset)*0.0150;  

gRaw is the raw gyro value*10, Vin/100 is the A2D full scale voltage (322/100) or 3.22V. This voltage is feed to the VRef pin of arduino. gOffset is the voltage from the gyro when it's stationary*10, and 0.0150 finally converts everything into degree/s. I'm assuming my gyro has a response of 150dgr/s/V output, it's pretty close to that.

Code: [Select]
angle += (rateold+rate)*0.010;  //trapz intergration
rateold = rate;


This does a second order trapezoidal integration, the formula is:

y_n = y_n-1 + ( x_n + x_n-1 )/2 *dt

dt/2 in my case is approximately 0.010

Quote

Did you use this in your code?


That bit of code does work to reduce drift when the head tracker is stationary, but it's not good when it's moving.

My code is very basic. I'm working on a better drift removal method by using a digital high-pass filter.

Hope this helps,
-Z-


tufan

Thank you, i really appreciate your help.

Go Up