I have a similar idea like @Bending Unit 22, which is not to follow the line but its edge instead. So you detect the line only with one sensor (let's say only with the left one (blue dot)).
If the you both sensor indicates line then your robot should turn right until the right sensor (green dot) indicates white surface. This is the event circled with green in the image below.
If both sensor are lost sight of the line, then the robot should turn left until the left sensor is back on the track. This is the event circled with blue in the image below.
Basically, there could be two states of line-following:
- Default state when the robot has one sensor on the line while the other is off the line.
- Turning state if one of the events occur. The robot could stop and turn until the the left sensor gets back on line or till the right leaves the line. Since we can assume that the direction is known and the robot is not moving, we could turn on maximum speed (or at least you can try and see how it works). You can test it while the robot is in motion of course.
Previously, when your robot lost the line there was no information about the direction, so it could only go backwards hoping to find the line.
It is only a theory but I think it's worth a try or just to move forward your project.
You have mentioned that your cannot use more sensors but are you allowed to modify on the current hardware?
I have checked that the sensors have digital output which means [line] - [no line], not much information. But if you could connect the IR-sensors output voltage to some analog pins, this way you could obtain higher resolution.
To explain further this part:
A basic line detecting sensor is a IR photo-diode and photo-transistor pair. Like the one on your robot only it has a little bit more on the module, a newer version from Makeblock's page:
(Module on left, actual sensor on the right) Your robot has a previous version, which probably uses an other sensor. This one in the image is a TCRT500 from Vishay.
If we have a look at the schematic level:
The output is at the red circle. Now, if there is sufficient reflected IR light the transistor will conduct and the output will be pulled down to GND. If there is not enough reflected IR light, the transistor won't conduct and the output is pulled up through the resistor to supply voltage. But it is not working like a switch, so the out can be anything between 0 - V_Supply. For a given spectral distribution (IR in our case), the photo-current is linearly proportional to the illuminance . So as I said the output voltage can vary between 0 V and VCC (5 V in common).
Your sensor module works the same way, only it has a comparator on it which makes digital output of the analog signal.
When the IR LED illuminates the edge of the line, maybe half of the light is reflected or more, so the transistor can conduct slightly. This means that the output won't be pulled down near 0 V, it will be, let's say around 2 V. But not 0 V (which is the complete white surface), and this is the important because this means that it partly detects something (the line).
Now back to the comparator, it compares the output voltage of the photo-transistor to a reference voltage. It checks if the signal is above or below the reference and sets its output to LOW or HIGH accordingly.
If this the reference is 2.5 V then your module will say that it detects line when the output voltage is above 2.5V, so that information with the 2 V signal will be considered as a white surface where as we saw the edge, thus we lose resolution.
Now, if you could read this whole analog range with an ADC your resolution would be higher and maybe a more delicate controlling algorithm could be achieved.