-2

I'm having trouble running the last part of my code here. Im using Raspberry Pi, OpenCV, PiCamera, and servo motors. NOT SHOWN i have the code to find the centroid, and from the centroid it will then determine how far off '160' it is. Im not totally sure if the centroid's middle point is 160, so do any of you know that? As well as I get a SyntaxError on the "if: cx>151 and cx<169", would any of you know why that it, or could you help me to figure out a different approach to telling it how to follow the line?

import RoboPiLib as RPL
import setup

motorL = 0
motorR = 1

#1500 = middle point
#The closer to '1500' the slower it will go
if: cx>151 and cx<169
    print "straight"
    RPL.servoWrite(motorL, 1000)
    RPL.servoWrite(motorR, 2000)
    time.sleep(2)

elif x<=150
    print "left"
    RPL.servoWrite(motorL, 1000)
    RPL.servoWrite(motorR, 1750)
    time.sleep(2)

elif x>=170
    print "right"
    RPL.servoWrite(motorL, 1250)
    RPL.servoWrite(motorR, 1000)
    time.sleep(2)

else print "stop"
Miki
  • 40,887
  • 13
  • 123
  • 202
  • 3
    it should be `if :` you need to move your colon to the end of the line – Mohammad Athar Jan 10 '18 at 15:18
  • Better read the [official documentation](https://docs.python.org/3/tutorial/controlflow.html) some time, or you're bound to run into syntax errors while trying to fix your *actual* algorithm. – Jongware Jan 10 '18 at 15:23

1 Answers1

1

The colon on this line needs to be moved to the end of the line:

if cx>151 and cx<169:

Also the elif lines have the same problem: a colon is missing at the end of the lines!

mrCarnivore
  • 4,638
  • 2
  • 12
  • 29