Gryoscope is driving me up the wall
Technic-R-C
Posts: 117
Hello Folks,
I've got a question in regards to a bit of code that I am working on.· I recently purchased an ADXRS300 gyro and
have spent the last couple of days trying to convert the analog values to degrees.· At the moment I am using an ADC0831
along with a BS2px and am trying to get these degree values to show up but I just can't seem to do it.
This is what I've done so far:
Gyro Calculations:
'·51.2 steps per volt (256 steps total (ADC031) divided by 5 volts)
' ADXRS 300 = 5 mV/°/s
' 51.2·/ 1000mV·*·5 mV/°/s = .256 steps per degree per second
' 2.5 V = ADC031 128 Reading
' 0 V = 0 "············ "
' 5 V = 256 "············ "
' 40 Hz gyro
This is my ADC031 values to degrees conversion:
In regards to this code I am not sure how to manipulate degreesPerSec to just equal degrees.
Using unit conversion I multiplied x degrees/sec by Hz (1sec / 40 cycles) to get degrees/cycle?? Is this the number I am looking for?
I am also having problems with the ADC0831 code... From my debug window, the gyro seems to be resetting itself instantly after I turn it a certain number of degrees?·
·The gyro starts at around 2.6V as it should and an ADC value of around 134.· When I·rotate the gyroscpe the value changes but then instantly changes back to this initial voltage and ADC value?· The only thing I can think of is that the ADC0831 is resetting itself and this in turn resets the gyro?
All help is much appreciated
Thank you
Technic-R-C
I've got a question in regards to a bit of code that I am working on.· I recently purchased an ADXRS300 gyro and
have spent the last couple of days trying to convert the analog values to degrees.· At the moment I am using an ADC0831
along with a BS2px and am trying to get these degree values to show up but I just can't seem to do it.
This is what I've done so far:
Gyro Calculations:
'·51.2 steps per volt (256 steps total (ADC031) divided by 5 volts)
' ADXRS 300 = 5 mV/°/s
' 51.2·/ 1000mV·*·5 mV/°/s = .256 steps per degree per second
' 2.5 V = ADC031 128 Reading
' 0 V = 0 "············ "
' 5 V = 256 "············ "
' 40 Hz gyro
This is my ADC031 values to degrees conversion:
Calc_Degree: steps = (51 / 1000) * 5 degreePerSec = adcBits / steps degree = degreePerSec / 40 ' is this the correct conversion???? RETURN
In regards to this code I am not sure how to manipulate degreesPerSec to just equal degrees.
Using unit conversion I multiplied x degrees/sec by Hz (1sec / 40 cycles) to get degrees/cycle?? Is this the number I am looking for?
I am also having problems with the ADC0831 code... From my debug window, the gyro seems to be resetting itself instantly after I turn it a certain number of degrees?·
ADC_Data: LOW CLK LOW CS PULSOUT CLK, 210 SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8] HIGH CS RETURN Calc_Volts: v = 5 * adcBits / 255 r = 5 * adcBits // 255 v2 = 100 * R / 255 RETURN
·The gyro starts at around 2.6V as it should and an ADC value of around 134.· When I·rotate the gyroscpe the value changes but then instantly changes back to this initial voltage and ADC value?· The only thing I can think of is that the ADC0831 is resetting itself and this in turn resets the gyro?
All help is much appreciated
Thank you
Technic-R-C
Comments
If the unit is in fact a gyro.....then it will nullify itself. Gyro's only give rate of turn information.......so they only output while the unit is in motion/rotation.
Now if the unit is an accelerometer....that is different, for it has reference to the gravitational pull of the earth.
I know that is not something you wanted to hear.....but electronic gyros must be paired to some other sensor to derive their heading (compass, accelerometer, magnometer, etc).
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Please note: Due to economic conditions the light at the end of the tunnel will be turned off until further notice. Thanks for your understanding.
That makes perfect sense!· Now the only thing I need to figure out is, how to calculate the max amount of degrees the gyro moved in one rotation...
I've been looking at the code and I think the problem might be caused by·the·use of·small decimal numbers to calculate the rotation (floating point math).· However i am not sure what is wrong...
Technic-R-C
Post Edited (Technic-R-C) : 9/30/2009 1:37:02 AM GMT
But directional gyros indicate an angle of rotation from some zero state.· Artificial horizons indicate the bank angle, and not the rate-of-change of the bank angle.· The directional gyro (gyrocompass) indicates the direction in which the aircraft is pointed, but not the rate-of-change of that direction.
All of these are gyros.· So the statement is simply untrue, and based on a sketchy and incorrect understanding of gyroscopes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
any ideas?
Technic-R-C
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
For instance, let's say you're sampling at 10 times/sec, or .1 sec between samples. You'll read the rate from the rate sensor and convert it to degrees/second, then multiply that by by the sample time. So if you're reading 50 degrees/sec during one sample, you'll have rotated 5 degrees during the sample time (50 deg/sec x .1 sec = 5 deg). Add this to your current degree estimate and repeat (i.e. if you were aimed at 120 degrees, after this sample you'll be aimed at 125 degrees)
Having said that, here's some issues you should keep in mind:
1. Since you're working with integer values of no greater than 255 (your sensor resolution), you'll get some pretty significant round-off error pretty fast. This will cause your estimate to drift. If you sample too fast, your round-off error will increase. Sample too slow and you'll be inaccurate also. I would actually suggest using a 10-bit or 12-bit ADC and changing your units from degrees to hundredths of a degree (using a WORD variable), that way you'll have less round-off error and you'll be able to sample faster.
2. Rate sensors can be noisy, so do what you can to reduce line noise and put a low-pass filter between the rate sensor and the ADC based on your sample rate (see Nyquist frequency). Noise will add additional drift and inaccuracy.
3. We're assuming you're rotating in just 1 axis. If you're rotating in 3 axes, the math gets really messy.
Hope that helps...
Dave
I hate to say it.....but I was avionics for 12 years....and my understanding of gyros is close to complete.
The problem, you are comparing a electronic digital gyro to a mechanical spinning gyro. Mechanical gyros have a mass which is spun to give a gyroscopic reference in rotation. Since digital gyro's do not have a rotating mass, they can only give rotation rate information. There is no such thing as a digital directional gyro. There are ring laser gyro's and such, but those are much more expensive than a simple digital chip.
Unfortunately......using a rate gyro by itself can be a problem. You can derive a heading based on how much the gyro states that you have turned, but there is some error with that method.
These are the reasons INU setups are so expensive. It takes a large amount of sensors to calculate the action of a mechanical gyro.
I'm sorry the answer is not what you were looking for......but it does explain your issue with the output becoming null.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Please note: Due to economic conditions the light at the end of the tunnel will be turned off until further notice. Thanks for your understanding.
Post Edited (James Long) : 10/1/2009 12:27:49 AM GMT
Great suggestion!· I was thinking along the same line, 255 is a very constricting max value..· I think I am going to purchase this 12 A/D converter but considering shipping costs, I'll try to find someplace nearby to buy it.· Every town is always short of an excellent electronics parts store...
I was actually going to ask about filtering.· When you say "put a low-pass filter between the rate sensor and the ADC" do you mean physically as a component, if so where should I start looking, or are you talking code?
Yes definately, I am using an accelerometer along with this gyro two make a balancing robot.
James L:
Thank you for all the info in regards to gyro's.· Now I definately have a better understanding of gyros and how they work.
Technic-R-C
Post Edited (Technic-R-C) : 10/1/2009 11:49:23 PM GMT
I am sorry that I had to throw a wrench into the works. I too long for a digital solution for the old and fragile mechanical gyro.
I think if you have an accelerometer, and a gyro....you will probably be fine. The calculations can be overwhelming (if you get deep into Kalman type filters.....which I think you will be able to refrain from), but that is what this forum is for.
Please keep us update of your status and progress.
I do know there have been balancing robots that have been successful with just a few sensors.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Please note: Due to economic conditions the light at the end of the tunnel will be turned off until further notice. Thanks for your understanding.
If you can get the code to run the same loop over and over, then your sample rate should stay pretty constant. If you need the stamp to go off and do other stuff (communicate, servo control, etc), then you'd either need a second stamp (easy) or you'd need an external source (hard). If you can get it to run the same loop of code over and over, then all you need to do is time how long it takes to take 1000 samples with that loop. The time it took divided by 1000 is how long it is between each sample. To increase the sample time, just add a pause statement.
HOWEVER, if I understand correctly how you're using the sensor, you might not need to integrate to get the direction. Your accelerometer is already measuring tilt, so why do you need a second sensor to measure tilt? I would suggest using the raw rate sensor signal to get rotational velocity (i.e. how fast it's tilting forward or backward), and combine that with the data from the accelerometer to figure out if the robot needs to go forward or backward. (Combining the sensor data could be tricky, and a Kalman filter would work, but they are harder to code... there's probably a simpler way to do it that would work adequately).
I like the MCP320X chips. They're cheap and work well too. The MCP3204 has 4 channels you can read sensor data with.
I mean components, although you could code it (but that's probably harder). Wiki has a good primer on low pass filters: en.wikipedia.org/wiki/Low_pass_filter
What I'd suggest is shown in this diagram:upload.wikimedia.org/wikipedia/commons/3/3b/RC_Divider.svg
Vin is the output pin on the sensor, and Vout goes to the ADC. If you're sampling at 40Hz, then a .47uF cap and a 10k resistor should probably work well (someone care to check my math?)
Check out the attachment. It shows the idea behind an unfiltered signal and a filtered signal.
Placement of the accelerometer is critical if you're using it to measure the tilt of the robot. If you put it near the top, when the robot wobbles, the accelerometer will sense the wobbling and think it's tilting differently than it is, and it'll crash down. Or the feedback loop with cause increasing oscillations. Placing the accelerometer at the wheel axle is probably your best bet.
Hope that helps.
Dave