Help on PID line follower

Hi i have made a PID based Line follower with pololu libraries. i have completed it and have tuned it very well but however i am unable to crack how to decide the path for a MAZE . Can someone help me with it…I have attached my program.

pid_for_l293d.ino (3.07 KB)

Is there a line to be followed to get through the maze? Specifically, what problem(s) are you looking for help with?

For those who can’t see the code

#include <QTRSensors.h>

#define Kp  .5// experiment to determine this, start by something small that just makes your bot follow the line at a slow speed
#define Kd  7.5// experiment to determine this, slowly increase the speeds and adjust this value. ( Note: Kp < Kd) 

#define rightMaxSpeed 200 // max speed of the robot
#define leftMaxSpeed 200 // max speed of the robot

#define rightBaseSpeed 150 // this is the speed at which the motors should spin when the robot is perfectly on the line
#define leftBaseSpeed 150  // this is the speed at which the motors should spin when the robot is perfectly on the line


#define NUM_SENSORS  8     // number of sensors used
#define TIMEOUT       2500  // waits for 2500 us for sensor outputs to go low
#define EMITTER_PIN   2     // emitter is controlled by digital pin 2


#define rightMotor2 4
#define rightMotorPWM 5


#define leftMotor2 11
#define leftMotorPWM 10



QTRSensorsRC qtrrc((unsigned char[]) {A0,A1,A2,A3,A4,A5,11,9} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN); //analog sensor connected through analog pins A0 - A5

unsigned int sensorValues[NUM_SENSORS];

void setup()
{
  Serial.begin(9600);
  Serial.print("start");
  pinMode(rightMotor2, OUTPUT);
  pinMode(rightMotorPWM, OUTPUT);
  
  pinMode(leftMotor2, OUTPUT);
  pinMode(leftMotorPWM, OUTPUT);
  
  
digitalWrite(13,HIGH); 
for (int i = 0; i < 300; i++) // calibrate for sometime by sliding the sensors across the line, or you may use auto-calibration instead
{
     qtrrc.calibrate();    
        
}    
digitalWrite(13,LOW);     
     
     
  // comment out for serial printing
    
    for (int i = 0; i < NUM_SENSORS; i++)
    {
      Serial.print(qtrrc.calibratedMinimumOn[i]);
      Serial.print(' ');
    }
    Serial.println();

    for (int i = 0; i < NUM_SENSORS; i++)
    {
      Serial.print(qtrrc.calibratedMaximumOn[i]);
      Serial.print(' ');
    }
    Serial.println();
    Serial.println();
    
  } 

int lastError = 0;

void loop()
{
  unsigned int sensors[6];
  int position = qtrrc.readLine(sensors); // get calibrated readings along with the line position, refer to the QTR Sensors Arduino Library for more details on line position.
  int error = position - 2500;
  Serial.println(position);

  int motorSpeed = Kp * error + Kd * (error - lastError);
  lastError = error;

  int rightMotorSpeed = rightBaseSpeed + motorSpeed;
  int leftMotorSpeed = leftBaseSpeed - motorSpeed;
  
    if (rightMotorSpeed > rightMaxSpeed ) rightMotorSpeed = rightMaxSpeed; // prevent the motor from going beyond max speed
  if (leftMotorSpeed > leftMaxSpeed ) leftMotorSpeed = leftMaxSpeed; // prevent the motor from going beyond max speed
  if (rightMotorSpeed < 0) rightMotorSpeed = 0; // keep the motor speed positive
  if (leftMotorSpeed < 0) leftMotorSpeed = 0; // keep the motor speed positive
   {
  
  
  analogWrite(rightMotorPWM, rightMotorSpeed);
  digitalWrite(rightMotor2, LOW);

  
  analogWrite(leftMotorPWM, leftMotorSpeed);
  digitalWrite(leftMotor2, LOW);
 
}
}
void turn_left()
{
 digitalWrite(5,HIGH);
  digitalWrite(4,LOW);
}
void turn_right()
{
  digitalWrite(10,LOW);
  digitalWrite(11,HIGH);
}

Yeah i have a maze with three junctions to reach home…!!I have attached the maze now.
My bot is capable of following the line but however i am not sure how to make decisions on the line .

I am not using the last two functions to turn left and right..!! just tried to calibrate with it ignore those two function definitions..!!i didnt make any call