Gyro Angle Problems

We are using a gyro to detect turn changes on the Robot for an aiming function. Currently, the gyro is in Digital IO slot 2 and appears to be correctly wired. However, when we ask for the getAngle values and spin the robot in circles, we get values of less than 1 in the positive and negative direction. Turning the robot a full 360 would increase the gyro angle by at most (.1). My understanding is that getAngle should return values far greater than this. How do we get the gyro to return proper angles?

The Gyro should be in Analog 1 or 2.

Are you using RobotBuilder? If so, there is a bug I just found earlier today. The default sensitivity for the gyro is set to 1.25, but it really should be 0.007 volts/degree/second. The fix will be available in the next update, but in the mean time you can change it manually.

We tried both changes and the angle still goes up very very slow, only ranging between .7 and -.7

Post your code and a picture of the gyro installation (including wiring at both ends).

Does it seem at all responsive to reality? In other words, does the response have the right shape but the wrong magnitude, or is it just wandering on its own? Graphing the values will answer this question quickly.

If it is a magnitude issue, change the sensitivity.

If it is just wandering, recheck your wiring.

At the moment when the shoot function is called the robot goes into a death spin and rapidly rotates for a bit, then slows down but still locks me from moving using the joysticks. I’ve found that the robot gets stuck in the aiming loop and is never able to get out of it, but for some reason it will stop turning the robot and just sit in the loop doing nothing afterwards. Here is any code that includes the gyro’s:

Robot Template function:

    public RobotTemplate() {
        watchD = this.getWatchdog();
        //kills the watchdog
        watchD.setEnabled(false);
        //run the compressor
        comp1.start();
        //start with all arms retracted
        Arm1.retract();
        Arm2.retract();
        Arm3.retract();
        Arm4.retract();
        gShoot.reset();
        gShoot.setSensitivity(.007);
        camera = AxisCamera.getInstance("10.16.31.11");
        SmartDashboard.putString("Made it out~", "BEFORE BUTTON");
    }

data function(called in main loop to update dashboard)


 public void data() {
        //put smartdashboard values
        SmartDashboard.putNumber("Left Motor", Y);
        SmartDashboard.putNumber("Right Motor", Y * backward);
        SmartDashboard.putBoolean("Compressor Running: ", comp1.enabled());
        SmartDashboard.putNumber("gyro angle", gShoot.getAngle());
        //SmartDashboard.putString("Taken Picture", ".............");
        //SmartDashboard.putNumber("gyro angle", gShoot.getAngle());
    }

Shoot function(i think this is the source of my problem)


    public void shoot(final double finalAngle) {
        //declare and start a timer, used for smooth transition between sections
        gShoot.reset();
        Timer t_aim = new Timer();
        t_aim.start();
        //while the difference in absolute values of gyro angle and finalangle is greater than .75
        while (gShoot.getAngle() > (finalAngle + .75) || gShoot.getAngle() < (finalAngle - .75) && !joy2.getRawButton(1)){
            SmartDashboard.putString("Made it out~", "ITS IN THE LOOP");
            if(t_aim.get() > .6) {
                t_aim.reset();
                t_aim.start();
                if(gShoot.getAngle() < finalAngle){
                    //I have no idea which way to turn the robot. Change positive and negative.
                    jag1.set(.25);
                    jag2.set(.25);
                    jag3.set(.25);
                    jag4.set(.25);
                }
                else if(gShoot.getAngle() > finalAngle){
                    //I have no idea which way to turn the robot. Change positive and negative.
                    jag1.set(-.25);
                    jag2.set(-.25);
                    jag3.set(-.25);
                    jag4.set(-.25);
                }
            }
        }
        SmartDashboard.putString("Made it out~", "ITS OUT OF THE LOOP");
        //stopping the jaguars after the angle is correct
        jag1.set(0);
        jag2.set(0);
        jag3.set(0);
        jag4.set(0);
        
    }

The value in Finalangle on average ranges from -30 degrees to 30 degrees, and i used the jags in all combinations with negative and possible, i wouldnt think it is the jags. Any help is really appreciated!

Are you describing the same problem, or did something happen between the above two posts that you haven’t mentioned??

I gyro still stays at a very small angle, i had just modified the code a lot to fix some logical problems. ill upload some pictures to this post showing what i see with the gyro.

http://dl.dropbox.com/u/78573135/IMAG0067.jpg
http://dl.dropbox.com/u/78573135/IMAG0068.jpg
The second photo is after doing a complete turn around, though the value only went back by -.1

I’m using a school wifi system right now so i don’t have access to image sites, sorry!

EDIT: at this point i think the gyro might have been installed wrong, could anyone link a PDF on how to correctly install a gyro? i can’t seem to find one.

Follow these steps:

  1. go to andymark.com

  2. type “gyro” in the search box and press ENTER

  3. click on the link that says “Dual Use Gyro and Accelerometer Sensor Board (am-2067)”

  4. on that page, click on the tab named “Files & Documents”

  5. click on the link “Wiring diagram”

  6. scroll to the bottom of the page

What is the range of values the getAngle function will return? The gyro updates correctly, but starts at a very small angle and only increment by maybe .15 at a time.

If we have an example angle of 6.8 degrees, and the gyro stays at such a small number, the robot goes into a death spin until reaching 6.8 degrees(which is a long time).

follow these steps:

  1. Go to the folder on your development PC where the WPILib Java source code files are kept.

  2. Open the file named “gyro.java”

  3. Search for “getAngle”

  4. Read the method header comments

getAngle requires that the sensitivity of the gyro is set correctly with the setSensitivity method. For the ADW22307 gyro available on FIRST Choice, the sensitivity is 0.007 V/°/s. If you are using a different gyro, you will need to find the sensitivity from the data sheet of the gyro.

If you are using Robot Builder version 619 or earlier, there is a bug that defaults the sensitivity to 1.25 V/°/s. See the post by Alex Henning above. This would cause an issue similar to what you saw. It would take approximately 3.4 full revolutions before the robot measured 6.8 degrees. You should make sure that the sensitivity matches your gyro.

Edit: sorry, I see that you are setting sensitivity. I’ll leave this here in case it helps someone in the future.

With a DMM, what is the voltage on the rate and +5v pins of the gyro?

First, don’t print useless “I’m here” messages at the maximum loop rate! The first one conveys information all the rest consume bandwidth. (check your logs for when the spinning slows I would not be surprised if your prints are gradually backing up and consuming all your CPU and/or bandwidth)

Second, If your code stays in a while loop forever it means you are not meeting the exit criterea. Period. In this case that almost certainly means your spinning in the wrong direction, or +/- .75 degrees is smaller than the distance covered at 25% power in 6 tenths of a second. (how did you come up with .6 as the magic amount of time between checks?)

Third, never create a loop that can run forever! Create a counter or timer that guarantees you’ll exit after, say, 5 seconds, or 10 iterations, or something. If your gyro gets unplugged or damaged you will sit and spin. (been there)

Noticed something about the setup, wondering if anyone can explain it…

I plugged the gyro into the analog breakout and set everything up correctly, until i just realized the analog has never had a power cord to it(i feel very stupid). But how was the gyro returning values to us when the analog was never powered to begin with?

I would imagine it was just integrating noise. It wasn’t returning good values, was it?

Edit: The analog breakout is just a few connectors and a 5V supply. All the actual measuring is done by the cRIO module, which is powered by the cRIO backbone.