PID control wouldn't handle sharp 90 degree turns

I’m working on a line maze solver and implemented PID control.5 tcrt5000 sensor array is used to detect the line.My question is,as PID always tries so keep the middle sensor on the line,that is favors the 00100 condition, when the bot approaches a right angle turn, like condition like 00111, PID throws in correction by increasing right motor speed so the bot turns to the left.But the bot should go right and PID does exactly the opposite.
On side note, how do I precisely take 90 degree turns needed for the maze solving part of the code.

P.S. I added my code, I know some things are wrong but you’ll get a rough idea on how I planned solving the maze and implementing PID control.

maze.ino (5.5 KB)

PID does exactly the opposite.

The "run straight line" PID algorithm is the wrong one for that situation.

how do I precisely take 90 degree turns needed

How are you measuring the turn angle, as required by the "turn" PID algorithm?

jremington:
The "run straight line" PID algorithm is the wrong one for that situation.

Well,then how do I make my bot take sharp 90 degree turns but use PID at the same time? :frowning:

You would have two different PID algorithms, one for running straight and once the decision is made to turn, one for the turn.

They might have totally different inputs. For the turn, most people use wheel encoders.