Page 1 of 1

Syntax error in if code

Posted: Sat Sep 24, 2016 12:10 pm
by nautilus27
Hey peeps,

Last year I made a hovercraft with Arduino and used skid steering via 2x motors. It worked great and controls were pretty accurate. So I'm trying to convert it to Python. I'm using Xbox 360 controller with xboxdrv drivers. Analog stick feedbacks are converted to certain values. Everything went smooth until i get syntax error for the if code:

Code: Select all

  File "sample.py", line 55
    if left_y_1023 > 550
                    ^
SyntaxError: invalid syntax
Why is this happening?

Code: Select all


import xbox
import RPi.GPIO as GPIO
import time

def mymap(x, in_min, in_max, out_min, out_max):
    return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)

motor1 = GPIO.PWM(11,50)
motor2 = GPIO.PWM(12,50)
motor3 = GPIO.PWM(15,50)
motor4 = GPIO.PWM(16,50)


while not joy.Back():

    left_x_1023 = mymap(joy.leftX(),-1.0,1.0,0,1023)
    print(left_x_1023)," ",
    left_y_1023 = mymap(joy.leftY(),-1.0,1.0,0,1023)
    print(left_y_1023), " ",
    right_x_1023 = mymap(joy.rightX(),-1.0,1.0,0,1023)
    print(right_x_1023), " ",
    right_y_1023 = mymap(joy.rightY(),-1.0,1.0,0,1023)
    print(right_y_1023), " ",

    speed1 = mymap(left_y_1023, 550,1023,0,100)
    speed2 = mymap(left_y_1023, 500,0,0,100)
    
    turn1 = mymap(left_x_1023,500,0,-50,50)

    skid1a = (speed1 - turn1)
    skid1b = (speed1 + turn1)
    
    turn2 = mymap(left_x_1023,550,1023,-50,50)
    
    skid2a = (speed1 - turn2)
    skid2b = (speed1 + turn2)
    
    skid3a = (speed2 - turn1)
    skid3b = (speed2 + turn1)
    
    skid4a = (speed2 - turn2)
    skid4b = (speed2 + turn2)
    
    turn3 = mymap(left_x_1023,500,0,0,100)
    turn4 = mymap(left_x_1023,550,1023,0,100)
    
    if left_y_1023 > 550
        if left_x_1023 > 501 and left_x_1023 < 549
            motor1.start(speed1)
            motor2.start(0)
            motor3.start(speed1)
            motor4.start(0)

Re: Syntax error in if code

Posted: Sat Sep 24, 2016 12:14 pm
by joan
Python requires a colon at the start of a block.

See http://stackoverflow.com/questions/2155 ... -in-python

Re: Syntax error in if code

Posted: Sat Sep 24, 2016 12:14 pm
by kusti8
You don't have a colon after the if statement

Re: Syntax error in if code

Posted: Sat Sep 24, 2016 12:16 pm
by nautilus27
joan wrote:Python requires a colon at the end of the if statement.
Thanks! I'm such a Python noob really. I wish i knew a Python Language reference like Arduino Referance in Arduino website.

https://www.arduino.cc/en/Reference/HomePage

Is there any?

Re: Syntax error in if code

Posted: Sat Sep 24, 2016 12:17 pm
by joan
nautilus27 wrote:
joan wrote:Python requires a colon at the end of the if statement.
Thanks! I'm such a Python noob really. I wish i knew a Python Language reference like Arduino Referance in Arduino website.

https://www.arduino.cc/en/Reference/HomePage

Is there any?
Just search for a Python tutorial with Google. You should find one which chimes with you.

Re: Syntax error in if code

Posted: Sat Sep 24, 2016 12:22 pm
by kusti8
Here's the documentation:
https://docs.python.org/3/