Answers.Body: <p>There are two options that I can think of.</p>
  
  <ol>
  <li><p>Do the "hardware" fix before every run of the robot to reboot the sensor along with the "software" fix to zero it.</p></li>
  <li><p>Don't use the Angle reading at all. To calibrate the sensor, sample the rate (d/s) 10 times or so and take the average to get the "at rest" rate offset and store it in a variable. Subtract this variable from the rate returned by the sensor to get the actual rate. Integrate the rate over time to calculate the angle. (I haven't actually attempted this myself, but this is how you use, for example, the HiTechnic Gyro sensor since it does not provide an angle).</p></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-22T23:33:22.207Z
Answers.Text: At least 1. can be done by FLL teams.  2. can also be done, but . . . wow is that complicated.  How many samples per second?  Does it fix the problem? It is better than "Don't use the Gyro sensor." which is my current recommendation.  I was hoping for something less complicated.  I'm going to give this a day to see if there is another option.
Answers.UserDisplayName: dfrevert
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-22T04:12:25.170Z
Answers.LastActivityDate: 2015-12-22T04:12:25.170Z
Answers.UserDisplayName: David Lechner
Answers.Body: <p>My team put their software fix in a loop with a small wait that cycles until the d/s = 0, then reset it to 0. Here's a simplified version:
  <a href="https://i.sstatic.net/9Df9W.png" rel="noreferrer"><img src="https://i.sstatic.net/9Df9W.png" alt="Gyro calibrate loop"></a></p>
  
  <p>It works like a charm. We don't mess with the hardware reset anymore. Combined with a heading variable, a turn my block, and a few drive my blocks they can program a maze run in minutes.</p>
  
  <p>FWIW: They output their angle and rate to the display so they can monitor it even when not connected to a computer. They're working on checking the number of loops and total time it takes to optimize. Your team may need to play with the wait time a bit to get the best results.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-13T22:29:25.943Z
Answers.LastActivityDate: 2017-12-13T22:29:25.943Z
Answers.UserDisplayName: EzraCc
Answers.Body: <p>The Gyro is a tricky sensor to use, but at yesterday's FLL competition in Elk River, at least 5 teams had worked out the issues to their satisfaction.  I'm revealing their answers here.  It is unfair to those teams, since their research does represent a significant advantage over other teams.  That said, none of their solutions were complete.  Each team had some part of the answer, but none had everything.</p>
  
  <p>One team, not one of the 5, had given up on using the gyro in the belief that it could not be place close to the rechargeable battery pack because the gyro sensor would get too hot.  I hadn't heard that before and have no idea if it has any basis in fact.</p>
  
  <p>Almost all of the teams used the "Simple Gyro Fix" mentioned in the original question.  They varied in whether they paused before, during, and after each step.</p>
  
  <p>Two teams had tests to avoid leaving home base with a "drifting" gyro.  One waited 10 seconds to see if the drift was still less than 2 degrees.  Another ran the robot through a routine that cause the robot to twitch if it was drifting.  No twitching meant it was ok.</p>
  
  <p>A different set of two teams added a double reset of the gyro.  This reset being the reset of the Gyro angle to 0.  One of those teams said they had followed the advice of some site on the internet.  That team also added a 1 second wait before and after the double reset.  The first to "still" the robot; the second to ensure the zeroing of the gyro angle had been taken.</p>
  
  <p>One team had a set of MyBlocks that turned based on either the rotation sensors or the gyro sensor.  It allowed them to retreat from using the gyro sensor if they needed to.  They had gone to the trouble because of the bad reputation of the Gyro sensor.  In front of the judges, they used the gyro.  It worked.  Clearly, they had worried a lot and then figured out how to use it.</p>
  
  <p>The teams differed in how they turned.  Some pivoted, some spinned, and some accepted any motion.  </p>
  
  <p>One team used the gyro to go straight, sort of a proportional line follower with a gyro sensor instead of light sensor.  They did not use it for turns.</p>
  
  <p>None of the teams did the work of recording the drifting episodes to a file.  None of the teams displayed a warning as a sound, a blinking light, or a message on the LCD panel before the robot left the home base.
  None of the teams switch automagically to the rotation sensors when the gyro is known to be drifting.</p>
  
  <p>None of the teams used #2 of the accepted answer.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-14T00:59:21.760Z
Answers.Text: An additional suggestion from a team judged a couple weeks ago.  They did their best to isolate the robot from vibration during the brick's boot up time.  They started by demanding everyone keep their hands off the table, but found that less effective than placing the robot on the floor.
Answers.UserDisplayName: dfrevert
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-11T02:37:38.090Z
Answers.LastActivityDate: 2016-01-11T02:37:38.090Z
Answers.UserDisplayName: dfrevert
Answers.Body: <p>The most reliable way I've found to quickly reset the gyro is simply unplug it &amp; plug it into a different input port, then unplug it &amp; plug it back into it's port.  Just unplugging &amp; plugging it into the same port doesn't always work for me.</p>
  
  <p>My software always has a 1 sec delay as the first step, and then software reset of the gyro.  This is so after pressing the button on the brick to run the program I have a sec to remove my hand &amp; the bot settles perfectly still, then the gyro resets itself to zero before any motors start to run.</p>
  
  <p>Just this last weekend I started using the gyro to run perfectly forward &amp; it works like a charm, but I haven't experimented how long until it's off by a degree, etc.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-11T23:53:48.017Z
Answers.LastActivityDate: 2016-01-11T23:53:48.017Z
Answers.UserDisplayName: borjonx
Body: <p>EV3 robots can use a Gyro sensor to determine the direction the robot is heading.</p>
  
  <p>The initial conditions are important.  The sensor needs to be still and then the sensor reset.  </p>
  
  <p>However, once in a while the Gyro returns values that drift over time.</p>
  
  <p>What can be done to handle Gyro drift?</p>
  
  <p>Step one would be to remove the drift using the </p>
  
  <ul>
  <li>Hardware fix:  unplug the gyro sensor, make sure the robot is still, and then plug in the sensor.</li>
  <li>Software fix: <a href="http://www.us.lego.com/en-us/mindstorms/community/robot?projectid=96894a3a-45db-48f9-9544-abf66f481b32" rel="noreferrer">Gyro Drift Simple Fix</a> which should only need to be run once. 
  <a href="https://i.sstatic.net/5zCRP.png" rel="noreferrer"><img src="https://i.sstatic.net/5zCRP.png" alt="Gyro Drift Simple Fix"></a></li>
  </ul>
  
  <p>However, I'm aware of several FLL teams using this fix and even then, once in a while the robot goes crazy, because the Gyro sensor has acquired a drift.</p>
  
  <p>Applying the Simple Fix at the start of every run does not seem to fix it every time.</p>
  
  <p>Is there a way to handle this?</p>
  
Tags: <programming><ev3-g><gyro>
Title: How can EV3 Gyro sensor drift be handled?
UserDisplayName: dfrevert
ThreadText: # How can EV3 Gyro sensor drift be handled?
  
  (Asked by: username_0 on 2015-12-18)
  
  EV3 robots can use a Gyro sensor to determine the direction the robot is heading.
  
  The initial conditions are important. The sensor needs to be still and then the sensor reset.
  
  However, once in a while the Gyro returns values that drift over time.
  
  What can be done to handle Gyro drift?
  
  Step one would be to remove the drift using the
  
  * Hardware fix: unplug the gyro sensor, make sure the robot is still, and then plug in the sensor.
  * Software fix: [Gyro Drift Simple Fix](http://www.us.lego.com/en-us/mindstorms/community/robot?projectid=96894a3a-45db-48f9-9544-abf66f481b32) which should only need to be run once.
    [![Gyro Drift Simple Fix](https://i.sstatic.net/5zCRP.png)](https://i.sstatic.net/5zCRP.png)
  
  However, I'm aware of several FLL teams using this fix and even then, once in a while the robot goes crazy, because the Gyro sensor has acquired a drift.
  
  Applying the Simple Fix at the start of every run does not seem to fix it every time.
  
  Is there a way to handle this?
  
  **Tags:** programming, ev3-g, gyro
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2015-12-22. Score: 5 | Accepted answer
  
  There are two options that I can think of.
  
  1. Do the "hardware" fix before every run of the robot to reboot the sensor along with the "software" fix to zero it.
  2. Don't use the Angle reading at all. To calibrate the sensor, sample the rate (d/s) 10 times or so and take the average to get the "at rest" rate offset and store it in a variable. Subtract this variable from the rate returned by the sensor to get the actual rate. Integrate the rate over time to calculate the angle. (I haven't actually attempted this myself, but this is how you use, for example, the HiTechnic Gyro sensor since it does not provide an angle).
  
  > **Comments:**
  > **username_0**: At least 1. can be done by FLL teams.  2. can also be done, but . . . wow is that complicated.  How many samples per second?  Does it fix the problem? It is better than "Don't use the Gyro sensor." which is my current recommendation.  I was hoping for something less complicated.  I'm going to give this a day to see if there is another option.  
  
  ---
  
  ### Answer by username_2 on 2017-12-13. Score: 5
  
  My team put their software fix in a loop with a small wait that cycles until the d/s = 0, then reset it to 0. Here's a simplified version:
  [![Gyro calibrate loop](https://i.sstatic.net/9Df9W.png)](https://i.sstatic.net/9Df9W.png)
  
  It works like a charm. We don't mess with the hardware reset anymore. Combined with a heading variable, a turn my block, and a few drive my blocks they can program a maze run in minutes.
  
  FWIW: They output their angle and rate to the display so they can monitor it even when not connected to a computer. They're working on checking the number of loops and total time it takes to optimize. Your team may need to play with the wait time a bit to get the best results.
  
  
  ---
  
  ### Answer by username_0 on 2016-01-11. Score: 4
  
  The Gyro is a tricky sensor to use, but at yesterday's FLL competition in Elk River, at least 5 teams had worked out the issues to their satisfaction. I'm revealing their answers here. It is unfair to those teams, since their research does represent a significant advantage over other teams. That said, none of their solutions were complete. Each team had some part of the answer, but none had everything.
  
  One team, not one of the 5, had given up on using the gyro in the belief that it could not be place close to the rechargeable battery pack because the gyro sensor would get too hot. I hadn't heard that before and have no idea if it has any basis in fact.
  
  Almost all of the teams used the "Simple Gyro Fix" mentioned in the original question. They varied in whether they paused before, during, and after each step.
  
  Two teams had tests to avoid leaving home base with a "drifting" gyro. One waited 10 seconds to see if the drift was still less than 2 degrees. Another ran the robot through a routine that cause the robot to twitch if it was drifting. No twitching meant it was ok.
  
  A different set of two teams added a double reset of the gyro. This reset being the reset of the Gyro angle to 0. One of those teams said they had followed the advice of some site on the internet. That team also added a 1 second wait before and after the double reset. The first to "still" the robot; the second to ensure the zeroing of the gyro angle had been taken.
  
  One team had a set of MyBlocks that turned based on either the rotation sensors or the gyro sensor. It allowed them to retreat from using the gyro sensor if they needed to. They had gone to the trouble because of the bad reputation of the Gyro sensor. In front of the judges, they used the gyro. It worked. Clearly, they had worried a lot and then figured out how to use it.
  
  The teams differed in how they turned. Some pivoted, some spinned, and some accepted any motion.
  
  One team used the gyro to go straight, sort of a proportional line follower with a gyro sensor instead of light sensor. They did not use it for turns.
  
  None of the teams did the work of recording the drifting episodes to a file. None of the teams displayed a warning as a sound, a blinking light, or a message on the LCD panel before the robot left the home base.
  None of the teams switch automagically to the rotation sensors when the gyro is known to be drifting.
  
  None of the teams used #2 of the accepted answer.
  
  > **Comments:**
  > **username_0**: An additional suggestion from a team judged a couple weeks ago.  They did their best to isolate the robot from vibration during the brick's boot up time.  They started by demanding everyone keep their hands off the table, but found that less effective than placing the robot on the floor.  
  
  ---
  
  ### Answer by username_3 on 2016-01-11. Score: 2
  
  The most reliable way I've found to quickly reset the gyro is simply unplug it & plug it into a different input port, then unplug it & plug it back into it's port. Just unplugging & plugging it into the same port doesn't always work for me.
  
  My software always has a 1 sec delay as the first step, and then software reset of the gyro. This is so after pressing the button on the brick to run the program I have a sec to remove my hand & the bot settles perfectly still, then the gyro resets itself to zero before any motors start to run.
  
  Just this last weekend I started using the gyro to run perfectly forward & it works like a charm, but I haven't experimented how long until it's off by a degree, etc.
  
  
  ---
  
  