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;
    int sensor_counter=0;
        if (sensor_values==111){
            if (sensor_values==0){


    if (sensor_values==3){

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 ).

  • $\begingroup$ it is not possible to answer the question about detecting the junctions .... we have no idea what kind of a sensor you are using and how it is detecting the lights $\endgroup$
    – jsotola
    Commented Oct 24, 2018 at 5:31
  • $\begingroup$ Im using a light sensor $\endgroup$
    – robotlover
    Commented Oct 24, 2018 at 6:50
  • $\begingroup$ which detects 1 when it is infront of a white line and 0 when infront of a black line $\endgroup$
    – robotlover
    Commented Oct 24, 2018 at 6:50
  • $\begingroup$ there you go ... you asked a question without giving all details ... how do you expect a useful answer .... you question says nothing about any black lines .... it mentions crossing lights (this is unclear) ..... please edit your question so that it includes all the information .... please draw a diagram if you have to $\endgroup$
    – jsotola
    Commented Oct 24, 2018 at 7:00


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.