title: Line Follower - How to detect 90 degree turns with 2 color sensors?
body: <p>I'm building a line follower with EV3 lego kit as a school project. To stay on the line I'm using PID regulator which uses difference between 2 color sensors  on the front for calculating error (sensor read ranges from about 20 on black to 200 on white). It looks something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/oQduA.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oQduA.gif" alt="Line Follower"></a></p>
  
  <p>The code I wrote works pretty well for smooth turns, even the sharp ones - but if the turn is a straight 90 degree angle something like this happens:</p>
  
  <ol>
  <li>Robot starts the turn</li>
  <li>It's not turning fast enough and both sensors end up on the black line</li>
  <li>Error falls to zero as both sensors are reading same value from black</li>
  <li>As the error is zero the robot goes straight and looses the line</li>
  </ol>
  
  <p>I can manage make those turns by slowing speed and increasing integral and differential constants, but that makes control too aggressive and then it bounces left-right a lot, sometimes making one turn takes like 20 seconds before it manages to bounce like that to the straight line.</p>
  
  <p>Any tips or tricks I could use to improve my Line Follower to deal better with those turns and overall?</p>
  
  <p><a href="https://github.com/Stormwaker/LineFollower/blob/master/line_follower.py" rel="nofollow noreferrer">Here is my code on GitHub</a> written with <a href="https://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/stable/" rel="nofollow noreferrer">Python API for ev3dev</a>.</p>