So I am making a robot which is to follow a line. The field has both +(junctions) as well(by the intersection of two lights). I am yet to figure out what exactly is the best way to track the number of junctions.
The following is the code I have thought out. However, if there is a better way I would highly appreciate any suggestions.
while (true){
cout << rlink.request(READ_PORT_4)<<endl;
go_straight();
int sensor_counter=0;
while(sensor_counter<=2){
if (sensor_values==111){
while(sensor_values!=0){
go_straight_before_junction();
}
if (sensor_values==0){
sensor_counter=sensor_counter+1;
}
;}
;}
while(sensor_values!=3){
turn_left_corner();
}
if (sensor_values==3){
direction-=90;
}
sensor_values=5 -robot Too left to the line
sensor_values=4 -robot Slightly left to the line
sensor_values=3 - exactly on the line
sensor_values=2 -robot slightly right of the line
sensor_values=1 -robot Too right of the line
Sensor_values=0 or 111 - robot crossed junction (0 is for the sensor at the back off the centre line and 111 is for the 3 sensors at the front. )
I'm using a light sensor and it reads 1 when in front of a white line and 0 when in front of a black line(rather like white tapes on a black floor ).