cant figure out the white line code pid in line folower

//we have been working on line follower bot using qtr 8a array sensors, everything was good when used black line on white board but now we are having many troubles in white line and black board.
attatched the pid code which worked for black line. Please tell us how to convert this code for white line.
Thank you.

#include <QTRSensors.h>
#define NUMREADINGS 10 
QTRSensorsRC qtrrc((unsigned char[]) {4, 5, 6, 7, 8, 9  }, 6, 2500, QTR_NO_EMITTER_PIN);
unsigned int sensors[6];

int last_proportional;

int integral;
void setup(){
pinMode(3,OUTPUT);
pinMode(11,OUTPUT);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(16,OUTPUT);
pinMode(17,OUTPUT);
unsigned int counter; // used as a simple counter
for(counter=0; counter<73; counter++){
  if(counter < 20 || counter >= 57){

  digitalWrite(14,HIGH);
  digitalWrite(15,LOW);
  digitalWrite(16,LOW);
  digitalWrite(17,HIGH);
  analogWrite(3,80);
  analogWrite(11,80);  }
 else{
   digitalWrite(14,LOW);
digitalWrite(15,HIGH);
 digitalWrite(16,HIGH);
 digitalWrite(17,LOW);
  analogWrite(3,80);
  analogWrite(11,80);  }

  // This function stores a set of reads of the sensors and 

  // keep information about the maximum and minimum values found.

 qtrrc.calibrate();

  // Since w count till 80, the whole time of calibration will be: 80 * 10 = 800 ms

  delay(10);
}}
void loop(){
 unsigned int position = qtrrc.readLine(sensors);
  int proportional = ((int)position) - 2500;
// Serial.println("proportional");
 //Serial.println(proportional);

  int derivative = proportional - last_proportional;

  integral += proportional;
  last_proportional = proportional;
 int power_difference = proportional/20 + integral/10000 + derivative*3/2;
  const int max = 180;
  if(power_difference > max)
    power_difference = max;
  if(power_difference < -max)
    power_difference = -max;
  if(power_difference < 0)
    set_motors(max+power_difference, max);
  else
    set_motors(max, max-power_difference);
 Serial.println("---position");

Serial.println(sensors[0]);

   // Serial.println("----------power_difference");

  //  Serial.println(power_difference);
 }

void set_motors(int left_speed, int right_speed){
{

  if(left_speed >=0 && right_speed >=0 )
  {
 digitalWrite(14,HIGH);
  digitalWrite(15,LOW);
  digitalWrite(16,HIGH)
 digitalWrite(17,LOW);
  analogWrite(3,left_speed);
  analogWrite(11,right_speed);
  }
 else if(left_speed <0 && right_speed >=0 )
  {
    delay(70);
  digitalWrite(14,LOW);
  digitalWrite(15,LOW);
  digitalWrite(16,HIGH);
  digitalWrite(17,LOW);
  analogWrite(3,left_speed);
  analogWrite(11,right_speed);
  }
  else if(left_speed >=0 && right_speed <0 )
{   delay(70);
  digitalWrite(14,HIGH);
 digitalWrite(15,LOW);
  digitalWrite(16,LOW);
 digitalWrite(17,LOW)
  analogWrite(3,left_speed);
  analogWrite(11,right_speed);
  }
}


/* Serial.println("--------------left_speed");

Serial.println(left_speed);

Serial.println("-------------------right_speed");

Serial.println(right_speed);*/
}

This pid code worked very well with black line.
Glad you replied.

MY_PID.ino (2.85 KB)

Why not post the code here to make it easier to copy to an editor ?
Please use [­code] [­/code] tags around the code when you do

My wild guess is that the problem is entirely within this line of code

unsigned int position = qtrrc.readLine(sensors,1);

Presumably you need to do something to tell that library that white is the new black.

...R

You code is completely unreadable.

Please modify your post and use the code button </> so your code looks like this and is easy to read and to copy to a text editor. See How to use the Forum

...R

Sorry for that... Please help us now

HRx:
Sorry for that... Please help us now

Thank you for putting the code in code tags - that's a big improvement. However it still has an enormous number of unnecessary blank lines which is a big part of the unreadability. Please remove them. A little whitespace is very helpful, but in your 200 line program there must be 100 blank lines.

...R

Modified

Thanks. That's much better. I have tidied it up a bit more - similar to what you get when you use the AutoFormat tool. See how much easier to is to see the different parts relate to each other with some consistent layout.

#include <QTRSensors.h>
#define NUMREADINGS 10
QTRSensorsRC qtrrc((unsigned char[]) {4, 5, 6, 7, 8, 9  }, 6, 2500, QTR_NO_EMITTER_PIN);
unsigned int sensors[6];

int last_proportional;

int integral;
void setup(){
    pinMode(3,OUTPUT);
    pinMode(11,OUTPUT);
    pinMode(14,OUTPUT);
    pinMode(15,OUTPUT);
    pinMode(16,OUTPUT);
    pinMode(17,OUTPUT);
    unsigned int counter; // used as a simple counter
    for(counter=0; counter<73; counter++){
        if(counter < 20 || counter >= 57){
            digitalWrite(14,HIGH);
            digitalWrite(15,LOW);
            digitalWrite(16,LOW);
            digitalWrite(17,HIGH);
            analogWrite(3,80);
            analogWrite(11,80);  
        }
         else{
            digitalWrite(14,LOW);
            digitalWrite(15,HIGH);
            digitalWrite(16,HIGH);
            digitalWrite(17,LOW);
            analogWrite(3,80);
            analogWrite(11,80);  
        }

            // This function stores a set of reads of the sensors and
            // keep information about the maximum and minimum values found.
        qtrrc.calibrate();
            // Since w count till 80, the whole time of calibration will be: 80 * 10 = 800 ms
        delay(10);
    }
}

void loop(){
    unsigned int position = qtrrc.readLine(sensors);
    int proportional = ((int)position) - 2500;
        // Serial.println("proportional");
        //Serial.println(proportional);

    int derivative = proportional - last_proportional;

    integral += proportional;
    last_proportional = proportional;
    int power_difference = proportional/20 + integral/10000 + derivative*3/2;
    const int max = 180;
    if(power_difference > max) {
        power_difference = max;
    }
    if(power_difference < -max) {
        power_difference = -max;
    }
    if(power_difference < 0) {
        set_motors(max+power_difference, max);
    }
    else {
        set_motors(max, max-power_difference);
    }
    Serial.println("---position");
    Serial.println(sensors[0]);

    // Serial.println("----------power_difference");
    //  Serial.println(power_difference);
 }

void set_motors(int left_speed, int right_speed){

    if(left_speed >=0 && right_speed >=0 ) {
        digitalWrite(14,HIGH);
        digitalWrite(15,LOW);
        digitalWrite(16,HIGH)
        digitalWrite(17,LOW);
        analogWrite(3,left_speed);
        analogWrite(11,right_speed);
    }
    else if(left_speed <0 && right_speed >=0 ) {
        delay(70);
        digitalWrite(14,LOW);
        digitalWrite(15,LOW);
        digitalWrite(16,HIGH);
        digitalWrite(17,LOW);
        analogWrite(3,left_speed);
        analogWrite(11,right_speed);
    }
    else if(left_speed >=0 && right_speed <0 ) {
        delay(70);
        digitalWrite(14,HIGH);
        digitalWrite(15,LOW);
        digitalWrite(16,LOW);
        digitalWrite(17,LOW)
        analogWrite(3,left_speed);
        analogWrite(11,right_speed);
    }
    
    // Serial.println("--------------left_speed");
    // Serial.println(left_speed);
    // Serial.println("-------------------right_speed");
    //Serial.println(right_speed);*/
}

...R

Now you need to post a link to the documentation for the QTRSensors library so that we can see whether it needs to be set up differently for a white line. This is what I was alluding to in Reply #2

...R

Your answer is in this line from the library documentation:

For line-detection applications, you can request the line location using the readLine() method, which takes as optional parameters a boolean that indicates whether the line is white on a black background or black on a white background, and a boolean that indicates whether the IR emitters should be on or off during the measurement.

I think the call would be:

unsigned int position = qtrrc.readLine(sensors, QTR_EMITTERS_ON, 1); // white is the new black

Yes we are using the library of 'qtr sensors'

Did you read reply #9

Please help us with the solution now.

HRx:
Please help us with the solution now.

What part of the documentation don't you understand?

...R