You need to set the whiteLine argument to true when calling readLine . For more information, see the documentation for readLine in the “3pi Robot Functions” section of the Pololu AVR Library Command Reference guide.
Thanks for the reply
I go through the following link https://www.pololu.com/docs/0J18/19 but I could not get the logic. Can you please provide the modified code instead of following code
unsigned int position = robot.readLine(sensors, IR_EMITTERS_ON);
Is this correct
unsigned int position = robot.readLine(sensors, IR_EMITTERS_ON,0);
You should not need to change anything for the calibration. If you are reading the position of the sensor over a white line, you can use position = readLine(sensors, IR_EMMITTERS_ON, 1); and if you are reading the position of the sensor over a black line, you can use position = readLine(sensors, IR_EMMITTERS_ON, 0);. If your course has sections of both, your robot will need to determine which section it is currently in and use the correct whiteLine parameter.
You can see an example of both white and black line courses in this forum post). The course shown in your diagram is a segmented black line on a white surface, so you would use the normal readLine() function with the whiteLine parameter of 0. However, the readLine() function does not do anything special to handle segmented lines; it simply returns the current position of the line being detected, so you might need to add some extra logic for detecting when the line is segmented and acting appropriately (e.g. when the line disappears, go straight until the line is detected again).