ROBOTC.net forumshttp://robotc.net/forums/ Angular rotation using Dexter Gyroscopehttp://robotc.net/forums/viewtopic.php?f=41&t=4463 Page 1 of 1

Author:  Farshid.T [ Mon Apr 23, 2012 4:09 am ]
Post subject:  Angular rotation using Dexter Gyroscope

Hi,
I want to get angular rotation using a Dexter gyro but I have more 5-10 degree error in 90 degrees rotation.
This is how I use dps to get rotation:
 Code:DIMUconfigGyro(DIMU, DIMU_GYRO_RANGE_2000);float x_val, y_val, z_val;  while (true){    static int time_temp = 0;    static float total = 0;         // Read the GYROSCOPE    DIMUreadGyroAxes(DIMU, x_val, y_val, z_val);           short loop_delay = nPgmTime-time_temp;    time_temp = nPgmTime;    total += x_val/(1000.0/loop_delay); //  x_val/(1000/50) won't be accurate.         nxtDisplayBigTextLine(4, "Rotation:%f", total);     wait1Msec(50);  }

I'm not sure if that's the correct way to get rotation. If that's the correct way, I guess the inaccuracy is related to third last line of my code. If I divide x_val by a number near 17 the error reduces to 1-2 degrees. (1000.0/loop_delay)=18.5 approx.

Please tell me if I am doing something wrong.
Thanks,

 Author: mattallen37 [ Mon Apr 23, 2012 1:19 pm ] Post subject: Re: Angular rotation using Dexter Gyroscope For an integration loop, it's best to loop as quickly as possible (maybe a 5ms wait). Also, I think using the 250 dps range will give you much higher resolution.

Author:  Farshid.T [ Tue Apr 24, 2012 11:53 pm ]
Post subject:  Re: Angular rotation using Dexter Gyroscope

 mattallen37 wrote:For an integration loop, it's best to loop as quickly as possible (maybe a 5ms wait). Also, I think using the 250 dps range will give you much higher resolution.

5ms wait doesn't make any improvement to 50ms.
with 250dps range, with gyro being static, the rotation starts to increase or decrease very fast. 2000dps gives much lower error in this case.

p.s : If i manually rotate the unit 90 degrees. total x_val will be 1520-1540. 1530/90 gives us 17 and if I divide x_val by 17 the output gets accurate.
Now the problem is that output keeps increasing or decreasing with respect to the direction of last rotation. I assume that happens to all gyroscopes..

Author:  MHTS [ Wed Apr 25, 2012 3:22 am ]
Post subject:  Re: Angular rotation using Dexter Gyroscope

You should not initialize time_temp to zero. That would introduce a random error to your integration because nPgmTime doesn't start at zero. Instead you need to do this:
 Code:DIMUconfigGyro(DIMU, DIMU_GYRO_RANGE_2000);float x_val, y_val, z_val;float total = 0;int time_temp = nPgmTime;  while (true){        // Read the GYROSCOPE    DIMUreadGyroAxes(DIMU, x_val, y_val, z_val);           short loop_delay = nPgmTime-time_temp;    time_temp = nPgmTime;    total += x_val/(1000.0/loop_delay); //  x_val/(1000/50) won't be accurate.         nxtDisplayBigTextLine(4, "Rotation:%f", total);     wait1Msec(50);  }

There may be some other issues with the calculation but not knowing the spec of the gyroscope you are using, I wouldn't know.

Author:  Farshid.T [ Thu Apr 26, 2012 10:09 pm ]
Post subject:  Re: Angular rotation using Dexter Gyroscope

 MHTS wrote:You should not initialize time_temp to zero. That would introduce a random error to your integration because nPgmTime doesn't start at zero. Instead you need to do this:...There may be some other issues with the calculation but not knowing the spec of the gyroscope you are using, I wouldn't know.

That's correct. The code i wrote does not take into account the time before starting the loop.

Thanks for the tip !

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/