Monday, 22 August 2011

How to use gyroscope?

I told you here, that gyro gives us angular velocity. They are two common ways that most gyro use, one is I2C or Analog output. In both methods, you have to find a value which is equivalent to zero angular velocity. In order to find this value, you have to read your sensor output while it is not moving. They are few different ways to measure this value.


1) you can read the value every time that you turn on your controller, which means your vehicle has to start while it is not moving.
2) you can read this value once, and just use that as a constant in your program
3) You can read this value when ever you want and save it in dynamic memory (you will not lose it if you turn your controller off)

So far we just found a value which represent zero. Let's call this value "zero_representer".
We refer the out put from sensor, "sensor_output"
There is a factor provided by company that gives your out put in second/degree or any equivalent unit, we call this value "factor".

angular_velocity =  (sensor_output -  zero_representer)  *  factor

There is now way improving this reading as far as I know.
Now we have to integrate (in order to integrate you have to turn on a timer and count time between your readings).
dt is the time interval. they are two ways measuring this that you can find it here.

 angle_change = angular_velocity * dt   (formula # 1)
this basically shows how many degrees you have changed over an specific axis during dt.

they are ways that you can make this more accurate which is using the following procedure:
you use this formula
 angle_change =   angle_change  + ( angular_velocity * dt )
 You let this formula to run in your controller and after certain time, let's say two minutes you read the out put.  Keep in mind that during this two minutes you will not move the gyroscope.
 Now imagine in two minutes your reading is 2 degree. Which means that the rate for drifting is equal to 2degree/2min which is equal to 1 degree/min. You have to change the time unite to the same unit that you used for dt. Let's say our dt was in second, so here our rate will be 1/60 degree/second.

now we use this rate in formula #1:
    angle_change =  (angular_velocity * dt ) - (rate * dt)     (formula # 2)

now we know that this is more accurate.
As far as I know there is no other way make this more accurate.

I stop this here, you may think that it does not make any sense to calculate angle_change but later I show you how we use this.

No comments:

Post a Comment