2

I'm making a raspberry pi robot in Python and it moves, but it does not follow the line and I am using an infrared line sensor. I think that I have done everything properly.

Here are some results by replacing 0 and 0 (in the expressions) to different values (00, 01, 10, 11) and I've got some results here:

00 - Circles with boosts
10 - Circles with boosts
01 - Circles with boosts
11 - Straight line
10 with no DRIVE_1 - Circles

I've narrowed it down to these lines of code and I think that it's an infinite loop problem:

    if line_left == 0:
        GPIO.output(DRIVE_1, GPIO.HIGH)
        GPIO.output(DRIVE_2, GPIO.LOW)
        time.sleep(1)
        RobotForward()
        time.sleep(0.5)
    elif line_right == 0:
        GPIO.output(DRIVE_1, GPIO.LOW)
        GPIO.output(DRIVE_2, GPIO.HIGH)
        time.sleep(1)
        RobotForward()
        time.sleep(0.5)
    else:
        RobotForward()

Robot from front side:
Front

Robot from back side:
Back

Robot from left side:
Left

Robot from right side:
Right

Robot from above:
Above

Robot from below:
Below

  • Do you have a way of confirming what it is actually doing at any given point? You might want to attach a few leds (one for right and one for left) and turn them on and off at the beginning and end of each block in the if/elsif. – goldilocks Jan 23 '16 at 19:50
  • 1
    I am not familiar with the method you are using. I've only ever used two sensors which are positioned slightly further apart than the width of the black line to be followed. Then its straight on if both sensors see white, left if right hand sensor sees black, right if left hand sensor sees black, random if both see black. – joan Jan 23 '16 at 20:00
  • Is this your own robot design or are you following something posted on the Internet? – HeatfanJohn Jan 23 '16 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.