Gyroscope Issues

Hi, we recently received a gyroscope and think its an amazing sensor :open_mouth:

We are using RobotC 3.51 with all the drivers updated etc.

However, we have been having a few problems with it, quite often the values will keep going up (even if its not plugged in), this usually happens after a program download. The only way we have found to fix it is to re-download the RobotC firmware - is this a common issue, or is it just us? If its common, has anyone found a permanent fix? We just dont want to be using a sensor which can be unreliable in competition :confused: if its just us, we may have to get another one instead - because we think its awesome!

Thanks in advance!


Support for the gyro has gradually been improving since it’s introduction, recent versions of ROBOTC are handling drift much better but the gyro is not perfect. Some things to watch out for.

  1. The gyro must be stationary when it initializes, when the code first runs ROBOTC integrates and measures the offset voltage coming from it and uses this as a reference for no angular motion. I usually include the ability to reinitialize the gyro from some type of user input in my code. One technique is as follows.
    // Cause the gyro to reinitialize
    SensorType[theGyro.port] = sensorNone;

    // Wait 1/2 sec

    // Gyro should be motionless here
    SensorType[theGyro.port] = sensorGyro;

    // Wait 1/2 sec
  1. Keep the gyro on as short a cable as is practical, don’t run the cable near potential sources of noise, ie. don’t run it with motor wiring, my normal setup would be to use a 6 inch cable and mount the gyro next to the cortex but it really depends on the configuration of your robot.

  2. Although ROBOTC is handling drift a little better than last year I would include some code to remove drift when the gyro is stationary, there are some old discussions on the forum about this but the general idea is to ignore gyro changes below a certain threshold. Here is another excerp from some code that shows one technique.

        // get current gyro value (deg * 10)
        gyro_value = SensorValue[theGyro.port];

        // Filter drift when not moving
        if( (nSysTime - nSysTimeOffset) > 250 )
            if( abs( gyro_value - lastDriftGyro ) < 3 )
                gyro_error += (lastDriftGyro - gyro_value);

            lastDriftGyro = gyro_value;

            nSysTimeOffset = nSysTime;

        // Create float angle, remove offset
        angle = (gyro_value + gyro_error)  / 10.0;

It’s accumulating an error signal that is deducted from the gyro value for small changes, the drift is sampled every 250mS.

  1. Don’t expect anything useful if the gyro is not plugged, the analog input has noise on it which may be interpreted as movement.

How are you planning to use the gyro ?

Hmmm, that could be the issue actually… didnt think of that one, il give it a go today :slight_smile:

Yup, i have it on a 6" cable screwed down to the chassis of the robot away from cables

Thats really interesting, il look into noise removal in my program

Hahahaha, of course it wouldnt be useful if it wasnt plugged in :stuck_out_tongue: it was just an observation that when it plays up it acts as if nothing is plugged in - and then when the firmware re-downloads it works again

We arent using it for anything fancy, i have just written turning functions to use it instead of the encoders so it knows where it is from the start point. They are working great when the sensor is actually working :slight_smile:

Thanks for your advice :slight_smile:

I encountered this issue last year as well and created a thread about it here: I think jpearman pretty much covered the real solution but you might as well read through it. Good Luck!