Gyro problem, please help!

Our gyro is not working properly. Gyro is connected to the analog breakout port 1 and signal is going to the output which is closer to the rate sign ( its not the temperature). We are running it through java.

when we enable the teleoperated mod it resets itself but its drifting the angle even when its stable. i already checked the sensitivity and its just multiplying with other numbers so when it turns it gives lower or higher numbers.At 0.007 i can get the degree for a while (around 10 sec)but it keep increasing even when i’m moving it. here is my simple code for it …

package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Gyro;

import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;

public class RobotTemplate extends SimpleRobot {

private Gyro gyro = new Gyro(1);

public void autonomous() {
}


public void operatorControl() {
    double number1 = 0;

    gyro.reset();

    while (isEnabled() && isOperatorControl()) {
        Timer.delay(0.05);

        double number = gyro.getAngle();

        System.out.println(number);
        
    }
}


public void test() {
}

}

thanks for your helps.

Gyros tend to drift, but not by large amounts. Make sure your robot isn’t moving when you power on to minimize the drift. We’ve found that the normal gyro drift doesn’t affect us much during autonomous, and during teleop we always use offsets rather than absolute angles when giving gyro-based commands. (ie. use the current gyro angle + some offset rather than using an absolute angle)

Code wise if you are using the gyro from the Kit of Parts then you should keep its sensitivity at 0.007 so the getAngle() reports in degrees.

How much is it drifting? It is normal for the gyro to drift a fraction of a degree because of the nature of a gyro being a rate of change sensor. To get the current angle the gyro is facing it sums up all the changes in angle. The calculated rate of change is not 100% accurate and thus has error. Due to this error it builds up as more and more of these are added up as drift. You would have to reset the gyro when you know its heading to reset the error in getAngle() to 0.

What do you mean by offset ?

Earlier tonight we got it drifted 1 degree in 3 minutes while we were suspecting form the temperature ,we put a fan on the gyro and it was fine. So we tried it after 1 hour and it start changing 1 degree a minute. Is there any library or source for the temp output on the gyro ?

For example, if you know the robot is straight and you want to turn 30 degrees (but your gyro drift is adding up), you could turn to gyro.getAngle() + 30.0. Another solution, as MagiChau wrote, is to reset the gyro if you know where your robot is pointed.

I already written a program for that but never get to test it because our robot is packed up and only thing i could access from our lab is bunch of sensors and a crio. does is work properly when you use it like that ?

public void operatorControl() {

    double lastAngle = 0;
    double newAngle =0;
    double realAngle = 0;
    gyro.reset();
    while (isEnabled() && isOperatorControl()) {
        double move = y.getY();
        motor.set(move/5);
        
        if (move > 0.01 || move < -0.01) {
            newAngle = gyro.getAngle();
            lastAngle = realAngle;
        } else {
            realAngle = newAngle + lastAngle;
            
            gyro.reset();
            
        }
        
        System.out.println(realAngle);
        System.out.println(move);
        Timer.delay(0.05);
        
    }
}

do you think this will work ?

Zach, 1 degree every 1-3 minutes is actually good performance from the KOP gyro. As far as I know, you’re not going to be able to improve on it substantially.

Perhaps you can tell us the application. I can’t think of many applications for a gyro that would be messed up by 1 degree over the course of the match.