1
$\begingroup$

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

$\endgroup$
  • $\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 Oct 24 '18 at 5:31
  • $\begingroup$ Im using a light sensor $\endgroup$ – robotlover Oct 24 '18 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 Oct 24 '18 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 Oct 24 '18 at 7:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.