0

The gyroscope value continuously increases/decreases, even when the brick is not rotating! What could be done in order to avoid, mitigate or at least reduce the impact of this behaviour?

1
  • *I know that this has been answered a few other times, but it's such a common problem I thought it best to have a dedicated question/answer for it.
    – Jme
    Aug 16 at 1:27

1 Answer 1

2

This is a pretty common issue called "gyro drift". If the gyroscope is rotating when plugged in and/or when the brick starts up, that constant rotation will be seen as "resting", and when the gyroscope is still, it believes it is rotating.
There are two main fixes to this


Hardware fix

In this, you simply unplug the gyroscope, then plug it back in while holding the robot very still. Any rotation can drift the gyroscope, however, it is pretty simple for most robots.

Alternatively, completely restart the robot while keeping it still. Most of the time this is easier to do, though it takes quite a while.


Software fix

In the software, you can account for the gyroscope drift. Instead of measuring the gyroscope directly, create a variable called gyro. At the start of the program, measure the gyroscope speed multiple times (about 10 should be good for most applications), waiting a small amount of time (try 0.05 seconds) between each, and take the average of the measurements. Then, every second, change the gyro variable by the gyro speed MINUS the averaged gyroscope drift. My preferred method for doing this is to broadcast a message, and have a forever loop in the broadcast receiver, updating gyro and waiting one second in the loop. This keeps your main forever loop free to run quickly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.