Hello Everyone,
I'm trying to calculate angles using the IXZ-500 gyro but I seem to be having issues properly calculating the angles. For example if I rotate the gyro 90* my calculated angle ends up being around 30. It also seems to be calculating different rates in the negative direction opposed to positive, ie: returning to "zero" positions doesn't give a calculated angle of zero. My Code is below, I'm using trapezoid rule integration with a sampling time of 100 ms. Where the angle should be:
angle=angle + (Z_old+Z_new)*.1
-------------------
2
Where Z_old and Z_new are angles using the conversion: z*(5000mv) (*/s)
---------- * --------
1024bit 9.1mv
I'm using the amplified Z-Output connected to analog pin 1 with VREF connected to analog pin 2.
Does anyone have experience doing something similar with gyros? I'm not sure if I'm converting my values properly or the gyro isn't accurate enough.
Thanks!
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int z1;
int z2;
int zo;
int zn;
float angle;
int zero_o;
int zero_n;
float anglerate1;
float anglerate2;
void setup()
{
lcd.begin(16, 2);
delay(1000);
zero_o=analogRead(2);
zo=zero_o;
delay(1000);
delay(1000);
}
void loop(){
zn = analogRead(1);
zero_n=analogRead(2);
z1=zero_o-zo;
z2=zero_n-zn;
anglerate1=z1*(5000/1024)/9.1;
anglerate2=z2*(5000/1024)/9.1;
angle=angle+(anglerate1+anglerate2)*.05;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("angle: ");
lcd.print(angle);
lcd.setCursor(0, 1);
lcd.print("Angle Rate: ");
lcd.print(anglerate1);
delay(100);
zo=zn;
zero_o=zero_n;}
Gyro Datasheet:
http://invensense.com/mems/gyro/documents/PS-IXZ-0500B-00-03.pdf