# Example Follow line program # Python port of C follow line program by Jan-Klaas Kollhof # Same copy right as the original program global LightThreshold, Speed # A simple spiral search def findLineSpiral(): ratio=30; while(SENSOR_3 >= LightThreshold): OnFwdSync(OUT_BC, Speed, ratio); Wait(200); if ratio > 20: ratio -= 1 # A simple left right search for the line def findLine(): tvar = lineFound = turnLeft = 0 if Random(2) > 0: turnLeft = 1 longTimeout = 10 longStartTime = 0 while not lineFound: longStartTime = CurrentTick() tvar = 100 if turnLeft: tvar *= -1 OnFwdSync(OUT_BC, Speed, tvar) #turn until we find a line or time is up while (CurrentTick() - longStartTime < longTimeout) or lineFound: if SENSOR_3 < LightThreshold: lineFound = 1 if not lineFound: turnLeft = not turnLeft if longTimeout > 1000: # lets give up and search with a spiral findLineSpiral() lineFound = 1 else: # lets give the bot a bit more time to turn longTimeout += 100 LightThreshold = Speed = 50 SetSensorLight(IN_3) findLineSpiral() OnFwd(OUT_BC, Speed) while(true): if(SENSOR_3 > LightThreshold): findLine() OnFwd(OUT_BC, Speed)