Gyroscope weirdness

Our programmer is working with a gyroscope for the first time and is seeing some unexplained weirdness.

He started out with the sample code posted elsewhere on the forum to display the sensor reading to the V5 brain. No problem - it starts at zero - when he picks it up and manually turns it 90 degrees, the reading agrees.

The problem only occurs once a motor is applied - a non-manual turn. He wanted to program a basic 90. He has a live reading going to the v5 brain screen. It is like the sensor value is increasing as the robot turns, but also decreasing at a slower rate. So if you tell it to run the motors "while sensor <90), it physically turns past 90, reaches a sensor reading of 90, but the on screen reading continues to slowly decrease indefinitely until you manually stop the program…

So he tried a manual dead reckoning turn with the sensor reading displayed. Same thing. The onscreen reading when it actually gets to 90 says 24, but once the movement stops the sensor value slowly rolls backward indefinitely.

As per other posts he was very careful to keep the wiring away from any of the motors so it shouldn’t be interference. He has tried multiple ports with the same results.

I want to say defective sensor - but why does it read correctly for a manual turn?

I’m going to bet that when he is having it do a powered turn he isn’t waiting for the gyro to finish calibration, but when doing it manually he delays a couple seconds before picking the robot up and turning it, allowing the gyro enough time to calibrate. Have him add a delay of a few seconds before starting the motors and see if it persists.

He had thought he had that covered by using a “While iscalibrating” loop. Changing it to a forced wait did the trick. Thank you!!