Line Following with ODS

Begin by mounting your ODS sensor downwards to that it can sense the black line on the floor.
Plugging your ODS sensor into the A7 port, use the diagnostic tool to measure its reading on the floor, on the tape, and half on the floor, half on the tape... write these down.
Entirely on the floor
Half on the floor, half on the tape
Entirely on the tape
Use the following code to let your robot follow the black line. You will need to change the desired value to the reading you got when the sensor was half on the tape and half on the floor. You may also need to adjust the gain!
import Fusion
import time
f = Fusion.driver()
ods = Fusion.analog(f, f.A7)
desired = 200
error = 0
gain = 2
while True:
error = ods.read() - desired
f.motorSpeed(f.M0, (50 - error)*gain)
f.motorSpeed(f.M1, (50 + error)*gain)
Last updated
Was this helpful?