# How do I create a broken line follower? [RobotC] [Legomindstorm] [Ev3]

Trying to create an algorithm/code in order to get my robot to follow a track which it currently can do, using a color sensor and following the inside edge. So I'm wondering how to transition to the track with broken parts the track has gaps with a max length of 20cm and only on straight parts. I also have a distance sensor available? any ideas

Currently your robot is only controlled by external factors. It always responds to external stimuli, it does not have any other operating mode.

In order to cope with missing line segments, you could add operating modes (or states) to the logic. You could detect the point where the line disappears and transition to an operating mode which goes straight on. In order to do this, it must store what does straight on mean (direction vector) and it probably should get a limit how far should it go straight on without a line present. Afterwards it could transition to a stopped sate (or operation mode).

If the line reapears in the sensors, it should switch back to line following state.

Although this problem only requires two states, as a learning exercise, you might want top look at state machine based programming approaches.

• How would that solve the issue of turns though If I use that approach? I was thinking what if I use a distance sensor to detect when there is a white line within 20cm then while the robot is on white go forward until it detects black, stop change code to going forward on black until it detects white, and if the distance sensor cant detects white within the distance it turns? Commented Mar 1, 2019 at 13:48
• It would not, since your question explicitly stated that in the missing line is only on straight parts... Your current description of the problem is not clear. Maybe add a figure to the answer?
– 50k4
Commented Mar 1, 2019 at 14:33
• Yeah the turns don't have any missing part but I would need to transition back to the code with the turns, the track has corners but the gaps are only on the straight part. Commented Mar 1, 2019 at 14:39
• "If the line reapears in the sensors, it should switch back to line following state."
– 50k4
Commented Mar 1, 2019 at 14:40