how to read yaw angle of a gyroscope?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello. I am using ly330h analogue single axis gyroscope. I want to read the angle from it. It's output is angular velocity (degrees per second(dps)). I know that this is done through integrating the values I get from the ADC which is the sum of them but I don't know how to do this using ATMEGA, because I need the integration to start only after the gyroscope starts moving and stop after it sops and return to its zero rate. If you can provide codes it will be better.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Something like degrees = degrees + degreespersecond*deltatsecs where you read the read the degreesperseond from the gyro and thr deltatsecs is the interval between reading the gyro. Since reading the a/d takes 100 usecs, maybe 200 or 500 or 1000 usecs would be a good rate to read it.

Imagecraft compiler user

Last Edited: Sat. Mar 16, 2013 - 12:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's very hard to use a gyroscope to get a yaw reading since the output tends to drift, which is magnified by the integration of the values. Gyroscopes are more useful for using them to improve movement data. I suggest you use a magnetometer or an accelerometer instead for yaw measurements, because these are not affected by drift concerning angular state of a system, and find some clever algorithm to use your gyroscope data only in situations where the yaw changes quickly.

To find this out yourself, you can use a (naive) algorithm like:

float angle = 0; //set the initial angle to 0
while(1){
	angle += get_dps() * get_time_since_last_measurement(); // estimation only
}

where get_dps returns the angular rate, and get_time_since_last_measurement returns the time in seconds(float). Please tell us what you've tried or came up with yourself before asking for more help :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mohammed_mustafa_91 wrote:
Hello. I am using ly330h analogue single axis gyroscope. I want to read the angle from it. It's output is angular velocity (degrees per second(dps)).

For some background information, read this tutorial.

-- Damien

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you all, I get how to integrate the data I read from ADC I just don't know how to use the timer to estimate the interval between the readings?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is the code I used. I wrote a function to read the gyroscope,using it the readings are only integrated during the movement, that's when the value is higher or lower than the zero level voltage which is 1.5 v. I chose to start integrating when it goes higher than 1.6 or lower than 1.4 to make it immune to small fluctuations and noise. It's working well for me, the only draw back is if I try and set the sum back to zero after it ends the result becomes wrong, this means the angle I get is with respect to the initial position always but that's not a problem if I knew the initial position and this fits my application very well. Thank you all :)

float read_gyro0()              // find the position of gyro0
{
    
    z0= read_adc(0);            
    if (z0 > 496 || z0 < 434)   // has a  movement occur?
    {  
       state=1;                     // gyro is moving, enter loop
       while(state)
       { 
            if (z0 > 496)           // is the movement positive?
            {
                state=1;            
                sum0+= z0;          // integrate
            }   
       
            if(z0 < 434)            // is the movement negative?
            {    
                state=1;
                sum0-= z0;          // integrate
            }     
       
            if(z0 <= 496 || z0 >= 434)  // did the gyro stop?
            { 
                state=0;                    // gyro stopped, get out of the loop
                z_angle0 = sum0*3.3/1024;     // calculate the horizontal position in degrees
            }
               
            z0=read_adc(0);             
       }   
    }  
    
    return z_angle0 ;                         // return the angle value
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Get yourself a mpu-6050 and avoid the headache.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Get yourself a mpu-6050 and avoid the headache.

This one is really nice solution .
Ready to use library .
No need Kalman nor cosin matrix etc. It have Digital Motion Processor .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I live in Sudan so it's not easy to get components here, that's why I have to work with what I got. Thanks anyway.