Hi,
I started to learn how to use the gyro. I downloaded Kevin’s code from the internet and tried to use it. There are some things which I haven’t understood completely.
I tried to print the variable “gyro_rate”, but its values were between 1800-2200.
Shouldn’t it be much lower? Shouldn’t this variable be measuring the angular velocity in (radians/seconds)? I don’t know if there is something wrong with the code, or something wrong with my understanding. I then tried to print the value from the function Get_Gyro_Angle(), but again, the printed values were unreasonable. The value jumped from positive to negative numbers without any logical order.
I would be very glad if someone could guide me through it.
I haven’t used the gyro code in a little over a year, but if I remember right the angular unit used in Kevin Watson’s gyro code is milliradians, not radians. You should also be able to change it to tenths of a degree in the gyro.h file. That would at least explain the large numbers you were getting.
Sorry I don’t know the complete answer to your question, but it’s a start.
Hey, I don’t have the code in front of me but I can look at it when I get back to my dorm.
For your First question neilsonster is right about the units. That would explain the large numbers 1.8 radians per second is alot easier to explain than 1800. I am assuming that the values you are giving us are when the robot is at rest if this is not the case then please specify what you are doing to the robot while it is printing out the data. If the robot is just sitting there than your problem is probably in the initialization of the gyro. When you enable the robot let it sit for a second or two, also make sure the gyro isn’t too close to the compressor or anything else that may cause it to vibrate. If this doesn’t help then give us any more information that you can and I’ll try again.
The value of “gyro_rate” is about 2030 while not moving. When I do rotate the gyro the value decreases or increases depending on the direction. My guess is that the gyro is somehow not calibrated or initialized well, but I don’t know how to make it correct…
That sounds like a problem with the bias. You should try calling Get_Gyro_Bias() and printing the return value, which I think should be something relatively close to 512 if I remember correctly, also make sure that you called Initialize_Gyro() at some point in the code, otherwise it might be the case that the variable holding the bias was never initialized, and contains a random number, offsetting all of your data by that number.
I havent used to gyro but if i recall it is supposed to be 512 for the x and 512 for the y when they gyro isnt moving. Then then you start moving it values will vary from 0 to 1023.
Do you have your code calling the StartGyroCalibration() and StopGyroCalibration()?
If you tried to integrate Kevin’s code into your own code you might not be initializing the gyro correctly. Look at the ProcessDataFromMasteruP() in Kevin’s code.
You need to set the gyro’s bias… You do this by using the Start_Gyro_Bias_Calc() and
Stop_Gyro_Bias_Calc(). Let The start_bias_calc() run for a few secs while the robot isn’t moving.
If you are using Kevin Watson’s code, Get_Gyro_Angle is giving you the actual calculated angle 1800 is 180.0 degrees. He removed the decimal to help the pic process faster(it sucks at floating point stuff).
The actual gyro only outputs the angular rate but his code integrates to give you the actual angle at that point in time.
Read the “Readme” file that came with the gyro code. It should help you setup and calibrate the whole gyro.
I’m such a fool. I forgot that there was code executed in the Process_Data_From_Master_uP function, and I worked with the gyro with the RC turned off…
When I did work with the RC switched on, the gyro’s bias was indeed calculated, but its value was 2040… As a consequence, I believe, the angle and the angular rate were not calculated correctly.
Try running a “clean” copy of kevin’s code . Then if the gyro acts correctly you’ll know its your code. If it still has problems it could be a hardware issue.
If you use the oversampling feature of the analog-to-digital code, the bias value will likely be larger than 512. If you’re averaging sixteen samples, 2040 would be a reasonable value for the bias as it is very close to being halfway between 0 and 4096. This feature is documented in adc.h and adc_readme.txt.
I changed the update rate to 2 and the bias was 512. I don’t know why, but it still not measuring the angle correctly. The anglular rate is not stable, and the angle just keeps incrementing without any sense.
gyro_rate jumps from negative to positive numbers as I turn the gyro, is doesnt become 0 when I stop turning it.
Im using the default code, without any modifications. It is really a weird. Im starting to become frustrated…
Hang in there Guy_E…we’ve all been in your shoes with frustrating problems!
Looking back through the thread, I was wondering what kind of gyro chip you are using? If it’s an Analog Devices, are you using it in conjunction with it’s evaluation board? Or have you created your own custom installation?
In the past we’ve used the 150 and 300 deg/sec chips and simply sampled them with a Get_Analog_Value function in the Default_Routine. With the chip sitting still we’ve often seen the value jump around. So, even though it introduces an error, we’d create a small deadband. As long as the value jumped around inside the deadband, we’d declare the value to be neutral. Outside we’d use it. It would be one way to keep your integration from running away, while you try to figure out why it is jumping around.
I don’t have a lot of experience with Kevin’s code, but I do believe that the methods he uses would greatly reduce this effect.
Oh yeah…should have guessed that. Well the K.O.P gyro is only 80deg/sec, which is REALLY slow for an FRC chassis. That might explain gyro_rate jumping around like you observed.
So the chip will swamp at something like 0.22 rev/sec… I was going to suggest bench testing it by taping it to an old LP record player turntable- to get a reasonably steady rotation- but even that will swamp the gyro. …hmmmm
I’ll have to take a closer look at Kevin’s code at this point. Perhaps someone whose used his code in competition could jump in?