Tackling line breaks in line following arenas

Our local robotics club recently held a line following competition that included an advanced course with obstacles like dashed lines and right-angle turns. For the dashed lines, I had my robot use essentially the logic I described in my previous post (keeping track of the last position to detect the dashed line). I found only two values were needed. Essentially, before I updated the position reading I saved the current position to another variable. Then, after updating the position reading, I checked if the current reading was not detecting the line and if the last position was within some threshold of the center. For example:

if( lineLost() && (prevPos > -1000) && (prevPos < 1000)){
  dashFound = true;
}

If the dashFound value is true, I had the robot enter a loop that just goes straight and updates the sensor readings to see if it finds the line again. When it does, it goes back to following the line.

It sounds like you might be doing some serial communication for debugging right now; you might get better performance by removing that since it could be slowing down your loop. Other than that, it is hard to give specific advice for tuning the PD coefficients for better performance without seeing the behavior. If you can post a video of your robot’s performance, I might be able to offer some more recommendations.

Battery drain can certainly cause inconsistencies and make it harder to tune your robot. Regulating your motor voltage is one way to fix this problem. If you want to do this, you should be sure to use a regulator that can handle the combined current draw of your motors. It sounds like you are using the 30:1 Micro Metal Gearmotor HP 6V and running them from a 3S LiPo. Please note that at 11V, those motors could pull upwards of 3.1A each. However, it also sounds like you are using them at a duty cycle well below 100%, so you might be able to use something like our 7.5V, 2.4A Step-Down Voltage Regulator D24V22F7. It sounds like running the motors at 7.5V might still be faster than you want to go, and having a wider range of duty cycles available will probably help with control also.

Brandon