Program for line following robot with dotted line

Dear experts as per the below robot path please provide the little advise to
program for line following robot with dotted line but without getting effected to the dead end line up
Note
My robot Meze following is working properly but during the dotted line following area the robot get turn around

Since you have a dead end and a dashed line in the same course, the way I would probably go about it is to first detect when the line suddenly disappears. One way you can do this is by keeping track of the previous line reading, and when your robot no longer senses the line, check and see if the previous reading was toward the middle of the line sensor array. If it was, break out of your normal line following routine and have the robot move straight forward for a short amount of time while continuing to take line sensor readings. If the line is detected again before the designated time is up, it was a line break and the robot can go back to following the line again (this will repeat through each dash in the line). Otherwise, if the line wasn’t detected before the designated time limit, it must have been a dead end and it should do a U-turn.

Brandon

Thanks Brandom

I think you explained about Maze follower code is doing …Isn’t it ?

In this case bit straight + lineup + dash_detec Then total length is very high , Then meat near the next line
Please advice

Yes, it is very similar to basic maze solving methods. Maze solving methods generally try to identify an intersection and consider which combination of the following conditions have been found:

Left turn
Straight
Right turn
U-turn
Finish

The steps for doing this are similar to what I described (once you identify the intersection, drive forward a short amount and keep track of what your sensors are seeing, then analyze them). Essentially, I’m suggesting adding one additional edge case: when a U-turn is found, drive forward another short amount and see if the line is suddenly detected again to make sure it wasn’t a dashed line instead.

Brandon

1 Like

Hi
Sorry for late reply
We are getting ready for another competition with same course. please check that I used the method that I understood of your explanation

unsigned int position = robot.readLine(sensors, IR_EMITTERS_ON);
  unsigned int prevPos = position;
  delay(200);
  position = robot.readLine(sensors, IR_EMITTERS_ON);
  unsigned int newPos = position;
  /// if ((prevPos > -1000) && (prevPos < 1000))
  if (prevPos > newPos) {
    dashFound = true;
    lineLost(dashFound);
  }

Your code seems to be missing a lot and I don’t think it will work how you want with what you have right now. Without the context of the rest of your code, the two main problems I see are:

  1. You are not centering your readLine() reading. The readLine() function returns a value between 0 and n\times1000 where n is the number of QTR sensors you’re using. So typically, you would subtract \frac{n\times1000}{2} from the reading so you can use a value of 0 to represent when your robot is centered on the line. Negative values would mean the line is on one side of the line, and positive values would mean it is on the other.

  2. Your logic of checking if the previous position is larger than the new position does not work in all cases. When the QTR sensors are not seeing a line, it will return a value of 0 or n\times1000 (depending on where the line was when it was lost). So, once you center that reading by subtracting \frac{n\times1000}{2}, your line reading will either be \frac{-n\times1000}{2} or \frac{n\times1000}{2}. To check if the robot has abruptly lost the line because it has ended (and not that it just turned off of the line), you can check if the previous reading was between some threshold (for example -500 and 500), and that the current reading is either \frac{-n\times1000}{2} or \frac{n\times1000}{2}. At that point, you still have to determine if it is a dashed line or a U-turn. To do that, you can go straight for a very short period, take a new reading and see if it is valid (i.e. between \frac{-n\times1000}{2} and \frac{n\times1000}{2} again). If it is, you found a dashed line. If it isn’t, then you found a U-turn.

Brandon

1 Like

Hi BrandoM
Thanks for very clear explanation
I modify the code as follows

 unsigned int position = robot.readLine(sensors, IR_EMITTERS_ON);

  if  (sensors[1] < 200 || sensors[2] <200 || sensors[3] < 200) {
    dashFound = true;
    lineLost(dashFound);
  }

Above code is locks like working but not always success

void lineLost(unsigned int dashFound) {
  while (1) {
    OrangutanMotors::setSpeeds(50, 50);
    delay(100);
    robot.readLine(sensors, IR_EMITTERS_ON);
    if (sensors[1] > 200 || sensors[2] > 200 || sensors[3] > 200) {
      return;
    }
  }
  //OrangutanMotors::setSpeeds(50, 50);
  //return;
}

U turn not yet success
please advise if the path I am going correct
Thanks in advanced

It looks like you are using the individual sensor readings now instead of the line position reading, which is another valid way to do it. However, if it works sometimes, and not others, you might be getting to the point where you will need to do specific troubleshooting and tuning for your robot. For example, you might need to adjust the speed or delay before taking another reading. Helping troubleshoot further is generally beyond the scope of our direct technical support.

That being said, your latest code reminded me of the maze solving code I wrote for the last competition I was in, and I made a quick addition to it to as an example for determining between dashes and U-turns, in case it helps:

int16_t position = lineSensors.readLineBlack(lineSensorValues);
int16_t error = position - 2000;

onLine = false;

//if one of the 3 center sensors sees the line, the robot is considered on the line, otherwise it is not.

if(sensors[1] > sensorThresholdDark || sensors[2] > sensorThresholdDark || sensors[3] > sensorThresholdDark)
{
    onLine = true;
}

//if the robot is not on the line, but was in the previous loop, the line stopped abruptly
//so drive forward a small distance and check again to see if the line is picked back up 

if( !onLine && onLinePrevious )
{
    
    motors.setSpeeds(60, 60);
    delay(200);
 
    position = lineSensors.readLineBlack(lineSensorValues);
    
    if(sensors[1] > sensorThresholdDark || sensors[2] > sensorThresholdDark || sensors[3] > sensorThresholdDark)
    {
        //if the line did pick back up, a dash was found
        onLine = true;
        foundDash = true;
    }
    else
    {
        //if the line did not pick back up, a U-turn was found
        foundUturn = true;
    }
}
 
onLinePrevious = onLine;

Brandon