View unanswered posts | View active topics It is currently Thu Jul 24, 2014 2:05 am






Reply to topic  [ 5 posts ] 
Angular rotation using Dexter Gyroscope 
Author Message
Rookie

Joined: Thu Mar 01, 2012 11:01 pm
Posts: 3
Post 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,


Mon Apr 23, 2012 4:09 am
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post 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.

_________________
Matt


Mon Apr 23, 2012 1:19 pm
Profile WWW
Rookie

Joined: Thu Mar 01, 2012 11:01 pm
Posts: 3
Post 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.

Thanks for your reply.
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..


Tue Apr 24, 2012 11:53 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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.


Wed Apr 25, 2012 3:22 am
Profile
Rookie

Joined: Thu Mar 01, 2012 11:01 pm
Posts: 3
Post 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 !


Thu Apr 26, 2012 10:09 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.